12
12
import com .google .common .collect .Lists ;
13
13
import org .junit .jupiter .api .AfterAll ;
14
14
import org .junit .jupiter .api .BeforeAll ;
15
- import org .junit .jupiter .api .Test ;
16
15
import org .junit .jupiter .params .ParameterizedTest ;
17
16
import org .junit .jupiter .params .provider .Arguments ;
18
17
import org .junit .jupiter .params .provider .MethodSource ;
32
31
import static org .junit .jupiter .api .Assertions .assertEquals ;
33
32
import static org .junit .jupiter .api .Assertions .assertFalse ;
34
33
import static org .junit .jupiter .api .Assertions .assertNotNull ;
34
+ import static org .junit .jupiter .api .Assertions .assertNull ;
35
35
import static org .junit .jupiter .api .Assertions .assertTrue ;
36
36
37
37
/**
@@ -131,8 +131,9 @@ private static Stream<Arguments> createPublishFeedCases() {
131
131
);
132
132
}
133
133
134
- @ Test
135
- void shouldUpdateFeedInfoAfterPublishComplete () {
134
+ @ ParameterizedTest
135
+ @ MethodSource ("createUpdateFeedInfoCases" )
136
+ void shouldUpdateFeedInfoAfterPublishComplete (String agencyId , boolean isUnknownFeedId ) {
136
137
// Add the version to the feed source
137
138
FeedVersion createdVersion = createFeedVersionFromGtfsZip (feedSource , "bart_new_lite.zip" );
138
139
@@ -149,7 +150,7 @@ void shouldUpdateFeedInfoAfterPublishComplete() {
149
150
assertNotNull (updatedFeedVersion .sentToExternalPublisher );
150
151
151
152
// Create a test FeedUpdater instance, and simulate running the task.
152
- TestCompletedFeedRetriever completedFeedRetriever = new TestCompletedFeedRetriever ();
153
+ TestCompletedFeedRetriever completedFeedRetriever = new TestCompletedFeedRetriever (agencyId );
153
154
FeedUpdater feedUpdater = FeedUpdater .createForTest (completedFeedRetriever );
154
155
155
156
// The list of feeds processed externally (completed) should be empty at this point.
@@ -163,38 +164,66 @@ void shouldUpdateFeedInfoAfterPublishComplete() {
163
164
// If a feed has been republished since last check, it will have a new etag/file hash,
164
165
// and the scenario below should apply.
165
166
Map <String , String > etagsAfter = feedUpdater .checkForUpdatedFeeds ();
166
- assertEquals (1 , etagsAfter .size ());
167
- assertTrue (etagsAfter .containsValue ("test-etag" ));
168
167
169
- // Make sure that the publish-complete attribute has been set for the feed version in Mongo.
170
168
FeedVersion updatedFeedVersionAfter = Persistence .feedVersions .getById (createdVersion .id );
171
169
Date updatedDate = updatedFeedVersionAfter .processedByExternalPublisher ;
172
170
String namespace = updatedFeedVersionAfter .namespace ;
173
- assertNotNull (updatedDate );
174
-
175
- // At the next check for updates, the metadata for the feeds completed above
176
- // should not be updated again.
177
- feedUpdater .checkForUpdatedFeeds ();
178
- FeedVersion updatedFeedVersionAfter2 = Persistence .feedVersions .getById (createdVersion .id );
179
- assertEquals (updatedDate , updatedFeedVersionAfter2 .processedByExternalPublisher );
180
- assertEquals (namespace , updatedFeedVersionAfter2 .namespace );
171
+
172
+ if (!isUnknownFeedId ) {
173
+ // Regular scenario: updating a known/existing feed.
174
+ assertEquals (1 , etagsAfter .size ());
175
+ assertTrue (etagsAfter .containsValue ("test-etag" ));
176
+
177
+ // Make sure that the publish-complete attribute has been set for the feed version in Mongo.
178
+ assertNotNull (updatedDate );
179
+
180
+ // At the next check for updates, the metadata for the feeds completed above
181
+ // should not be updated again.
182
+ feedUpdater .checkForUpdatedFeeds ();
183
+ FeedVersion updatedFeedVersionAfter2 = Persistence .feedVersions .getById (createdVersion .id );
184
+ assertEquals (updatedDate , updatedFeedVersionAfter2 .processedByExternalPublisher );
185
+ assertEquals (namespace , updatedFeedVersionAfter2 .namespace );
186
+ } else {
187
+ // Edge case: an unknown feed id was provided,
188
+ // so no update of the feed should be happening (and there should not be an exception).
189
+ assertEquals (0 , etagsAfter .size ());
190
+ assertNull (updatedDate );
191
+ }
192
+ }
193
+
194
+ private static Stream <Arguments > createUpdateFeedInfoCases () {
195
+ return Stream .of (
196
+ Arguments .of (
197
+ TEST_AGENCY ,
198
+ false
199
+ ),
200
+ Arguments .of (
201
+ "12345" ,
202
+ true
203
+ )
204
+ );
181
205
}
182
206
183
207
/**
184
208
* Mocks the results of an {@link S3ObjectSummary} retrieval before/after the
185
209
* external MTC publishing process is complete.
186
210
*/
187
211
private static class TestCompletedFeedRetriever implements FeedUpdater .CompletedFeedRetriever {
212
+ private final String agencyId ;
188
213
public boolean isPublishingComplete ;
189
214
215
+ public TestCompletedFeedRetriever (String agencyId ) {
216
+ this .agencyId = agencyId ;
217
+ }
218
+
190
219
@ Override
191
220
public List <S3ObjectSummary > retrieveCompletedFeeds () {
192
221
if (!isPublishingComplete ) {
193
222
return new ArrayList <>();
194
223
} else {
195
224
S3ObjectSummary objSummary = new S3ObjectSummary ();
196
225
objSummary .setETag ("test-etag" );
197
- objSummary .setKey (String .format ("%s/%s" , TEST_COMPLETED_FOLDER , TEST_AGENCY ));
226
+ objSummary .setKey (String .format ("%s/%s" , TEST_COMPLETED_FOLDER , agencyId ));
198
227
return Lists .newArrayList (objSummary );
199
228
}
200
229
}
0 commit comments