use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class TripDescriptorValidatorTest method testE030.
/**
* E030 - GTFS-rt alert trip_id does not belong to GTFS-rt alert route_id in GTFS trips.txt
*/
@Test
public void testE030() {
TripDescriptorValidator tripDescriptorValidator = new TripDescriptorValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
// In bullrunner-gtfs.zip trips.txt, trip_id=1 belongs to route_id=A
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
GtfsRealtime.EntitySelector.Builder entitySelectorBuilder = GtfsRealtime.EntitySelector.newBuilder();
// Don't set route_id or trip_id (but set stop_id - we need at least one specifier) - 1 warning for missing trip_id
entitySelectorBuilder.setStopId("1234");
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
// Missing trip_id
expected.put(W006, 1);
TestUtils.assertResults(expected, results);
// Set trip_id but not route_id - no errors
tripDescriptorBuilder.setTripId("1");
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.clearInformedEntity();
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Set route_id but not trip_id - 1 warning for missing trip_id
tripDescriptorBuilder.clear();
entitySelectorBuilder.setRouteId("A");
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.clearInformedEntity();
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
// Missing trip_id
expected.put(W006, 1);
TestUtils.assertResults(expected, results);
// Set route_id and trip_id to correct values according to GTFS trips.txt - no errors
tripDescriptorBuilder.setTripId("1");
entitySelectorBuilder.setRouteId("A");
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.clearInformedEntity();
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Set route_id to something other than the correct value ("A") - 1 error
tripDescriptorBuilder.setTripId("1");
entitySelectorBuilder.setRouteId("B");
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.clearInformedEntity();
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(E030, 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 TripDescriptorValidatorTest method testW009StopTimeUpdate.
/**
* W009 - schedule_relationship not populated (for StopTimeUpdate)
*/
@Test
public void testW009StopTimeUpdate() {
TripDescriptorValidator tripDescriptorValidator = new TripDescriptorValidator();
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.1");
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
// tripDescriptor is a required field in tripUpdate
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
// Missing schedule_relationship for StopTimeUpdate - 1 warning
stopTimeUpdateBuilder.setStopId("1000");
tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
assertEquals(1, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(W009, 1);
TestUtils.assertResults(expected, results);
// Missing another schedule_relationship for StopTimeUpdate - however, we only flag one occurrence warning per trip, so still 1 warning
stopTimeUpdateBuilder.setStopId("2000");
tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
assertEquals(2, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(W009, 1);
TestUtils.assertResults(expected, results);
// Add schedule_relationship of SCHEDULED for StopTimeUpdates - no warnings
tripUpdateBuilder.clearStopTimeUpdate();
stopTimeUpdateBuilder.clear();
stopTimeUpdateBuilder.setStopSequence(4);
stopTimeUpdateBuilder.setStopId("1000");
stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
stopTimeUpdateBuilder.setStopSequence(5);
stopTimeUpdateBuilder.setStopId("2000");
stopTimeUpdateBuilder.setScheduleRelationship(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder.addStopTimeUpdate(stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
assertEquals(2, feedMessageBuilder.getEntity(0).getTripUpdate().getStopTimeUpdateCount());
results = tripDescriptorValidator.validate(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 TripDescriptorValidatorTest method testE023.
/**
* E023 - start_time does not match GTFS initial arrival_time
*/
@Test
public void testE023() {
/**
* In testagency.txt, trip 1.2 has the following:
*
* trip_id,arrival_time,departure_time,stop_id,stop_sequence,shape_dist_traveled,pickup_type,drop_off_type
* 1.2,00:20:00,00:20:00,A,1,,0,0
* 1.2,00:30:00,00:30:00,B,2,,0,0
*
* So, initial arrival_time is 00:20:00.
*/
TripDescriptorValidator tripIdValidator = new TripDescriptorValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1.2");
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripIdValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
// No start_time - no errors
expected.clear();
TestUtils.assertResults(expected, results);
// Set valid start_time - no errors
tripDescriptorBuilder.setStartTime("00:20:00");
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripIdValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Set invalid start_time - 2 errors
tripDescriptorBuilder.setStartTime("00:30:00");
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripIdValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E023, 2);
TestUtils.assertResults(expected, results);
// Set valid start_time, but with a trip_id that doesn't exist in GTFS data (to make sure no NPE - see #217) - no errors for E023, but 2 errors for E003 missing trip_id in GTFS)
tripDescriptorBuilder.setStartTime("00:20:00");
tripDescriptorBuilder.setTripId("100000000");
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripIdValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
expected.put(E003, 2);
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 TripDescriptorValidatorTest method testE031.
/**
* E031 - Alert informed_entity.route_id does not match informed_entity.trip.route_id
*/
@Test
public void testE031() {
TripDescriptorValidator tripDescriptorValidator = new TripDescriptorValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
// In bullrunner-gtfs.zip routes.txt, route_id=A is a valid route
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
GtfsRealtime.EntitySelector.Builder entitySelectorBuilder = GtfsRealtime.EntitySelector.newBuilder();
// Don't set either route_id (but set stop_id - we need at least one specifier) - W006 warning for no trip_id
entitySelectorBuilder.setStopId("1234");
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(W006, 1);
TestUtils.assertResults(expected, results);
// Set informed_entity.route_id but not informed_entity.trip.route_id - no errors - W006 warning for no trip_id
entitySelectorBuilder.setRouteId("A");
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.clearInformedEntity();
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(W006, 1);
TestUtils.assertResults(expected, results);
// Set informed_entity.trip.route_id but not informed_entity.route_id - W006 warning for no trip_id
tripDescriptorBuilder.setRouteId("A");
entitySelectorBuilder.clear();
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.clearInformedEntity();
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(W006, 1);
TestUtils.assertResults(expected, results);
// Set informed_entity.trip.route_id and informed_entity.route_id to the same values - W006 warning for no trip_id
tripDescriptorBuilder.setRouteId("A");
entitySelectorBuilder.setRouteId("A");
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.clearInformedEntity();
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(W006, 1);
TestUtils.assertResults(expected, results);
// Set informed_entity.trip.route_id and informed_entity.route_id to they don't match - 1 error
tripDescriptorBuilder.setRouteId("A");
entitySelectorBuilder.setRouteId("B");
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.clearInformedEntity();
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(E031, 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 TripDescriptorValidatorTest method testW009TripDescriptor.
/**
* W009 - schedule_relationship not populated (for TripDescriptor)
*/
@Test
public void testW009TripDescriptor() {
TripDescriptorValidator tripDescriptorValidator = new TripDescriptorValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
// In bullrunner-gtfs.zip trips.txt, trip_id=1 exists
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
GtfsRealtime.EntitySelector.Builder entitySelectorBuilder = GtfsRealtime.EntitySelector.newBuilder();
// No schedule_relationship for trip - 3 warnings
tripDescriptorBuilder.setTripId("1");
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(W009, 3);
TestUtils.assertResults(expected, results);
// Add schedule_relationship of SCHEDULED for trip - 0 warnings
tripDescriptorBuilder.setTripId("1");
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
alertBuilder.clearInformedEntity();
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
clearAndInitRequiredFeedFields();
}
Aggregations