Search in sources :

Example 1 with VehicleValidator

use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator in project gtfs-realtime-validator by CUTR-at-USF.

the class VehicleValidatorTest method testE026.

/**
 * E026 - Invalid vehicle position
 */
@Test
public void testE026() {
    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();
    // 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);
    // Invalid lat - 1 error
    positionBuilder.setLatitude(1000f);
    positionBuilder.setLongitude(-82.4572f);
    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(E026, 1);
    TestUtils.assertResults(expected, results);
    // Invalid long - 1 error
    positionBuilder.setLatitude(27.9506f);
    positionBuilder.setLongitude(-1000);
    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(E026, 1);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) VehicleValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 2 with VehicleValidator

use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator in project gtfs-realtime-validator by CUTR-at-USF.

the class VehicleValidatorTest method testE052.

/**
 * E052 - vehicle.id is not unique
 */
@Test
public void testE052() {
    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 error, as there is only one vehicle in the feed
    results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    GtfsRealtime.VehicleDescriptor.Builder vehicleDescriptorBuilderConflict = GtfsRealtime.VehicleDescriptor.newBuilder();
    vehicleDescriptorBuilderConflict.setId("1");
    vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.addEntity(1, feedEntityBuilder.build());
    // 1 error for duplicate vehicle ID of 1
    results = vehicleValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(E052, 1);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) VehicleValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 3 with VehicleValidator

use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator 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();
}
Also used : HashMap(java.util.HashMap) VehicleValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 4 with VehicleValidator

use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator 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();
}
Also used : HashMap(java.util.HashMap) GtfsMetadata(edu.usf.cutr.gtfsrtvalidator.lib.validation.GtfsMetadata) VehicleValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 5 with VehicleValidator

use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator 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();
}
Also used : HashMap(java.util.HashMap) VehicleValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Aggregations

ValidationRule (edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule)8 FeedMessageTest (edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)8 VehicleValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator)8 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 GtfsMetadata (edu.usf.cutr.gtfsrtvalidator.lib.validation.GtfsMetadata)1