Skip to content

Commit

Permalink
Merge pull request #80 from entur/fix/missing-required-file-counts-as…
Browse files Browse the repository at this point in the history
…-error

fix: missing required files should count as an error
  • Loading branch information
testower authored Apr 25, 2024
2 parents 1bbd89f + 19b2f0a commit dc21dd3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public void validateMissingFile(FileValidationResult fvr) {
fvr.setVersion(version.getVersionString());
fvr.setSchema(version.getSchema(fvr.getFile()).toString());
fvr.setRequired(version.isFileRequired(fvr.getFile()));
if (version.isFileRequired(fvr.getFile())) {
fvr.setErrorsCount(1);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ void testEmptyDeliveryMapValidation() {
GbfsJsonValidator validator = new GbfsJsonValidator();
Map<String, InputStream> deliveryMap = new HashMap<>();
ValidationResult result = validator.validate(deliveryMap);
Assertions.assertEquals(0, result.getSummary().getErrorsCount());

// The expected error count is 2, because there are two required files
// missing in an empty delivery, gbfs.json, and system_information.json
Assertions.assertEquals(2, result.getSummary().getErrorsCount());
}

@Test
Expand All @@ -42,6 +45,7 @@ void testSuccessfulV1_0Validation() {

Map<String, InputStream> deliveryMap = new HashMap<>();
deliveryMap.put("gbfs", getFixture("fixtures/v1.0/gbfs.json"));
deliveryMap.put("system_information", getFixture("fixtures/v1.0/system_information.json"));
deliveryMap.put("system_hours", getFixture("fixtures/v1.0/system_hours.json"));

ValidationResult result = validator.validate(deliveryMap);
Expand All @@ -59,6 +63,7 @@ void testSuccessfulV1_1Validation() {
Map<String, InputStream> deliveryMap = new HashMap<>();
deliveryMap.put("gbfs", getFixture("fixtures/v1.1/gbfs.json"));
deliveryMap.put("gbfs_versions", getFixture("fixtures/v1.1/gbfs_versions.json"));
deliveryMap.put("system_information", getFixture("fixtures/v1.1/system_information.json"));
deliveryMap.put("system_hours", getFixture("fixtures/v1.1/system_hours.json"));

ValidationResult result = validator.validate(deliveryMap);
Expand All @@ -76,6 +81,7 @@ void testSuccessfulV2_0Validation() {
Map<String, InputStream> deliveryMap = new HashMap<>();
deliveryMap.put("gbfs", getFixture("fixtures/v2.0/gbfs.json"));
deliveryMap.put("gbfs_versions", getFixture("fixtures/v2.0/gbfs_versions.json"));
deliveryMap.put("system_information", getFixture("fixtures/v2.0/system_information.json"));
deliveryMap.put("system_hours", getFixture("fixtures/v2.0/system_hours.json"));

ValidationResult result = validator.validate(deliveryMap);
Expand Down Expand Up @@ -214,6 +220,8 @@ void testMissingRequiredFile() {

Assertions.assertTrue(result.getFiles().get("system_information").isRequired());
Assertions.assertFalse(result.getFiles().get("system_information").isExists());

Assertions.assertEquals(1, result.getSummary().getErrorsCount());
}

@Test
Expand All @@ -235,11 +243,14 @@ void testMissingNotRequiredFile() {

Map<String, InputStream> deliveryMap = new HashMap<>();
deliveryMap.put("gbfs", getFixture("fixtures/v2.2/gbfs.json"));
deliveryMap.put("system_information", getFixture("fixtures/v2.2/system_information.json"));

ValidationResult result = validator.validate(deliveryMap);

Assertions.assertFalse(result.getFiles().get("vehicle_types").isRequired());
Assertions.assertFalse(result.getFiles().get("vehicle_types").isExists());

Assertions.assertEquals(0, result.getSummary().getErrorsCount());
}

@Test
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/fixtures/v1.0/system_information.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"last_updated":1611598155,
"ttl":1800,
"version": "1.0",
"data":{
"system_id":"exampleride",
"language":"en",
"name":"Example Ride",
"timezone":"America/Chicago"
}
}
11 changes: 11 additions & 0 deletions src/test/resources/fixtures/v1.1/system_information.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"last_updated":1611598155,
"ttl":1800,
"version": "1.1",
"data":{
"system_id":"exampleride",
"language":"en",
"name":"Example Ride",
"timezone":"America/Chicago"
}
}
11 changes: 11 additions & 0 deletions src/test/resources/fixtures/v2.0/system_information.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"last_updated":1611598155,
"ttl":1800,
"version": "2.0",
"data":{
"system_id":"exampleride",
"language":"en",
"name":"Example Ride",
"timezone":"America/Chicago"
}
}

0 comments on commit dc21dd3

Please sign in to comment.