Search in sources :

Example 11 with StopTimeUpdateValidator

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

the class StopTimeUpdateValidatorTest method testE036.

/**
 * E036 - Sequential stop_time_updates have the same stop_sequence
 */
@Test
public void testE036() {
    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_sequences 1, 5 - no errors
    stopTimeUpdateBuilder.setStopSequence(1);
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    stopTimeUpdateBuilder.setStopSequence(5);
    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_ids - 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 sequence 5 twice (and to make sure we support it, no stopId). So, the stop sequence now is 1, 5, 5 - 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.setStopSequence(5);
    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);
    // E002 checks for strict ordering, so we'll get 1 of those here too
    expected.put(E002, 1);
    expected.put(E036, 1);
    TestUtils.assertResults(expected, results);
    // stop_sequence 5 twice again, but include stop_id 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(5);
    stopTimeUpdateBuilder.setStopId("3000");
    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);
    // E002 checks for strict ordering, so we'll get 1 of those here too
    expected.put(E002, 1);
    expected.put(E036, 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 12 with StopTimeUpdateValidator

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

the class StopTimeUpdateValidatorTest method testE41.

/**
 * E041 - trip doesn't have any stop_time_updates
 */
@Test
public void testE41() {
    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);
    // tripDescriptor is a required field in tripUpdate
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    // No stop_time_updates - 1 error
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 0
    assertEquals(0, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(E041, 1);
    TestUtils.assertResults(expected, results);
    // One stop_time_update added - 0 errors
    stopTimeUpdateBuilder.clear();
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setStopId("1.1");
    stopTimeUpdateBuilder.setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 1
    assertEquals(1, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // No stop_time_updates, but trip is CANCELED - 0 errors
    stopTimeUpdateBuilder.clear();
    tripUpdateBuilder.clearStopTimeUpdate();
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.CANCELED);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 0
    assertEquals(0, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    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 13 with StopTimeUpdateValidator

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

the class StopTimeUpdateValidatorTest method testE44.

/**
 * E044 - stop_time_update arrival/departure doesn't have delay or time
 */
@Test
public void testE44() {
    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);
    // tripDescriptor is a required field in tripUpdate
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    // One stop_time_update with arrival delay - 0 errors
    stopTimeUpdateBuilder.clearDeparture();
    stopTimeUpdateBuilder.clearArrival();
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setStopId("1.1");
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 1
    assertEquals(1, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // One stop_time_update with arrival time - 0 errors
    stopTimeUpdateBuilder.clearDeparture();
    stopTimeUpdateBuilder.clearArrival();
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setStopId("1.1");
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(TimestampUtils.MIN_POSIX_TIME).build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 1
    assertEquals(1, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // One stop_time_update with departure delay - 0 errors
    stopTimeUpdateBuilder.clearDeparture();
    stopTimeUpdateBuilder.clearArrival();
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setStopId("1.1");
    stopTimeUpdateBuilder.setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setDelay(60).build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 1
    assertEquals(1, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // One stop_time_update with departure time - 0 errors
    stopTimeUpdateBuilder.clearDeparture();
    stopTimeUpdateBuilder.clearArrival();
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setStopId("1.1");
    stopTimeUpdateBuilder.setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().setTime(TimestampUtils.MIN_POSIX_TIME).build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 1
    assertEquals(1, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // One stop_time_update without arrival time or delay - 1 error
    stopTimeUpdateBuilder.clearDeparture();
    stopTimeUpdateBuilder.clearArrival();
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setStopId("1.1");
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 1
    assertEquals(1, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(E044, 1);
    TestUtils.assertResults(expected, results);
    // One stop_time_update without departure time or delay - 1 error
    stopTimeUpdateBuilder.clearDeparture();
    stopTimeUpdateBuilder.clearArrival();
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
    stopTimeUpdateBuilder.setStopId("1.1");
    stopTimeUpdateBuilder.setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 1
    assertEquals(1, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(E044, 1);
    TestUtils.assertResults(expected, results);
    // One stop_time_update without arrival time or delay, but with SKIPPED schedule_relationship - 0 errors
    stopTimeUpdateBuilder.clearDeparture();
    stopTimeUpdateBuilder.clearArrival();
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED);
    stopTimeUpdateBuilder.setStopId("1.1");
    stopTimeUpdateBuilder.setArrival(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 1
    assertEquals(1, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // One stop_time_update without departure time or delay, but with SKIPPED schedule_relationship - 0 errors
    stopTimeUpdateBuilder.clearDeparture();
    stopTimeUpdateBuilder.clearArrival();
    stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED);
    stopTimeUpdateBuilder.setStopId("1.1");
    stopTimeUpdateBuilder.setDeparture(GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder().build());
    tripUpdateBuilder.clearStopTimeUpdate();
    tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // StopTimeUpdate count should be 1
    assertEquals(1, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
    results = stopSequenceValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    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

GtfsRealtime (com.google.transit.realtime.GtfsRealtime)13 ValidationRule (edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule)13 FeedMessageTest (edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)13 StopTimeUpdateValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.StopTimeUpdateValidator)13 HashMap (java.util.HashMap)13 Test (org.junit.Test)13