Search in sources :

Example 6 with ValidationRule

use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.

the class TimestampValidatorTest method testW001.

@Test
public void testW001() {
    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);
    // Timestamp will be zero initially in FeedHeader, TripUpdate and VehiclePosition. Should return 3 results.
    vehiclePositionBuilder.setVehicle(GtfsRealtime.VehicleDescriptor.newBuilder());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(W001, 3);
    TestUtils.assertResults(expected, results);
    // Populate timestamp to any value greater than zero in FeedHeader
    feedHeaderBuilder.setTimestamp(MIN_POSIX_TIME);
    feedMessageBuilder.setHeader(feedHeaderBuilder.build());
    // Invalid timestamp in TripUpdate and VehiclePosition. Should return 2 results.
    results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(W001, 2);
    TestUtils.assertResults(expected, results);
    // TripDescriptor is a required field in tripUpdate
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // Populate timestamp to any value greater than zero in TripUpdate.
    tripUpdateBuilder.setTimestamp(MIN_POSIX_TIME);
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // Invalid timestamp only in VehiclePosition. Should return 1 results.
    results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.put(W001, 1);
    TestUtils.assertResults(expected, results);
    vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME);
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // Now timestamp is populated in FeedHeader, TripUpdate and VehiclePosition . Should return no error.
    results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) TimestampValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TimestampValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 7 with ValidationRule

use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.

the class TimestampValidatorTest method testW008.

/**
 * W008 - Header timestamp is older than 65 seconds
 */
@Test
public void testW008() {
    TimestampValidator timestampValidator = new TimestampValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    // Set valid trip_id = 1.1
    tripDescriptorBuilder.setTripId("1.1");
    long currentTimeMillis = System.currentTimeMillis();
    long currentTimeSec = TimeUnit.MILLISECONDS.toSeconds(currentTimeMillis);
    /**
     * Use current time - no warnings
     */
    feedHeaderBuilder.setTimestamp(currentTimeSec);
    feedMessageBuilder.setHeader(feedHeaderBuilder.build());
    tripUpdateBuilder.setTimestamp(currentTimeSec);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
    vehiclePositionBuilder.setTimestamp(currentTimeSec);
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    GtfsRealtime.FeedMessage currentIteration = feedMessageBuilder.setEntity(0, feedEntityBuilder.build()).build();
    results = timestampValidator.validate(currentTimeMillis, gtfsData, gtfsDataMetadata, currentIteration, null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    /**
     * Use current time minus 70 seconds (feed is 1 min 10 sec old) - 1 warning
     */
    feedHeaderBuilder.setTimestamp(currentTimeSec - 70);
    feedMessageBuilder.setHeader(feedHeaderBuilder.build());
    tripUpdateBuilder.setTimestamp(currentTimeSec - 70);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
    vehiclePositionBuilder.setTimestamp(currentTimeSec - 70);
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    currentIteration = feedMessageBuilder.setEntity(0, feedEntityBuilder.build()).build();
    results = timestampValidator.validate(currentTimeMillis, gtfsData, gtfsDataMetadata, currentIteration, null, null);
    expected.put(W008, 1);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) TimestampValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TimestampValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) GtfsRealtime(com.google.transit.realtime.GtfsRealtime) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 8 with ValidationRule

use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.

the class TimestampValidatorTest method testE018.

@Test
public void testE018() {
    TimestampValidator timestampValidator = new TimestampValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    // Set valid trip_id = 1.1
    tripDescriptorBuilder.setTripId("1.1");
    final long CURRENT_TIME_MILLIS = TimeUnit.SECONDS.toMillis(MIN_POSIX_TIME);
    /**
     * No previous feed message (i.e., it's the first iteration) - no errors
     */
    feedHeaderBuilder.setTimestamp(MIN_POSIX_TIME + 1);
    feedMessageBuilder.setHeader(feedHeaderBuilder.build());
    tripUpdateBuilder.setTimestamp(MIN_POSIX_TIME + 1);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
    vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME + 1);
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    GtfsRealtime.FeedMessage currentIteration = feedMessageBuilder.setEntity(0, feedEntityBuilder.build()).build();
    // No previous iteration - no errors
    results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, currentIteration, null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    /**
     * Set the previous iteration header timestamp so it's less that the current iteration - 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());
    GtfsRealtime.FeedMessage previousIteration = feedMessageBuilder.setEntity(0, feedEntityBuilder.build()).build();
    results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, currentIteration, previousIteration, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    /**
     * Set the previous iteration header timestamp so it's greater than that the current iteration - 1 error
     */
    feedHeaderBuilder.setTimestamp(MIN_POSIX_TIME + 2);
    feedMessageBuilder.setHeader(feedHeaderBuilder.build());
    tripUpdateBuilder.setTimestamp(MIN_POSIX_TIME + 2);
    tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
    vehiclePositionBuilder.setTimestamp(MIN_POSIX_TIME + 2);
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    previousIteration = feedMessageBuilder.setEntity(0, feedEntityBuilder.build()).build();
    results = timestampValidator.validate(CURRENT_TIME_MILLIS, gtfsData, gtfsDataMetadata, currentIteration, previousIteration, null);
    expected.put(E018, 1);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : HashMap(java.util.HashMap) TimestampValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TimestampValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) GtfsRealtime(com.google.transit.realtime.GtfsRealtime) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 9 with ValidationRule

