Search in sources :

Example 56 with ValidationRule

use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.

the class FrequencyTypeZeroValidatorTest method testW005.

/**
 * W005 - Missing vehicle_id for frequency-based exact_times = 0
 */
@Test
public void testW005() {
    FrequencyTypeZeroValidator frequencyTypeZeroValidator = new FrequencyTypeZeroValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    // Set valid trip_id, start_date, and start_time so no errors/warnings for these attributes
    tripDescriptorBuilder.setTripId("1");
    tripDescriptorBuilder.setStartDate("4-24-2016");
    tripDescriptorBuilder.setStartTime("08:00:00AM");
    GtfsRealtime.VehicleDescriptor.Builder vehicleDescriptorBuilder = GtfsRealtime.VehicleDescriptor.newBuilder();
    feedHeaderBuilder.setTimestamp(TimestampUtils.MIN_POSIX_TIME);
    feedMessageBuilder.setHeader(feedHeaderBuilder.build());
    tripUpdateBuilder.setTimestamp(TimestampUtils.MIN_POSIX_TIME);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
    vehiclePositionBuilder.setTimestamp(TimestampUtils.MIN_POSIX_TIME);
    vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
    vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // No vehicle Id in trip update or vehicle position - 2 warnings
    results = frequencyTypeZeroValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(ValidationRules.W005, 2);
    TestUtils.assertResults(expected, results);
    // Add vehicle_id to vehicle position - 1 warning
    vehicleDescriptorBuilder.setId("1");
    vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // No vehicle Id in trip update - 1 warning
    results = frequencyTypeZeroValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(ValidationRules.W005, 1);
    TestUtils.assertResults(expected, results);
    // Add vehicle_id to trip update - no warnings
    vehicleDescriptorBuilder.setId("1");
    tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // Both have vehicle_id - no warnings
    results = frequencyTypeZeroValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) FrequencyTypeZeroValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.FrequencyTypeZeroValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 57 with ValidationRule

use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.

the class StopLocationTypeValidatorTest method testE010.

/**
 * E010 - If location_type is used in stops.txt, all stops referenced in stop_times.txt must have location_type of 0
 */
@Test
public void testE010() {
    StopLocationTypeValidator stopLocationValidator = new StopLocationTypeValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    // gtfsData does not contain location_type = 1 for stop_id. Therefore returns 0 results
    results = stopLocationValidator.validate(gtfsData);
    for (ErrorListHelperModel error : results) {
        assertEquals(0, error.getOccurrenceList().size());
    }
    // gtfsData2 contains location_type = 1 for stop_ids. Therefore returns errorcount = (number of location_type = 1 for stop_ids)
    results = stopLocationValidator.validate(gtfsData2);
    expected.put(E010, 1);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : ErrorListHelperModel(edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel) StopLocationTypeValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.gtfs.StopLocationTypeValidator) HashMap(java.util.HashMap) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 58 with ValidationRule

use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.

the class StopValidatorTest method testE011.

/**
 * E011 - All stop_ids referenced in GTFS-rt feed must appear in the GTFS feed
 */
@Test
public void testE011() {
    StopValidator locationValidator = new StopValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    GtfsRealtime.TripUpdate.StopTimeUpdate.Builder stopTimeUpdateBuilder = GtfsRealtime.TripUpdate.StopTimeUpdate.newBuilder();
    GtfsRealtime.EntitySelector.Builder entitySelectorBuilder = GtfsRealtime.EntitySelector.newBuilder();
    GtfsRealtime.VehicleDescriptor.Builder vehicleDescriptorBuilder = GtfsRealtime.VehicleDescriptor.newBuilder();
    vehicleDescriptorBuilder.setId("1");
    // tripDescriptor is a required field in tripUpdate
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // setting stop id = "A" in all the three feeds that matches the stop id in static Gtfs data
    stopTimeUpdateBuilder.setStopId("A");
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    vehiclePositionBuilder.setStopId("A");
    vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    entitySelectorBuilder.setStopId("A");
    alertBuilder.addInformedEntity(entitySelectorBuilder.build());
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // all the feeds have valid stop id matching that in static Gtfs data. So, returns 0 results
    results = locationValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // setting stop id = "DUMMY" in TripUpdate feed that does not match with any stop id in static Gtfs data
    stopTimeUpdateBuilder.setStopId("DUMMY");
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = locationValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    // one error from TripUpdate feed stop_id = "DUMMY". VehiclePosition and Alert feeds have valid stop id = "A"
    expected.put(E011, 1);
    TestUtils.assertResults(expected, results);
    vehiclePositionBuilder.setStopId("DUMMY");
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = locationValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    // 2 results from TripUpdate and VehiclePosition feeds stop_id="DUMMY". Alert feed have valid stop id ="A"
    expected.put(E011, 2);
    TestUtils.assertResults(expected, results);
    entitySelectorBuilder.setStopId("DUMMY");
    alertBuilder.addInformedEntity(entitySelectorBuilder.build());
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = locationValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    // 3 results from TripUpdate, VehiclePosition and alert feeds stop_id="DUMMY"
    expected.put(E011, 3);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : StopValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.StopValidator) HashMap(java.util.HashMap) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) GtfsRealtime(com.google.transit.realtime.GtfsRealtime) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 59 with ValidationRule

