use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class TimestampValidatorTest method testE001.
@Test
public void testE001() {
TimestampValidator timestampValidator = new TimestampValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
final long CURRENT_TIME_MILLIS = TimeUnit.SECONDS.toMillis(MIN_POSIX_TIME);
/**
* All times are POSIX - no errors
*/
feedHeaderBuilder.setTimestamp(MIN_POSIX_TIME);
feedMessageBuilder.setHeader(feedHeaderBuilder.build());
tripUpdateBuilder.setTimestamp(MIN_POSIX_TIME);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Header isn't POSIX - should be 1 error
*/
// Convert a valid POSIX time to milliseconds - this is a common error in feeds (providing time in milliseconds past epoch instead of seconds)
final long BAD_TIME = TimeUnit.SECONDS.toMillis(MIN_POSIX_TIME);
feedHeaderBuilder.setTimestamp(BAD_TIME);
feedMessageBuilder.setHeader(feedHeaderBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E001, 1);
TestUtils.assertResults(expected, results);
/**
* Header and TripUpdate aren't POSIX - 2 errors
*/
tripUpdateBuilder.setTimestamp(BAD_TIME);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E001, 2);
TestUtils.assertResults(expected, results);
/**
* Header, TripUpdate, and VehiclePosition aren't POSIX - 3 errors
*/
vehiclePositionBuilder.setTimestamp(BAD_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E001, 3);
TestUtils.assertResults(expected, results);
/**
* StopTimeUpdates are all POSIX - no errors
*/
feedHeaderBuilder.setTimestamp(MIN_POSIX_TIME);
feedMessageBuilder.setHeader(feedHeaderBuilder.build());
tripUpdateBuilder.setTimestamp(MIN_POSIX_TIME);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
GtfsRealtime.TripUpdate.StopTimeUpdate.Builder stopTimeUpdateBuilder = GtfsRealtime.TripUpdate.StopTimeUpdate.newBuilder();
GtfsRealtime.TripUpdate.StopTimeEvent.Builder stopTimeEventBuilder = GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder();
// First StopTimeUpdate
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
tripUpdateBuilder.addStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// Second StopTimeUpdate
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MAX_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MAX_POSIX_TIME));
tripUpdateBuilder.addStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* 2 StopTimeUpdates, which each have an arrival AND departure POSIX error - so 4 errors total
*/
// First StopTimeUpdate
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(BAD_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(BAD_TIME));
tripUpdateBuilder.setStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// Second StopTimeUpdate
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(BAD_TIME + 1));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(BAD_TIME + 1));
tripUpdateBuilder.setStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E001, 4);
TestUtils.assertResults(expected, results);
// Remove bad POSIX StopTimeUpdates to prep for next assertion
tripUpdateBuilder.clearStopTimeUpdate();
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
/**
* Alert active_period ranges - both start and end are valid POSIX, so 0 errors
*/
GtfsRealtime.Alert.Builder alertBuilder = GtfsRealtime.Alert.newBuilder();
GtfsRealtime.TimeRange.Builder timeRangeBuilder = GtfsRealtime.TimeRange.newBuilder();
timeRangeBuilder.setStart(MIN_POSIX_TIME);
timeRangeBuilder.setEnd(MIN_POSIX_TIME);
alertBuilder.addActivePeriod(timeRangeBuilder.build());
feedEntityBuilder.setAlert(alertBuilder);
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Alert active_period ranges - neither start nor end are valid POSIX, so 2 errors
*/
timeRangeBuilder.setStart(BAD_TIME);
timeRangeBuilder.setEnd(BAD_TIME);
alertBuilder.addActivePeriod(timeRangeBuilder.build());
feedEntityBuilder.setAlert(alertBuilder);
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E001, 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 TimestampValidatorTest method testE022.
/**
* E022 - trip stop_time_update times are not increasing
*/
@Test
public void testE022() {
TimestampValidator timestampValidator = new TimestampValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
final long CURRENT_TIME_MILLIS = TimeUnit.SECONDS.toMillis(MIN_POSIX_TIME);
/**
* Set timestamps on objects (without StopTimeUpdates first) so no errors
*/
feedHeaderBuilder.setTimestamp(MIN_POSIX_TIME);
feedMessageBuilder.setHeader(feedHeaderBuilder.build());
tripUpdateBuilder.setTimestamp(MIN_POSIX_TIME);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Each StopTimeUpdates have same departures (no arrivals), and StopTimeUpdate A times are less than StopTimeUpdate B - no errors
*/
GtfsRealtime.TripUpdate.StopTimeUpdate.Builder stopTimeUpdateBuilder = GtfsRealtime.TripUpdate.StopTimeUpdate.newBuilder();
GtfsRealtime.TripUpdate.StopTimeEvent.Builder stopTimeEventBuilder = GtfsRealtime.TripUpdate.StopTimeEvent.newBuilder();
// StopTimeUpdate A
stopTimeUpdateBuilder.clearArrival();
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
tripUpdateBuilder.addStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// StopTimeUpdate B
stopTimeUpdateBuilder.clearArrival();
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
tripUpdateBuilder.addStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Each StopTimeUpdates have same arrivals (no departures), and StopTimeUpdate A times are less than StopTimeUpdate B - no errors
*/
// StopTimeUpdate A
stopTimeUpdateBuilder.clearDeparture();
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
tripUpdateBuilder.setStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// StopTimeUpdate B
stopTimeUpdateBuilder.clearDeparture();
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
tripUpdateBuilder.setStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Each StopTimeUpdates have same arrivals and departures, and StopTimeUpdate A times are less than StopTimeUpdate B - no errors
*/
// StopTimeUpdate A
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
tripUpdateBuilder.setStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// StopTimeUpdate B
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
tripUpdateBuilder.setStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Each StopTimeUpdate has sequential arrivals and departures, and StopTimeUpdate A times are less than StopTimeUpdate B - no errors
*/
// StopTimeUpdate A
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
tripUpdateBuilder.setStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// StopTimeUpdate B
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 2));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 3));
tripUpdateBuilder.setStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* StopTimeUpdate A has departure time and arrival time equal to StopTimeUpdate B - 4 errors
*/
// StopTimeUpdate A
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
tripUpdateBuilder.setStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// StopTimeUpdate B
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
tripUpdateBuilder.setStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E022, 4);
TestUtils.assertResults(expected, results);
/**
* StopTimeUpdate B has arrival time less than StopTimeUpdate A arrival time and StopTimeUpdate B departure time - 2 errors
*/
// StopTimeUpdate A
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
tripUpdateBuilder.setStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// StopTimeUpdate B
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 3));
tripUpdateBuilder.setStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E022, 2);
TestUtils.assertResults(expected, results);
/**
* StopTimeUpdate B has arrival time equal to StopTimeUpdate A arrival time and StopTimeUpdate B departure time - 2 errors
*/
// StopTimeUpdate A
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
tripUpdateBuilder.setStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// StopTimeUpdate B
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 3));
tripUpdateBuilder.setStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E022, 2);
TestUtils.assertResults(expected, results);
/**
* StopTimeUpdate B has arrival time less than StopTimeUpdate A arrival time and StopTimeUpdate B departure time - 2 errors
*/
// StopTimeUpdate A
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
tripUpdateBuilder.setStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// StopTimeUpdate B
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 3));
tripUpdateBuilder.setStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E022, 2);
TestUtils.assertResults(expected, results);
/**
* StopTimeUpdate B has departure time less than StopTimeUpdate A departure time - 1 error
*/
// StopTimeUpdate A
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 3));
tripUpdateBuilder.setStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// StopTimeUpdate B
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 2));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 2));
tripUpdateBuilder.setStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E022, 2);
TestUtils.assertResults(expected, results);
/**
* StopTimeUpdate B has arrival and departure time less than StopTimeUpdate A arrival time and StopTimeUpdate A departure time - 4 errors
*/
// StopTimeUpdate A
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 2));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 3));
tripUpdateBuilder.setStopTimeUpdate(0, stopTimeUpdateBuilder.build());
// StopTimeUpdate B
stopTimeUpdateBuilder.setArrival(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
stopTimeUpdateBuilder.setDeparture(stopTimeEventBuilder.setTime(MIN_POSIX_TIME + 1));
tripUpdateBuilder.setStopTimeUpdate(1, stopTimeUpdateBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E022, 4);
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 testE034.
/**
* E034 - GTFS-rt agency_id does not exist in GTFS data
*/
@Test
public void testE034() {
// testagency.zip has agency_id=agency
TripDescriptorValidator tripDescriptorValidator = new TripDescriptorValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.EntitySelector.Builder entitySelectorBuilder = GtfsRealtime.EntitySelector.newBuilder();
// Add an informed_entity with an agency_id that exists in GTFS - 0 errors
entitySelectorBuilder.setAgencyId("agency");
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Change to agency_id that is NOT in GTFS - 1 error
entitySelectorBuilder.clear();
entitySelectorBuilder.setAgencyId("bad");
alertBuilder.clear();
alertBuilder.addInformedEntity(entitySelectorBuilder.build());
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = tripDescriptorValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E034, 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 testE003E004W006.
/**
* E003 - All trip_ids provided in the GTFS-rt feed must appear in the GTFS data unless schedule_relationship is ADDED
* E004 - All route_ids provided in the GTFS-rt feed must appear in the GTFS data
* W006 - trip_update missing trip_id
*/
@Test
public void testE003E004W006() {
TripDescriptorValidator tripIdValidator = new TripDescriptorValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
// Don't set a trip_id - 2 warnings
tripDescriptorBuilder.setRouteId("1");
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(W006, 2);
TestUtils.assertResults(expected, results);
// setting valid trip_id = 1.1, route_id 1.1 that match with IDs in static Gtfs data - no errors
tripDescriptorBuilder.setTripId("1.1");
tripDescriptorBuilder.setRouteId("1");
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 route id = 100 that does not match with any route_id in static Gtfs data - two errors
tripDescriptorBuilder.setRouteId("100");
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(E004, 2);
TestUtils.assertResults(expected, results);
// Reset to valid route ID
tripDescriptorBuilder.setRouteId("1");
// Set invalid trip_id = 100 that does not match with any trip_id in static Gtfs data - 2 errors
tripDescriptorBuilder.setTripId("100");
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);
// Set that trip_id is ADDED - should go back to 0 errors, as it's ok for trip_id to not be in the GTFS data if schedule_relationship is ADDED
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.ADDED);
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);
clearAndInitRequiredFeedFields();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class TripDescriptorValidatorTest method testE021.
/**
* E021 - Invalid start_date format
*/
@Test
public void testE021() {
TripDescriptorValidator tripIdValidator = new TripDescriptorValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
// Set valid trip_id = 1.1 that's in the GTFS data
tripDescriptorBuilder.setTripId("1.1");
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_date - no errors
expected.clear();
TestUtils.assertResults(expected, results);
// Set valid start_date - no errors
tripDescriptorBuilder.setStartDate("20170101");
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_date - 2 errors
tripDescriptorBuilder.setStartDate("01-01-2017");
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(E021, 2);
TestUtils.assertResults(expected, results);
clearAndInitRequiredFeedFields();
}
Aggregations