use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class StopTimeUpdateValidatorTest method testE43.
/**
* E043 - stop_time_update doesn't have arrival or departure
*/
@Test
public void testE43() {
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 without arrival or departure - 1 error
stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
stopTimeUpdateBuilder.setStopId("1.1");
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.put(E043, 1);
TestUtils.assertResults(expected, results);
// One stop_time_update without arrival or departure, but schedule_relationship SKIPPED - 0 errors
stopTimeUpdateBuilder.clear();
stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED);
stopTimeUpdateBuilder.setStopId("1.1");
tripUpdateBuilder.clearStopTimeUpdate();
tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.CANCELED);
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 or departure, but schedule_relationship NO_DATA - 0 errors
stopTimeUpdateBuilder.clear();
stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.NO_DATA);
stopTimeUpdateBuilder.setStopId("1.1");
tripUpdateBuilder.clearStopTimeUpdate();
tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.CANCELED);
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 - 0 errors
stopTimeUpdateBuilder.clear();
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.CANCELED);
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 - 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.clearStopTimeUpdate();
tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.CANCELED);
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();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule 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();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule 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();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule 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();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class ValidationRules method getRules.
/**
* Returns a read-only list of all currently-defined validation rules
* @return a read-only list of all currently-defined validation rules
*/
public static synchronized List<ValidationRule> getRules() {
if (mAllRules.isEmpty()) {
// Use reflection to get the list of rules
Field[] fields = ValidationRules.class.getDeclaredFields();
for (Field field : fields) {
if (Modifier.isStatic(field.getModifiers())) {
Class classType = field.getType();
if (classType == ValidationRule.class) {
ValidationRule rule = new ValidationRule();
try {
Object value = field.get(rule);
rule = (ValidationRule) value;
mAllRules.add(rule);
} catch (IllegalAccessException ex) {
ex.printStackTrace();
}
}
}
}
}
// Return a read-only list of these rules so different threads can't modify the list
return Collections.unmodifiableList(mAllRules);
}
Aggregations