-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repair Shared Stops Validator #584
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b2e6755
correct shared stops validator behaviors
miles-grant-ibigroup 6ad9abf
fix formatting
miles-grant-ibigroup 8eabd13
refactor: address pr feedback
miles-grant-ibigroup a55e37e
deps: update gtfs-lib
miles-grant-ibigroup 7521cc7
extract testable functionality to unit tests
miles-grant-ibigroup a2bdbff
refactor(Updates to enum use and parameterized unit tests):
br648 dbf47d3
Merge pull request #585 from ibi-group/shared-stops-validator-repair-rb
miles-grant-ibigroup 509cec4
update ci node
miles-grant-ibigroup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,10 @@ jobs: | |
java-version: 19 | ||
distribution: 'temurin' | ||
# Install node 14 for running e2e tests (and for maven-semantic-release). | ||
- name: Use Node.js 18.x | ||
- name: Use Node.js 20.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 18.x | ||
node-version: 20.x | ||
- name: Start MongoDB | ||
uses: supercharge/[email protected] | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/conveyal/datatools/manager/jobs/validation/SharedStopsHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.conveyal.datatools.manager.jobs.validation; | ||
|
||
import java.util.Map; | ||
|
||
public enum SharedStopsHeader { | ||
|
||
STOP_GROUP_ID_INDEX("stop_group_id"), | ||
|
||
STOP_ID_INDEX("stop_id"), | ||
|
||
IS_PRIMARY_INDEX("is_primary"), | ||
|
||
FEED_ID_INDEX("feed_id"); | ||
|
||
public final String headerName; | ||
|
||
SharedStopsHeader(String name) { | ||
this.headerName = name; | ||
} | ||
|
||
public String getHeaderName() { | ||
return headerName; | ||
} | ||
|
||
public static SharedStopsHeader fromValue(String headerName) { | ||
for (SharedStopsHeader sharedStopsHeader : SharedStopsHeader.values()) { | ||
if (sharedStopsHeader.getHeaderName().equalsIgnoreCase(headerName)) { | ||
return sharedStopsHeader; | ||
} | ||
} | ||
throw new UnsupportedOperationException(String.format("Unknown shared stops header: %s", headerName)); | ||
} | ||
|
||
public static boolean hasRequiredHeaders(Map<SharedStopsHeader, Integer> headerIndices) { | ||
return headerIndices.size() == SharedStopsHeader.values().length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/test/java/com/conveyal/datatools/manager/jobs/validation/SharedStopsValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.conveyal.datatools.manager.jobs.validation; | ||
|
||
import com.conveyal.datatools.UnitTest; | ||
import com.csvreader.CsvReader; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static com.zenika.snapshotmatcher.SnapshotMatcher.matchesSnapshot; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class SharedStopsValidatorTest extends UnitTest { | ||
|
||
@ParameterizedTest | ||
@MethodSource("createCSVHeaders") | ||
void canHandleVariousCorrectCSV(String headers) { | ||
assertThat(SharedStopsValidator.getHeaderIndices(CsvReader.parse(headers)), matchesSnapshot()); | ||
} | ||
|
||
private static Stream<String> createCSVHeaders() { | ||
return Stream.of( | ||
"is_primary,feed_id,stop_id,stop_group_id", | ||
"feed_id,stop_id,stop_group_id,is_primary", | ||
"feed_id,is_primary,stop_group_id,stop_id,feed_id" | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("createInvalidCSVArguments") | ||
void attemptToParseInvalidCSV(InvalidCSVArgument invalidCSVArgument) { | ||
CsvReader configReader = CsvReader.parse(invalidCSVArgument.csv); | ||
Exception exception = assertThrows(RuntimeException.class, () -> SharedStopsValidator.getHeaderIndices(configReader)); | ||
assertEquals(invalidCSVArgument.expectedError, exception.getMessage()); | ||
} | ||
|
||
private static Stream<InvalidCSVArgument> createInvalidCSVArguments() { | ||
String invalid = "Unknown shared stops header: "; | ||
String missing = "shared_stops.csv is missing headers!"; | ||
return Stream.of( | ||
new InvalidCSVArgument("this is a great string, but it's not a shared_stops csv!", invalid + "this is a great string"), | ||
new InvalidCSVArgument("", invalid), | ||
new InvalidCSVArgument("is_primary,stop_id", missing), | ||
new InvalidCSVArgument("is_primary,feed_id,,stop_group_id", invalid), | ||
new InvalidCSVArgument("is_primary,feed_id,stop_group_id", missing), | ||
new InvalidCSVArgument("feed_id, is_primary, stop_group_id,stop_id", invalid + " is_primary") | ||
); | ||
} | ||
|
||
private static class InvalidCSVArgument { | ||
public String csv; | ||
public String expectedError; | ||
|
||
public InvalidCSVArgument(String csv, String expectedError) { | ||
this.csv = csv; | ||
this.expectedError = expectedError; | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...atools/manager/jobs/validation/SharedStopsValidatorTest/canHandleVariousCorrectCSV-0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"STOP_GROUP_ID_INDEX" : 3, | ||
"STOP_ID_INDEX" : 2, | ||
"IS_PRIMARY_INDEX" : 0, | ||
"FEED_ID_INDEX" : 1 | ||
} |
6 changes: 6 additions & 0 deletions
6
...atools/manager/jobs/validation/SharedStopsValidatorTest/canHandleVariousCorrectCSV-1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"STOP_GROUP_ID_INDEX" : 2, | ||
"STOP_ID_INDEX" : 1, | ||
"IS_PRIMARY_INDEX" : 3, | ||
"FEED_ID_INDEX" : 0 | ||
} |
6 changes: 6 additions & 0 deletions
6
...atools/manager/jobs/validation/SharedStopsValidatorTest/canHandleVariousCorrectCSV-2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"STOP_GROUP_ID_INDEX" : 2, | ||
"STOP_ID_INDEX" : 3, | ||
"IS_PRIMARY_INDEX" : 1, | ||
"FEED_ID_INDEX" : 4 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit update to 20 or remove 14.