Skip to content

Commit dc21dd3

Browse files
authored
Merge pull request #80 from entur/fix/missing-required-file-counts-as-error
fix: missing required files should count as an error
2 parents 1bbd89f + 19b2f0a commit dc21dd3

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

src/main/java/org/entur/gbfs/validation/validator/FileValidator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public void validateMissingFile(FileValidationResult fvr) {
110110
fvr.setVersion(version.getVersionString());
111111
fvr.setSchema(version.getSchema(fvr.getFile()).toString());
112112
fvr.setRequired(version.isFileRequired(fvr.getFile()));
113+
if (version.isFileRequired(fvr.getFile())) {
114+
fvr.setErrorsCount(1);
115+
}
113116
}
114117
}
115118
}

src/test/java/org/entur/gbfs/validation/validator/GbfsJsonValidatorTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ void testEmptyDeliveryMapValidation() {
3333
GbfsJsonValidator validator = new GbfsJsonValidator();
3434
Map<String, InputStream> deliveryMap = new HashMap<>();
3535
ValidationResult result = validator.validate(deliveryMap);
36-
Assertions.assertEquals(0, result.getSummary().getErrorsCount());
36+
37+
// The expected error count is 2, because there are two required files
38+
// missing in an empty delivery, gbfs.json, and system_information.json
39+
Assertions.assertEquals(2, result.getSummary().getErrorsCount());
3740
}
3841

3942
@Test
@@ -42,6 +45,7 @@ void testSuccessfulV1_0Validation() {
4245

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

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

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

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

215221
Assertions.assertTrue(result.getFiles().get("system_information").isRequired());
216222
Assertions.assertFalse(result.getFiles().get("system_information").isExists());
223+
224+
Assertions.assertEquals(1, result.getSummary().getErrorsCount());
217225
}
218226

219227
@Test
@@ -235,11 +243,14 @@ void testMissingNotRequiredFile() {
235243

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

239248
ValidationResult result = validator.validate(deliveryMap);
240249

241250
Assertions.assertFalse(result.getFiles().get("vehicle_types").isRequired());
242251
Assertions.assertFalse(result.getFiles().get("vehicle_types").isExists());
252+
253+
Assertions.assertEquals(0, result.getSummary().getErrorsCount());
243254
}
244255

245256
@Test
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"last_updated":1611598155,
3+
"ttl":1800,
4+
"version": "1.0",
5+
"data":{
6+
"system_id":"exampleride",
7+
"language":"en",
8+
"name":"Example Ride",
9+
"timezone":"America/Chicago"
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"last_updated":1611598155,
3+
"ttl":1800,
4+
"version": "1.1",
5+
"data":{
6+
"system_id":"exampleride",
7+
"language":"en",
8+
"name":"Example Ride",
9+
"timezone":"America/Chicago"
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"last_updated":1611598155,
3+
"ttl":1800,
4+
"version": "2.0",
5+
"data":{
6+
"system_id":"exampleride",
7+
"language":"en",
8+
"name":"Example Ride",
9+
"timezone":"America/Chicago"
10+
}
11+
}

0 commit comments

Comments
 (0)