use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.

the class TripDescriptorValidatorTest method testE033.

/**
 * E033 - Alert informed_entity does not have any specifiers
 */
@Test
public void testE033() {
    TripDescriptorValidator tripDescriptorValidator = new TripDescriptorValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.EntitySelector.Builder entitySelectorBuilder = GtfsRealtime.EntitySelector.newBuilder();
    // Add an informed_entity without any specifiers - 1 error
    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(E033, 1);
    TestUtils.assertResults(expected, results);
    // Set stop_id as specifier - 0 errors
    entitySelectorBuilder.clear();
    entitySelectorBuilder.setStopId("1234");
    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.clear();
    TestUtils.assertResults(expected, results);
    // Set informed_entity.route_id as specifier - 0 errors
    entitySelectorBuilder.clear();
    entitySelectorBuilder.setRouteId("A");
    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.clear();
    TestUtils.assertResults(expected, results);
    // Set agency_id as specifier - 0 errors
    entitySelectorBuilder.clear();
    entitySelectorBuilder.setAgencyId("agency");
    alertBuilder.clearInformedEntity();
    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);
    // Set route_type as specifier - 0 errors
    entitySelectorBuilder.clear();
    entitySelectorBuilder.setRouteType(0);
    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.clear();
    TestUtils.assertResults(expected, results);
    // Set trip_id as specifier - 0 errors
    entitySelectorBuilder.clear();
    entitySelectorBuilder.setTrip(GtfsRealtime.TripDescriptor.newBuilder().setTripId("1").setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED).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.clear();
    TestUtils.assertResults(expected, results);
    // Set informed_entity.trip.route_id as specifier - 1 warning W006 for missing trip_id
    entitySelectorBuilder.clear();
    entitySelectorBuilder.setTrip(GtfsRealtime.TripDescriptor.newBuilder().setRouteId("A").setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED).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);
    // Clear all entity selectors again and don't set any - 1 error
    entitySelectorBuilder.clear();
    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.clear();
    expected.put(E033, 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 10 with ValidationRule

use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.

the class TripDescriptorValidatorTest method testE020.

/**
 * E020 - Invalid start_time format
 */
@Test
public void testE020() {
    TripDescriptorValidator tripIdValidator = new TripDescriptorValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
    tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
    // Set valid trip_id = 1.1 that's in the Bull Runner GTFS data
    tripDescriptorBuilder.setTripId("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, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    // No start_time - no errors
    expected.clear();
    TestUtils.assertResults(expected, results);
    // Set valid start_time - no errors
    tripDescriptorBuilder.setStartTime("00:20:00");
    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, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.clear();
    TestUtils.assertResults(expected, results);
    // Set invalid start_time - 2 errors
    tripDescriptorBuilder.setStartTime("5:15:35");
    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, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
    expected.put(E020, 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)

Aggregations

ValidationRule (edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule)65 Test (org.junit.Test)62 HashMap (java.util.HashMap)59 FeedMessageTest (edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)58 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)23 TripDescriptorValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TripDescriptorValidator)14 StopTimeUpdateValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.StopTimeUpdateValidator)13 TimestampValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.TimestampValidator)11 VehicleValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.VehicleValidator)8 ErrorListHelperModel (edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel)6 MessageLogModel (edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel)4 OccurrenceModel (edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel)4 FrequencyTypeZeroValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.FrequencyTypeZeroValidator)3 HeaderValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.HeaderValidator)3 CrossFeedDescriptorValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.CrossFeedDescriptorValidator)2 StopValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.StopValidator)2 GtfsMetadata (edu.usf.cutr.gtfsrtvalidator.lib.validation.GtfsMetadata)1 StopLocationTypeValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.gtfs.StopLocationTypeValidator)1 FrequencyTypeOneValidator (edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.FrequencyTypeOneValidator)1 Field (java.lang.reflect.Field)1