use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class VehicleValidatorTest method testE028.
/**
* E028 - Vehicle position outside agency coverage area
*/
@Test
public void testE028() {
VehicleValidator vehicleValidator = new VehicleValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.VehicleDescriptor.Builder vehicleDescriptorBuilder = GtfsRealtime.VehicleDescriptor.newBuilder();
vehicleDescriptorBuilder.setId("1");
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
/**
* Using normal USF Bull Runner feed, which includes GTFS shapes.txt
*/
// No errors, if position isn't populated
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
GtfsRealtime.Position.Builder positionBuilder = GtfsRealtime.Position.newBuilder();
// Valid lat and long (USF Campus in Tampa, FL)
positionBuilder.setLatitude(28.0587f);
positionBuilder.setLongitude(-82.4139f);
vehiclePositionBuilder.setPosition(positionBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Valid lat and long, but outside agency bounding box (Downtown Tampa, FL) - one error
positionBuilder.setLatitude(27.9482837f);
positionBuilder.setLongitude(-82.4655826f);
vehiclePositionBuilder.setPosition(positionBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(E028, 1);
TestUtils.assertResults(expected, results);
/**
* Using modified USF Bull Runner feed WITHOUT shapes.txt
*/
// Valid lat and long (USF Campus in Tampa, FL)
positionBuilder.setLatitude(28.0587f);
positionBuilder.setLongitude(-82.4139f);
vehiclePositionBuilder.setPosition(positionBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfsNoShapes, bullRunnerGtfsNoShapesMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Valid lat and long, but outside agency bounding box (Downtown Tampa, FL) - one error
positionBuilder.setLatitude(27.9482837f);
positionBuilder.setLongitude(-82.4655826f);
vehiclePositionBuilder.setPosition(positionBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfsNoShapes, bullRunnerGtfsNoShapesMetadata, feedMessageBuilder.build(), null, null);
expected.put(E028, 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 VehicleValidatorTest method testE029IgnoreShapes.
/**
* E029 - Vehicle position outside trip shape buffer, but ignoring GTFS shapes.txt
*/
@Test
public void testE029IgnoreShapes() {
// Re-create the metadata for this test, but this time ignoring the GTFS shapes.txt
bullRunnerGtfsMetadata = new GtfsMetadata("bullrunner-gtfs.zip", bullRunnerGtfsMetadata.getTimeZone(), bullRunnerGtfs, true);
VehicleValidator vehicleValidator = new VehicleValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.VehicleDescriptor.Builder vehicleDescriptorBuilder = GtfsRealtime.VehicleDescriptor.newBuilder();
vehicleDescriptorBuilder.setId("1");
// USF Bull Runner - route_id=A, trip_id=2
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("2");
tripDescriptorBuilder.setRouteId("A");
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
// Add the trip_id=2 to GTFS-rt message - now we can match against trip_id=2 in shapes.txt, and this should generate one error, but we're ignoring shapes.txt, so no error
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Create alert with effect other than a detour with trip_id=2 - point is not allowed outside shape, one error normally, but we're ignoring shapes.txt, so no errors
GtfsRealtime.Alert.Builder alertBuilder = GtfsRealtime.Alert.newBuilder();
alertBuilder.setEffect(GtfsRealtime.Alert.Effect.UNKNOWN_EFFECT);
alertBuilder.addInformedEntity(GtfsRealtime.EntitySelector.newBuilder().setTrip(tripDescriptorBuilder.build()));
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Change the alert back to DETOUR, but change the route_id to a different route - one error normally, as Route A is no longer on detour, but we're ignoring shapes.txt, so no errors
alertBuilder = GtfsRealtime.Alert.newBuilder();
alertBuilder.setEffect(GtfsRealtime.Alert.Effect.DETOUR);
alertBuilder.addInformedEntity(GtfsRealtime.EntitySelector.newBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setRouteId("C").build()));
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Alert is DETOUR again, but change the trip_id to a different trip - one error again normally, as trip_id=2 is no longer on detour, but we're ignoring shapes.txt, so no errors
alertBuilder = GtfsRealtime.Alert.newBuilder();
alertBuilder.setEffect(GtfsRealtime.Alert.Effect.DETOUR);
alertBuilder.addInformedEntity(GtfsRealtime.EntitySelector.newBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("10").build()));
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Re-create the metadata for next tests with shapes.txt metadata
bullRunnerGtfsMetadata = new GtfsMetadata("bullrunner-gtfs.zip", bullRunnerGtfsMetadata.getTimeZone(), bullRunnerGtfs, false);
clearAndInitRequiredFeedFields();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class VehicleValidatorTest method testW002.
/**
* W002 - vehicle_id should be populated in TripUpdate and VehiclePosition feeds
*/
@Test
public void testW002() {
VehicleValidator vehicleValidator = new VehicleValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
GtfsRealtime.VehicleDescriptor.Builder vehicleDescriptorBuilder = GtfsRealtime.VehicleDescriptor.newBuilder();
// tripDescriptor is a required field in tripUpdate
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
// setting a value for vehicle id = 1
vehicleDescriptorBuilder.setId("1");
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
// No errors, if vehicle id has a value.
results = vehicleValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Test with empty string for Vehicle ID, which should generate 2 warnings (one for TripUpdates and one for VehiclePositions)
vehicleDescriptorBuilder.setId("");
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = vehicleValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(W002, 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 CrossFeedDescriptorValidatorTest method testW003.
/**
* W003 - ID in one feed missing from the other
*/
@Test
public void testW003() {
Map<ValidationRule, Integer> expected = new HashMap<>();
CrossFeedDescriptorValidator crossFeedDescriptorValidator = new CrossFeedDescriptorValidator();
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
GtfsRealtime.VehicleDescriptor.Builder vehicleDescriptorBuilder = GtfsRealtime.VehicleDescriptor.newBuilder();
// Set the same trip and vehicle ID to both TripUpdate and VehiclePosition - no warnings
vehicleDescriptorBuilder.setId("1");
tripDescriptorBuilder.setTripId("1.1");
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = crossFeedDescriptorValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, null, null, feedMessageBuilder.build());
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Change the VehiclePosition to have trip_id = 100 and vehicle.id = 44, while TripUpdate has trip_id 1.1 and vehicle_id 1.
* TripUpdate is missing the IDs in VehiclePosition, and VehiclePosition is missing the IDs in TripUpdate - 4 warnings.
*/
vehicleDescriptorBuilder.setId("44");
tripDescriptorBuilder.setTripId("100");
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = crossFeedDescriptorValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, null, null, feedMessageBuilder.build());
expected.put(ValidationRules.W003, 4);
TestUtils.assertResults(expected, results);
/**
* Clear the VehiclePosition trip_id, and clear the TripUpdates vehicle.id, and add two versions of each
* (to make sure we catch this case - see
* https://github.com/CUTR-at-USF/gtfs-realtime-validator/issues/241#issuecomment-313194304, although we're no
* longer using HashBiMaps) - 4 warnings.
*/
vehicleDescriptorBuilder.clearId();
tripDescriptorBuilder.setTripId("100");
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehicleDescriptorBuilder.setId("44");
tripDescriptorBuilder.clearTripId();
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
vehicleDescriptorBuilder.clearId();
tripDescriptorBuilder.setTripId("101");
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehicleDescriptorBuilder.setId("45");
tripDescriptorBuilder.clearTripId();
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.addEntity(1, feedEntityBuilder.build());
results = crossFeedDescriptorValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, null, null, feedMessageBuilder.build());
expected.put(ValidationRules.W003, 4);
TestUtils.assertResults(expected, results);
/**
* Set the VehiclePosition trip_id to empty string, and set the TripUpdates vehicle.id to empty string, and add two versions of each
* (to make sure we catch this case - see https://github.com/CUTR-at-USF/gtfs-realtime-validator/issues/241#issuecomment-313194304, although we're no
* longer using HashBiMaps) - 4 warnings.
*/
vehicleDescriptorBuilder.setId("");
tripDescriptorBuilder.setTripId("100");
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehicleDescriptorBuilder.setId("44");
tripDescriptorBuilder.setTripId("");
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
vehicleDescriptorBuilder.setId("");
tripDescriptorBuilder.setTripId("101");
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehicleDescriptorBuilder.setId("45");
tripDescriptorBuilder.setTripId("");
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(1, feedEntityBuilder.build());
results = crossFeedDescriptorValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, null, null, feedMessageBuilder.build());
expected.put(ValidationRules.W003, 4);
TestUtils.assertResults(expected, results);
/**
* Clear the TripUpdates feed but not the VehiclePositions - no warnings should occur if no TripUpdates feed is provided
*/
feedEntityBuilder.clearTripUpdate();
feedMessageBuilder.clearEntity();
feedMessageBuilder.addEntity(0, feedEntityBuilder.build());
results = crossFeedDescriptorValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, null, null, feedMessageBuilder.build());
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Set the TripUpdates feed and clear the VehiclePositions - no warnings should occur if no VehiclePositions feed is provided
*/
feedEntityBuilder.clearVehicle();
feedMessageBuilder.clearEntity();
vehicleDescriptorBuilder.setId("");
tripDescriptorBuilder.setTripId("100");
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehicleDescriptorBuilder.setId("44");
tripDescriptorBuilder.setTripId("");
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedMessageBuilder.addEntity(0, feedEntityBuilder.build());
vehicleDescriptorBuilder.setId("");
tripDescriptorBuilder.setTripId("101");
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
vehicleDescriptorBuilder.setId("45");
tripDescriptorBuilder.setTripId("");
feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
feedMessageBuilder.addEntity(1, feedEntityBuilder.build());
results = crossFeedDescriptorValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, null, null, feedMessageBuilder.build());
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 FrequencyTypeZeroValidatorTest method testE006.
/**
* E006 - Missing required trip field for frequency-based exact_times = 0
*/
@Test
public void testE006() {
FrequencyTypeZeroValidator frequencyTypeZeroValidator = new FrequencyTypeZeroValidator();
Map<ValidationRule, Integer> expectedErrorsWarnings = new HashMap<>();
// Set valid trip_id
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1");
// Set valid vehicle_id so no warnings for these
GtfsRealtime.VehicleDescriptor.Builder vehicleDescriptorBuilder = GtfsRealtime.VehicleDescriptor.newBuilder();
vehicleDescriptorBuilder.setId("vehicle_A");
feedHeaderBuilder.setTimestamp(TimestampUtils.MIN_POSIX_TIME);
feedMessageBuilder.setHeader(feedHeaderBuilder.build());
tripUpdateBuilder.setTimestamp(TimestampUtils.MIN_POSIX_TIME);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(TimestampUtils.MIN_POSIX_TIME);
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
// Start with no start date or time - 4 errors
results = frequencyTypeZeroValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expectedErrorsWarnings.put(ValidationRules.E006, 4);
TestUtils.assertResults(expectedErrorsWarnings, results);
// Set start date - 2 errors
tripDescriptorBuilder.setStartDate("4-24-2016");
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = frequencyTypeZeroValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expectedErrorsWarnings.put(ValidationRules.E006, 2);
TestUtils.assertResults(expectedErrorsWarnings, results);
// Set start time - 0 error
tripDescriptorBuilder.setStartTime("08:00:00AM");
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
// No errors
results = frequencyTypeZeroValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expectedErrorsWarnings.clear();
TestUtils.assertResults(expectedErrorsWarnings, results);
clearAndInitRequiredFeedFields();
}
Aggregations