Search in sources :

Example 6 with TripDescriptorValidator

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

the class TripDescriptorValidatorTest method testE031.

/**
 * E031 - Alert informed_entity.route_id does not match informed_entity.trip.route_id
 */
@Test
public void testE031() {
    TripDescriptorValidator tripDescriptorValidator = new TripDescriptorValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    // In bullrunner-gtfs.zip routes.txt, route_id=A is a valid route
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    GtfsRealtime.EntitySelector.Builder entitySelectorBuilder = GtfsRealtime.EntitySelector.newBuilder();
    // Don't set either route_id (but set stop_id - we need at least one specifier) - W006 warning for no trip_id
    entitySelectorBuilder.setStopId("1234");
    entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
    alertBuilder.addInformedEntity(entitySelectorBuilder.build());
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(W006, 1);
    TestUtils.assertResults(expected, results);
    // Set informed_entity.route_id but not informed_entity.trip.route_id - no errors - W006 warning for no trip_id
    entitySelectorBuilder.setRouteId("A");
    entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
    alertBuilder.clearInformedEntity();
    alertBuilder.addInformedEntity(entitySelectorBuilder.build());
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(W006, 1);
    TestUtils.assertResults(expected, results);
    // Set informed_entity.trip.route_id but not informed_entity.route_id - W006 warning for no trip_id
    tripDescriptorBuilder.setRouteId("A");
    entitySelectorBuilder.clear();
    entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
    alertBuilder.clearInformedEntity();
    alertBuilder.addInformedEntity(entitySelectorBuilder.build());
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(W006, 1);
    TestUtils.assertResults(expected, results);
    // Set informed_entity.trip.route_id and informed_entity.route_id to the same values - W006 warning for no trip_id
    tripDescriptorBuilder.setRouteId("A");
    entitySelectorBuilder.setRouteId("A");
    entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
    alertBuilder.clearInformedEntity();
    alertBuilder.addInformedEntity(entitySelectorBuilder.build());
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(W006, 1);
    TestUtils.assertResults(expected, results);
    // Set informed_entity.trip.route_id and informed_entity.route_id to they don't match - 1 error
    tripDescriptorBuilder.setRouteId("A");
    entitySelectorBuilder.setRouteId("B");
    entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
    alertBuilder.clearInformedEntity();
    alertBuilder.addInformedEntity(entitySelectorBuilder.build());
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(E031, 1);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : TripDescriptorValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TripDescriptorValidator) HashMap(java.util.HashMap) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 7 with TripDescriptorValidator

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

the class TripDescriptorValidatorTest method testW009TripDescriptor.

/**
 * W009 - schedule_relationship not populated (for TripDescriptor)
 */
@Test
public void testW009TripDescriptor() {
    TripDescriptorValidator tripDescriptorValidator = new TripDescriptorValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    // In bullrunner-gtfs.zip trips.txt, trip_id=1 exists
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    GtfsRealtime.EntitySelector.Builder entitySelectorBuilder = GtfsRealtime.EntitySelector.newBuilder();
    // No schedule_relationship for trip - 3 warnings
    tripDescriptorBuilder.setTripId("1");
    entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
    alertBuilder.addInformedEntity(entitySelectorBuilder.build());
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(W009, 3);
    TestUtils.assertResults(expected, results);
    // Add schedule_relationship of SCHEDULED for trip - 0 warnings
    tripDescriptorBuilder.setTripId("1");
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    entitySelectorBuilder.setTrip(tripDescriptorBuilder.build());
    alertBuilder.clearInformedEntity();
    alertBuilder.addInformedEntity(entitySelectorBuilder.build());
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : TripDescriptorValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TripDescriptorValidator) HashMap(java.util.HashMap) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 8 with TripDescriptorValidator

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

the class TripDescriptorValidatorTest method testE032.

/**
 * E032 - Alert does not have an informed_entity
 */
@Test
public void testE032() {
    TripDescriptorValidator tripDescriptorValidator = new TripDescriptorValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.EntitySelector.Builder entitySelectorBuilder = GtfsRealtime.EntitySelector.newBuilder();
    // Don't set an informed_entity - 1 error
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(E032, 1);
    TestUtils.assertResults(expected, results);
    // Add an informed_entity with at least one specifier - no errors
    entitySelectorBuilder.setRouteId("A");
    alertBuilder.addInformedEntity(entitySelectorBuilder.build());
    feedEntityBuilder.setAlert(alertBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = tripDescriptorValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : TripDescriptorValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TripDescriptorValidator) HashMap(java.util.HashMap) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 9 with TripDescriptorValidator

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

the class TripDescriptorValidatorTest method testE024.

/**
 * E024 - trip direction_id does not match GTFS data
 */
@Test
public void testE024() {
    /**
     * In testagency2.txt, trips.txt has the following:
     *
     * route_id,service_id,trip_id,shape_id,block_id,wheelchair_accessible,trip_bikes_allowed,direction_id
     * 1,alldays,1.1,,,1,,0
     * 1,alldays,1.2,,,1,,0
     * 1,alldays,1.3,,,1,,0
     * 2,alldays,2.1,,,0,2,1
     * 2,alldays,2.2,,,0,2,1
     * 3,alldays,3.1,,,1,,
     *
     * So, direction_id for trip 1.1 is 0, and direction_id for trip 2.1 is 1.  trip 3.1 has no direction_id
     */
    TripDescriptorValidator tripIdValidator = new TripDescriptorValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    tripDescriptorBuilder.setTripId("1.1");
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    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, gtfsData2, gtfsData2Metadata, feedMessageBuilder.build(), null, null);
    // No GTFS-rt direction_id - no errors
    expected.clear();
    TestUtils.assertResults(expected, results);
    /**
     * Correct GTFS-rt direction_id value 0 - no errors
     */
    tripDescriptorBuilder.setTripId("1.1");
    tripDescriptorBuilder.setDirectionId(0);
    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, gtfsData2, gtfsData2Metadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    /**
     * Correct GTFS-rt direction_id value 1 - no errors
     */
    tripDescriptorBuilder.setTripId("2.1");
    tripDescriptorBuilder.setDirectionId(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, gtfsData2, gtfsData2Metadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    /**
     * Wrong GTFS-rt direction_id value 1 - 2 errors
     */
    tripDescriptorBuilder.setTripId("1.1");
    tripDescriptorBuilder.setDirectionId(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, gtfsData2, gtfsData2Metadata, feedMessageBuilder.build(), null, null);
    expected.put(E024, 2);
    TestUtils.assertResults(expected, results);
    /**
     * Wrong GTFS-rt direction_id value 0 - 2 errors
     */
    tripDescriptorBuilder.setTripId("2.1");
    tripDescriptorBuilder.setDirectionId(0);
    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, gtfsData2, gtfsData2Metadata, feedMessageBuilder.build(), null, null);
    expected.put(E024, 2);
    TestUtils.assertResults(expected, results);
    /**
     * GTFS-rt direction_id = 0, but no GTFS direction_id - 2 errors
     */
    tripDescriptorBuilder.setTripId("3.1");
    tripDescriptorBuilder.setDirectionId(0);
    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, gtfsData2, gtfsData2Metadata, feedMessageBuilder.build(), null, null);
    expected.put(E024, 2);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : TripDescriptorValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TripDescriptorValidator) HashMap(java.util.HashMap) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 10 with TripDescriptorValidator

use of edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TripDescriptorValidator 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();
}
Also used : TripDescriptorValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TripDescriptorValidator) HashMap(java.util.HashMap) 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)14 FeedMessageTest (edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)14 TripDescriptorValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TripDescriptorValidator)14 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)1