use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator in project gtfs-realtime-validator by CUTR-at-USF.
the class VehicleValidatorTest method testW004.
/**
* W004 - VehiclePosition has unrealistic speed
*/
@Test
public void testW004() {
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());
// No warnings, if speed 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), as they are required fields
positionBuilder.setLatitude(28.0587f);
positionBuilder.setLongitude(-82.4139f);
/**
* Valid speed of ~30 miles per hour
*/
positionBuilder.setSpeed(13.0f);
vehiclePositionBuilder.setPosition(positionBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
// No warnings, for valid speed
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Invalid negative speed
*/
positionBuilder.setSpeed(-13.0f);
vehiclePositionBuilder.setPosition(positionBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
// One warning for negative speed value
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(W004, 1);
TestUtils.assertResults(expected, results);
/**
* Abnormally large speed
*/
// ~ 70 miles per hour
positionBuilder.setSpeed(31.0f);
vehiclePositionBuilder.setPosition(positionBuilder.build());
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
// One warning for abnormally large speed
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(W004, 1);
TestUtils.assertResults(expected, results);
clearAndInitRequiredFeedFields();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator in project gtfs-realtime-validator by CUTR-at-USF.
the class VehicleValidatorTest method testE027.
/**
* E027 - Invalid vehicle bearing
*/
@Test
public void testE027() {
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());
// No warnings, 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();
// Set valid lat and long (USF Campus in Tampa, FL), as they are required fields
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());
// No warnings, if bearing isn't populated
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Valid bearing - no errors
positionBuilder.setBearing(15);
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);
// Invalid bearing - 1 error
positionBuilder.setBearing(-1);
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(E027, 1);
TestUtils.assertResults(expected, results);
// Invalid bearing - 1 error
positionBuilder.setBearing(361);
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(E027, 1);
TestUtils.assertResults(expected, results);
clearAndInitRequiredFeedFields();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator in project gtfs-realtime-validator by CUTR-at-USF.
the class VehicleValidatorTest method testE029.
/**
* E029 - Vehicle position outside trip shape buffer
*/
@Test
public void testE029() {
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());
/**
* Using modified USF Bull Runner feed WITHOUT shapes.txt - shouldn't throw any errors, as we don't have trip shapes to match against
*/
// Valid lat and long (USF Campus in Tampa, FL)
GtfsRealtime.Position.Builder positionBuilder = GtfsRealtime.Position.newBuilder();
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, inside agency bounding box but outside trip path (Downtown Tampa, FL) - would be an error if we had shapes.txt, but we don't for this assertion, so no errors
positionBuilder.setLatitude(28.057438520876673f);
positionBuilder.setLongitude(-82.43475437164307f);
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);
// Add trip_id - still no errors, because we don't have shapes.txt
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.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);
/**
* Using normal USF Bull Runner feed, which includes GTFS shapes.txt - now we can test for this error
*/
// No errors, if position isn't populated
vehiclePositionBuilder.clear();
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 (USF Marshal Center, which is within Route A path), but no trip_id in GTFS-rt - wouldn't be an error anyway, but we should still check this test case
positionBuilder.setLatitude(28.064065878608385f);
positionBuilder.setLongitude(-82.4131679534912f);
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);
// Now add trip_id=2 - still no error (point is within trip polygon)
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);
// Point is outside of USF Bull Runner route_id=A trip_id=2 polygon (buffer surrounding shapes.txt shape) - at University Mall, but no trip_id is set - so, no errors
vehiclePositionBuilder.clearTrip();
positionBuilder.setLatitude(28.057438520876673f);
positionBuilder.setLongitude(-82.43475437164307f);
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);
// 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
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.put(E029, 1);
TestUtils.assertResults(expected, results);
// Now add an alert saying there is a detour on trip_id=2 - point is allowed to be outside shape, so no error
GtfsRealtime.Alert.Builder alertBuilder = GtfsRealtime.Alert.newBuilder();
alertBuilder.setEffect(GtfsRealtime.Alert.Effect.DETOUR);
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);
// Make the alert to reference route_id=A instead of trip_id=2 - point is allowed to be outside shape, so still no error
alertBuilder = GtfsRealtime.Alert.newBuilder();
alertBuilder.setEffect(GtfsRealtime.Alert.Effect.DETOUR);
alertBuilder.addInformedEntity(GtfsRealtime.EntitySelector.newBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setRouteId("A").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 to something other than a detour with trip_id=2 - point is not allowed outside shape, one error
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.put(E029, 1);
TestUtils.assertResults(expected, results);
// Change the alert to something other than a detour with route_id=A instead of trip_id=2 - point is allowed to be outside shape, so still no error
alertBuilder = GtfsRealtime.Alert.newBuilder();
alertBuilder.setEffect(GtfsRealtime.Alert.Effect.UNKNOWN_EFFECT);
alertBuilder.addInformedEntity(GtfsRealtime.EntitySelector.newBuilder().setTrip(GtfsRealtime.TripDescriptor.newBuilder().setRouteId("A").build()));
feedEntityBuilder.setAlert(alertBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(E029, 1);
TestUtils.assertResults(expected, results);
// Change the alert back to DETOUR, but change the route_id to a different route - one error again, as Route A is no longer on detour
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.put(E029, 1);
TestUtils.assertResults(expected, results);
// Alert is DETOUR again, but change the trip_id to a different trip - one error again, as trip_id=2 is no longer on detour
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.put(E029, 1);
TestUtils.assertResults(expected, results);
clearAndInitRequiredFeedFields();
}
Aggregations