use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TimestampValidator in project gtfs-realtime-validator by CUTR-at-USF.
the class TimestampValidatorTest method testDuplicateFeedMessagesThrowException.
/**
* Make sure we throw an exception if current and previous message are the same. Some rules like E017 and E018
* require that the feed content for the current and previous iterations passed into the validate() method are different.
*/
@Test(expected = IllegalArgumentException.class)
public void testDuplicateFeedMessagesThrowException() {
TimestampValidator timestampValidator = new TimestampValidator();
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
feedHeaderBuilder.setTimestamp(MIN_POSIX_TIME + 1);
feedMessageBuilder.setHeader(feedHeaderBuilder.build());
tripUpdateBuilder.setTimestamp(MIN_POSIX_TIME + 1);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
// This should throw an IllegalArgumentException
results = timestampValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), feedMessageBuilder.build(), null);
}
use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TimestampValidator 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();
}
Aggregations