Skip to content

Commit

Permalink
fix(MtcFeedResource): Avoid NullPointerException if ExternalFeedSourc…
Browse files Browse the repository at this point in the history
…eProperty->AgencyId is set to n
  • Loading branch information
binh-dam-ibigroup committed Dec 3, 2021
1 parent eddd745 commit 1852cd5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void feedVersionCreated(
constructId(feedVersion.parentFeedSource(), this.getResourceType(), AGENCY_ID_FIELDNAME)
);

if(agencyIdProp == null || agencyIdProp.value.equals("null")) {
if(agencyIdProp == null || agencyIdProp.value == null || agencyIdProp.value.equals("null")) {
LOG.error("Could not read {} for FeedSource {}", AGENCY_ID_FIELDNAME, feedVersion.feedSourceId);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.conveyal.datatools.UnitTest;
import com.conveyal.datatools.manager.models.ExternalFeedSourceProperty;
import com.conveyal.datatools.manager.models.FeedSource;
import com.conveyal.datatools.manager.models.FeedVersion;
import com.conveyal.datatools.manager.models.Project;
import com.conveyal.datatools.manager.persistence.Persistence;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -15,7 +16,9 @@
import java.io.IOException;
import java.util.Date;

import static com.conveyal.datatools.TestUtils.createFeedVersion;
import static com.conveyal.datatools.TestUtils.parseJson;
import static com.conveyal.datatools.TestUtils.zipFolderFiles;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
Expand All @@ -27,6 +30,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

class MtcFeedResourceTest extends UnitTest {
private static Project project;
Expand Down Expand Up @@ -152,4 +156,23 @@ void canUpdateFeedExternalPropertiesToMongo() throws IOException {
ExternalFeedSourceProperty removedPublicIdProp = Persistence.externalFeedSourceProperties.getById(agencyPublicIdProp.id);
assertThat(removedPublicIdProp, nullValue());
}

@Test
void shouldTolerateNullObjectInExternalPropertyAgencyId() throws IOException {
// Add an entry in the ExternalFeedSourceProperties collection
// with AgencyId value set to null.
ExternalFeedSourceProperty agencyIdProp = new ExternalFeedSourceProperty(
feedSource,
"MTC",
"AgencyId",
null
);
agencyIdProp.feedSourceId = feedSource.id;
Persistence.externalFeedSourceProperties.create(agencyIdProp);

// Trigger the feed update process (it should not upload anything to S3).
FeedVersion feedVersion = createFeedVersion(feedSource, zipFolderFiles("mini-bart-new"));
MtcFeedResource mtcFeedResource = new MtcFeedResource();
assertDoesNotThrow(() -> mtcFeedResource.feedVersionCreated(feedVersion, null));
}
}

0 comments on commit 1852cd5

Please sign in to comment.