use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.

the class StopTimeUpdateValidatorTest method testE037.

/**
 * E037 - Sequential stop_time_updates have the same stop_id
 */
@Test
public void testE037() {
    StopTimeUpdateValidator stopSequenceValidator = new StopTimeUpdateValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.TripUpdate.StopTimeUpdate.Builder stopTimeUpdateBuilder = GtfsRealtime.TripUpdate.StopTimeUpdate.newBuilder();
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    tripDescriptorBuilder.setTripId("1234");
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    // tripDescriptor is a required field in tripUpdate
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    // stop_ids 1000, 2000 - no errors
    stopTimeUpdateBuilder.setStopId("1000");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("2000");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 2
    assertEquals(2, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // Add stop_sequence - no errors
    stopTimeUpdateBuilder.clear();
    stopTimeUpdateBuilder.setStopSequence(1);
    stopTimeUpdateBuilder.setStopId("1000");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopSequence(5);
    stopTimeUpdateBuilder.setStopId("2000");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 2
    assertEquals(2, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // Add stop_id 2000 twice (and to make sure we support it, no stop_sequence). So, repeating stop_ids 3000 - one error
    stopTimeUpdateBuilder.clear();
    stopTimeUpdateBuilder.setStopSequence(1);
    stopTimeUpdateBuilder.setStopId("1000");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopSequence(5);
    stopTimeUpdateBuilder.setStopId("2000");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.clear();
    stopTimeUpdateBuilder.setStopId("2000");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 3
    assertEquals(3, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(E037, 1);
    TestUtils.assertResults(expected, results);
    // stop_id 2000 twice again, but include stop_sequence for last stop_time_update - one error
    stopTimeUpdateBuilder.clear();
    stopTimeUpdateBuilder.setStopSequence(1);
    stopTimeUpdateBuilder.setStopId("1000");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopSequence(5);
    stopTimeUpdateBuilder.setStopId("2000");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopSequence(10);
    stopTimeUpdateBuilder.setStopId("2000");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 3
    assertEquals(3, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(E037, 1);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) StopTimeUpdateValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.StopTimeUpdateValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) GtfsRealtime(com.google.transit.realtime.GtfsRealtime) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 60 with ValidationRule

use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.

the class StopTimeUpdateValidatorTest method testE002noStopSequenceGtfsRt.

/**
 * E002 - stop_time_updates for a given trip_id must be sorted by increasing stop_sequence
 * <p>
 * Tests the case when the GTFS-rt feed is missing the stop_sequence field
 */
@Test
public void testE002noStopSequenceGtfsRt() {
    /**
     * bullrunner-gtfs.zip (bullRunnerGtfs) has the following in stop_times.txt:
     *
     * trip_id,arrival_time,departure_time,stop_id,stop_sequence
     * 1,07:00:00,07:00:00,222,1
     * 1,07:01:04,07:01:04,230,2
     * 1,07:01:38,07:01:38,214,3
     * 1,07:02:15,07:02:15,204,4
     * 1,07:02:56,07:02:56,102,5
     * 1,07:03:38,07:03:38,101,6
     * 1,07:04:04,07:04:04,108,7
     * 1,07:04:32,07:04:32,110,8
     * 1,07:05:38,07:05:38,166,9
     * 1,07:06:44,07:06:44,162,10
     * 1,07:07:48,07:07:48,158,11
     * 1,07:08:30,07:08:30,154,12
     * 1,07:09:20,07:09:20,150,13
     * 1,07:09:52,07:09:52,446,14
     * 1,07:11:01,07:11:01,432,15
     * 1,07:11:49,07:11:49,430,16
     * 1,07:12:34,07:12:34,426,17
     * 1,07:13:41,07:13:41,418,18
     * 1,07:14:34,07:14:34,401,19
     * 1,07:16:07,07:16:07,414,20
     * 1,07:16:53,07:16:53,330,21
     * 1,07:17:21,07:17:21,328,22
     * 1,07:17:59,07:17:59,326,23
     * 1,07:18:43,07:18:43,226,24
     * 1,07:19:43,07:19:43,222,25
     */
    StopTimeUpdateValidator stopSequenceValidator = new StopTimeUpdateValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.TripUpdate.StopTimeUpdate.Builder stopTimeUpdateBuilder = GtfsRealtime.TripUpdate.StopTimeUpdate.newBuilder();
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    tripDescriptorBuilder.setTripId("1");
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    // stop_sequence and stop_id pairings all correctly match GTFS - no errors
    stopTimeUpdateBuilder.setStopId("222");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("230");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("214");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("204");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("102");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("101");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("162");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("154");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("222");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    // This trip visits a stop more than once, and we're not providing stop_sequence, so we'll get 1 E009 error
    expected.put(E009, 1);
    TestUtils.assertResults(expected, results);
    // Swap the first and second update - 1 E002 error
    tripUpdateBuilder.clearStopTimeUpdate();
    stopTimeUpdateBuilder.clear();
    stopTimeUpdateBuilder.setStopId("230");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("222");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("214");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("204");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("102");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("101");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("162");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("154");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("222");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    // This trip visits a stop more than once, and we're not providing stop_sequence, so we'll get 1 E009 error
    expected.put(E009, 1);
    expected.put(E002, 1);
    TestUtils.assertResults(expected, results);
    // Repeat the prediction for stop_id 230 - 1 E002 error
    tripUpdateBuilder.clearStopTimeUpdate();
    stopTimeUpdateBuilder.clear();
    stopTimeUpdateBuilder.setStopId("222");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("230");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("230");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("214");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("204");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("102");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("101");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("162");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("154");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("222");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    // This trip visits a stop more than once, and we're not providing stop_sequence, so we'll get 1 E009 error
    expected.put(E009, 1);
    // We're repeating a stop_id back-to-back, so we'll get 1 E037 error
    expected.put(E037, 1);
    expected.put(E002, 1);
    TestUtils.assertResults(expected, results);
    // Put stop_id 154 out of order - 1 E002 error
    tripUpdateBuilder.clearStopTimeUpdate();
    stopTimeUpdateBuilder.clear();
    stopTimeUpdateBuilder.setStopId("222");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("230");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("214");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("204");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("102");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("101");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("162");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("222");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopId("154");
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    // This trip visits a stop more than once, and we're not providing stop_sequence, so we'll get 1 E009 error
    expected.put(E009, 1);
    expected.put(E002, 1);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) StopTimeUpdateValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.StopTimeUpdateValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) GtfsRealtime(com.google.transit.realtime.GtfsRealtime) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Aggregations

ValidationRule (edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule)65 Test (org.junit.Test)62 HashMap (java.util.HashMap)59 FeedMessageTest (edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)58 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)23 TripDescriptorValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TripDescriptorValidator)14 StopTimeUpdateValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.StopTimeUpdateValidator)13 TimestampValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TimestampValidator)11 VehicleValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator)8 ErrorListHelperModel (edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel)6 MessageLogModel (edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel)4 OccurrenceModel (edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel)4 FrequencyTypeZeroValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.FrequencyTypeZeroValidator)3 HeaderValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.HeaderValidator)3 CrossFeedDescriptorValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.CrossFeedDescriptorValidator)2 StopValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.StopValidator)2 GtfsMetadata (edu.usf.cutr.gtfsrtvalidator.lib.validation.GtfsMetadata)1 StopLocationTypeValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.gtfs.StopLocationTypeValidator)1 FrequencyTypeOneValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.FrequencyTypeOneValidator)1 Field (java.lang.reflect.Field)1