Search in sources :

Example 1 with FrequencyTypeOneValidator

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

the class FrequencyTypeOneValidatorTest method testE019.

/**
 * E019 - GTFS-rt trip start_date and start_time must match GTFS data
 * <p>
 * testagency.zip (gtfsData) has exact_times = 1 trips for 15.1 with a 1 hr (3600 sec) headway
 */
@Test
public void testE019() {
    Map<ValidationRule, Integer> expected = new HashMap<>();
    /**
     * Set start_time to match GTFS start_time exactly - 6am - no errors
     */
    FrequencyTypeOneValidator frequencyTypeOneValidator = new FrequencyTypeOneValidator();
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    tripDescriptorBuilder.setTripId("15.1");
    tripDescriptorBuilder.setStartTime("06:00:00");
    feedHeaderBuilder.setTimestamp(MIN_POSIX_TIME);
    feedMessageBuilder.setHeader(feedHeaderBuilder.build());
    tripUpdateBuilder.setTimestamp(MIN_POSIX_TIME);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
    vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
    vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = frequencyTypeOneValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    /**
     * Set start_time to be a multiple of headway_secs - 1 hr later at 7:00am - 0 errors
     */
    tripDescriptorBuilder.setTripId("15.1");
    tripDescriptorBuilder.setStartTime("07:00:00");
    feedHeaderBuilder.setTimestamp(MIN_POSIX_TIME);
    feedMessageBuilder.setHeader(feedHeaderBuilder.build());
    tripUpdateBuilder.setTimestamp(MIN_POSIX_TIME);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
    vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
    vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = frequencyTypeOneValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    /**
     * Set start_time to NOT be a multiple of headway_secs - 2.5 hr later at 7:30am - 2 errors
     */
    tripDescriptorBuilder.setTripId("15.1");
    tripDescriptorBuilder.setStartTime("07:30:00");
    feedHeaderBuilder.setTimestamp(MIN_POSIX_TIME);
    feedMessageBuilder.setHeader(feedHeaderBuilder.build());
    tripUpdateBuilder.setTimestamp(MIN_POSIX_TIME);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
    vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
    vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = frequencyTypeOneValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(E019, 2);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) FrequencyTypeOneValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.FrequencyTypeOneValidator) 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)1 FeedMessageTest (edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)1 FrequencyTypeOneValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.FrequencyTypeOneValidator)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1