Search in sources :

Example 1 with HeaderValidator

use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.HeaderValidator in project gtfs-realtime-validator by CUTR-at-USF.

the class HeaderValidatorTest method testE039.

/**
 * E039 - FULL_DATASET feeds should not include entity.is_deleted
 */
@Test
public void testE039() {
    HeaderValidator headerValidator = new HeaderValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.FeedHeader.Builder headerBuilder = GtfsRealtime.FeedHeader.newBuilder();
    headerBuilder.setGtfsRealtimeVersion("1.0");
    // FULL_DATASET feed without any entities - no errors
    headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET);
    feedMessageBuilder.setHeader(headerBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // DIFFERENTIAL feed without any entities - no errors
    headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.DIFFERENTIAL);
    feedMessageBuilder.setHeader(headerBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // FULL_DATASET feed without is_deleted field in any entities - no errors
    headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET);
    feedMessageBuilder.setHeader(headerBuilder.build());
    feedMessageBuilder.addEntity(feedEntityBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // DIFFERENTIAL feed without is_deleted field in any entities - no errors
    headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.DIFFERENTIAL);
    feedMessageBuilder.setHeader(headerBuilder.build());
    feedMessageBuilder.addEntity(feedEntityBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // FULL_DATASET feed with is_deleted field in an entity - 1 error
    headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET);
    feedMessageBuilder.setHeader(headerBuilder.build());
    feedEntityBuilder.setIsDeleted(true);
    feedMessageBuilder.addEntity(feedEntityBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(ValidationRules.E039, 1);
    TestUtils.assertResults(expected, results);
    // DIFFERENTIAL feed with is_deleted field in an entity - 0 errors
    feedMessageBuilder.clearEntity();
    headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.DIFFERENTIAL);
    feedMessageBuilder.setHeader(headerBuilder.build());
    feedEntityBuilder.setIsDeleted(true);
    feedMessageBuilder.addEntity(feedEntityBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) HeaderValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.HeaderValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 2 with HeaderValidator

use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.HeaderValidator in project gtfs-realtime-validator by CUTR-at-USF.

the class HeaderValidatorTest method testE049.

/**
 * E038 - Invalid header.gtfs_realtime_version
 */
@Test
public void testE049() {
    HeaderValidator headerValidator = new HeaderValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.FeedHeader.Builder headerBuilder = GtfsRealtime.FeedHeader.newBuilder();
    // GTFS-rt v1.0, and no incrementality - no errors
    headerBuilder.setGtfsRealtimeVersion("1.0");
    feedMessageBuilder.setHeader(headerBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // GTFS-rt v2.0, and no incrementality - 1 error
    headerBuilder.setGtfsRealtimeVersion("2.0");
    feedMessageBuilder.setHeader(headerBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(ValidationRules.E049, 1);
    TestUtils.assertResults(expected, results);
    // GTFS-rt v2.0, and has incrementality - no errors
    headerBuilder.setGtfsRealtimeVersion("2.0");
    headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET);
    feedMessageBuilder.setHeader(headerBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) HeaderValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.HeaderValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 3 with HeaderValidator

use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.HeaderValidator in project gtfs-realtime-validator by CUTR-at-USF.

the class HeaderValidatorTest method testE038.

/**
 * E038 - Invalid header.gtfs_realtime_version
 */
@Test
public void testE038() {
    HeaderValidator headerValidator = new HeaderValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.FeedHeader.Builder headerBuilder = GtfsRealtime.FeedHeader.newBuilder();
    // Valid version - no errors
    headerBuilder.setGtfsRealtimeVersion("1.0");
    feedMessageBuilder.setHeader(headerBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // Valid version, and set incrementality to avoid E049 - no errors
    headerBuilder.setGtfsRealtimeVersion("2.0");
    headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET);
    feedMessageBuilder.setHeader(headerBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // Bad version - 1 error
    headerBuilder.setGtfsRealtimeVersion("3.0");
    feedMessageBuilder.setHeader(headerBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(ValidationRules.E038, 1);
    TestUtils.assertResults(expected, results);
    // Bad version - one error
    headerBuilder.setGtfsRealtimeVersion("1");
    feedMessageBuilder.setHeader(headerBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(ValidationRules.E038, 1);
    TestUtils.assertResults(expected, results);
    // Bad version - one error
    headerBuilder.setGtfsRealtimeVersion("abcd");
    feedMessageBuilder.setHeader(headerBuilder.build());
    results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(ValidationRules.E038, 1);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) HeaderValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.HeaderValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Aggregations

ValidationRule (edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule)3 FeedMessageTest (edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)3 HeaderValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.HeaderValidator)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3