Search in sources :

Example 51 with ValidationRule

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

the class CrossFeedDescriptorValidatorTest method testE047.

/**
 * E047 - VehiclePosition and TripUpdate ID pairing mismatch
 */
@Test
public void testE047() {
    Map<ValidationRule, Integer> expected = new HashMap<>();
    CrossFeedDescriptorValidator crossFeedDescriptorValidator = new CrossFeedDescriptorValidator();
    GtfsRealtime.TripDescriptor.Builder tripA = GtfsRealtime.TripDescriptor.newBuilder();
    GtfsRealtime.VehicleDescriptor.Builder vehicleA = GtfsRealtime.VehicleDescriptor.newBuilder();
    // Set the same trip and vehicle ID to both TripUpdate and VehiclePosition - no errors
    vehicleA.setId("1");
    tripA.setTripId("1.1");
    tripUpdateBuilder.setVehicle(vehicleA.build());
    tripUpdateBuilder.setTrip(tripA.build());
    vehiclePositionBuilder.setVehicle(vehicleA.build());
    vehiclePositionBuilder.setTrip(tripA.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.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 1.1 and vehicle.id = 44, while TripUpdate still has trip_id 1.1 and vehicle_id 1 - 1 mismatch, so 1 error.
     * Also, 2 warnings for W003.
     */
    GtfsRealtime.TripDescriptor.Builder tripB = GtfsRealtime.TripDescriptor.newBuilder();
    GtfsRealtime.VehicleDescriptor.Builder vehicleB = GtfsRealtime.VehicleDescriptor.newBuilder();
    vehicleB.setId("44");
    tripB.setTripId("1.1");
    vehiclePositionBuilder.setVehicle(vehicleB.build());
    vehiclePositionBuilder.setTrip(tripB.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, 2);
    expected.put(ValidationRules.E047, 1);
    TestUtils.assertResults(expected, results);
    /**
     * Change the VehiclePosition to have trip_id 44 and vehicle.id = 1, while TripUpdate still has trip_id 1.1 and vehicle_id 1.
     * These trips aren't in the same block (same trips.txt block_id), so 1 mismatch, so 1 error.
     * Also, 2 warnings for W003.
     */
    vehicleB.setId("1");
    tripB.setTripId("44");
    vehiclePositionBuilder.setVehicle(vehicleB.build());
    vehiclePositionBuilder.setTrip(tripB.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, 2);
    expected.put(ValidationRules.E047, 1);
    TestUtils.assertResults(expected, results);
    /**
     * Change the VehiclePosition to have trip_id 44 and vehicle.id = 45, while TripUpdate still has trip_id 1.1 and vehicle_id 1 - 0 mismatch, so 0 errors.
     * Also, 4 warnings for W003.
     */
    vehicleB.setId("45");
    tripB.setTripId("44");
    vehiclePositionBuilder.setVehicle(vehicleB.build());
    vehiclePositionBuilder.setTrip(tripB.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    results = crossFeedDescriptorValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, null, null, feedMessageBuilder.build());
    expected.clear();
    expected.put(ValidationRules.W003, 4);
    TestUtils.assertResults(expected, results);
    /**
     * Set the VehiclePosition trip_id to empty string (and create two entities like this, to make sure catch this
     * case - see https://github.com/CUTR-at-USF/gtfs-realtime-validator/issues/241#issuecomment-313194304, although
     * we're no longer using HashBiMaps), and change TripUpdate to trip_id 1.1 and vehicle_id 1 - 0 mismatch, so 0
     * errors. Also, 4 warnings for W003 (2 for TripUpdate, and 1 for each VehiclePosition).
     */
    vehicleB.setId("45");
    tripB.setTripId("");
    vehiclePositionBuilder.setVehicle(vehicleB.build());
    vehiclePositionBuilder.setTrip(tripB.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    vehicleB.setId("100");
    tripB.setTripId("");
    vehiclePositionBuilder.setVehicle(vehicleB.build());
    vehiclePositionBuilder.setTrip(tripB.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedEntityBuilder.clearTripUpdate();
    feedMessageBuilder.addEntity(1, feedEntityBuilder.build());
    results = crossFeedDescriptorValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, null, null, feedMessageBuilder.build());
    expected.clear();
    expected.put(ValidationRules.W003, 4);
    TestUtils.assertResults(expected, results);
    /**
     * Clear the VehiclePosition trip_id (and create two entities like this 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), while TripUpdate still has trip_id 1.1 and vehicle_id 1 - 0 mismatch, so 0 errors.
     * Also, 4 warnings for W003 (2 for TripUpdate, and 1 for each VehiclePosition).
     */
    vehicleB.setId("45");
    tripB.clearTripId();
    vehiclePositionBuilder.setVehicle(vehicleB.build());
    vehiclePositionBuilder.setTrip(tripB.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    vehicleB.setId("100");
    tripB.clearTripId();
    vehiclePositionBuilder.setVehicle(vehicleB.build());
    vehiclePositionBuilder.setTrip(tripB.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(1, feedEntityBuilder.build());
    results = crossFeedDescriptorValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, null, null, feedMessageBuilder.build());
    expected.clear();
    expected.put(ValidationRules.W003, 4);
    TestUtils.assertResults(expected, results);
    /**
     * Set the TripUpdate vehicle.id to empty string and VehiclePosition trip_id to empty string (and create two entities like this to make 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) - 0 mismatch, so 0 errors.
     * Also, 4 warnings for W003 (two for each entity with empty string IDs).
     */
    vehicleB.setId("45");
    tripB.setTripId("");
    vehiclePositionBuilder.setTrip(tripB);
    vehiclePositionBuilder.setVehicle(vehicleB);
    tripA.setTripId("1");
    vehicleA.setId("");
    tripUpdateBuilder.setTrip(tripA);
    tripUpdateBuilder.setVehicle(vehicleA);
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    vehicleB.setId("46");
    tripB.setTripId("");
    vehiclePositionBuilder.setTrip(tripB);
    vehiclePositionBuilder.setVehicle(vehicleB);
    tripA.setTripId("2");
    vehicleA.setId("");
    tripUpdateBuilder.setTrip(tripA);
    tripUpdateBuilder.setVehicle(vehicleA);
    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.clear();
    expected.put(ValidationRules.W003, 4);
    TestUtils.assertResults(expected, results);
    /**
     * Clear the TripUpdate vehicle.id and VehiclePosition trip_id (and create two entities like this 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) - 0 mismatch, so 0 errors.
     * Also, 4 warnings for W003 (two for each entity with cleared IDs).
     */
    vehicleB.setId("45");
    tripB.clearTripId();
    vehiclePositionBuilder.setTrip(tripB);
    vehiclePositionBuilder.setVehicle(vehicleB);
    tripA.setTripId("1");
    vehicleA.clearId();
    tripUpdateBuilder.setTrip(tripA);
    tripUpdateBuilder.setVehicle(vehicleA);
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    vehicleB.setId("46");
    tripB.clearTripId();
    vehiclePositionBuilder.setTrip(tripB);
    vehiclePositionBuilder.setVehicle(vehicleB);
    tripA.setTripId("2");
    vehicleA.clearId();
    tripUpdateBuilder.setTrip(tripA);
    tripUpdateBuilder.setVehicle(vehicleA);
    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.clear();
    expected.put(ValidationRules.W003, 4);
    TestUtils.assertResults(expected, results);
    /**
     * Change the TripUpdate to have trip_id 6.1 and vehicle.id = 45, while VehiclePosition is changed to have trip_id 7.1 and vehicle_id 45.
     * Trips 6.1 and 7.1 have the same block_id block.1 (i.e., the same vehicle is going to serve both trips), so having the same vehicle_id is ok - 0 errors.
     * See https://github.com/CUTR-at-USF/gtfs-realtime-validator/issues/255 for details on same vehicle running more than one trip in the same block.
     * Also 2 occurrences of W003.
     */
    vehicleA.setId("45");
    tripA.setTripId("6.1");
    tripUpdateBuilder.setVehicle(vehicleA.build());
    tripUpdateBuilder.setTrip(tripA.build());
    vehicleB.setId("45");
    tripB.setTripId("7.1");
    vehiclePositionBuilder.setVehicle(vehicleB.build());
    vehiclePositionBuilder.setTrip(tripB.build());
    feedEntityBuilder.setTripUpdate(tripUpdateBuilder.build());
    feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
    feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
    // Remove the additional entity created in previous tests
    feedMessageBuilder.removeEntity(1);
    results = crossFeedDescriptorValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, null, null, feedMessageBuilder.build());
    expected.clear();
    expected.put(ValidationRules.W003, 2);
    TestUtils.assertResults(expected, results);
}
Also used : HashMap(java.util.HashMap) CrossFeedDescriptorValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.rules.CrossFeedDescriptorValidator) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test) FeedMessageTest(edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)

Example 52 with ValidationRule

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

the class UtilTest method testAssertResultsThrowExceptionMoreActual.

@Test(expected = AssertionError.class)
public void testAssertResultsThrowExceptionMoreActual() {
    // Make sure we fail if we have actual results that weren't expected
    List<ErrorListHelperModel> results = new ArrayList<>();
    MessageLogModel modelE001 = new MessageLogModel(E001);
    OccurrenceModel errorE001 = new OccurrenceModel(String.valueOf(MIN_POSIX_TIME));
    List<OccurrenceModel> errorListE001 = new ArrayList<>();
    errorListE001.add(errorE001);
    results.add(new ErrorListHelperModel(modelE001, errorListE001));
    Map<ValidationRule, Integer> expected = new HashMap<>();
    // No expected results included for E001, but there is one actual error for E001 - this should throw an AssertionError
    TestUtils.assertResults(expected, results);
}
Also used : ErrorListHelperModel(edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel) MessageLogModel(edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel) OccurrenceModel(edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test)

Example 53 with ValidationRule

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

the class UtilTest method testAssertResultsThrowExceptionMismatchActualExpected.

@Test(expected = AssertionError.class)
public void testAssertResultsThrowExceptionMismatchActualExpected() {
    // Make sure we fail if we have actual results that don't match the expected results
    List<ErrorListHelperModel> results = new ArrayList<>();
    MessageLogModel modelE001 = new MessageLogModel(E001);
    OccurrenceModel errorE001 = new OccurrenceModel(String.valueOf(MIN_POSIX_TIME));
    List<OccurrenceModel> errorListE001 = new ArrayList<>();
    errorListE001.add(errorE001);
    results.add(new ErrorListHelperModel(modelE001, errorListE001));
    Map<ValidationRule, Integer> expected = new HashMap<>();
    expected.put(E002, 1);
    // We are expecting error for E002, but get one for E001 - this should throw an AssertionError
    TestUtils.assertResults(expected, results);
}
Also used : ErrorListHelperModel(edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel) MessageLogModel(edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel) OccurrenceModel(edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test)

Example 54 with ValidationRule

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

the class UtilTest method testAssertResults.

/**
 * Make sure our utility method TestUtils.assertResults() properly asserts number of expected==actual
 * rule occurrences
 */
@Test
public void testAssertResults() {
    MessageLogModel modelE001 = new MessageLogModel(E001);
    OccurrenceModel errorE001 = new OccurrenceModel(String.valueOf(MIN_POSIX_TIME));
    List<OccurrenceModel> errorListE001 = new ArrayList<>();
    List<ErrorListHelperModel> results = new ArrayList<>();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    // Test empty list of error results and empty hashmap
    TestUtils.assertResults(expected, results);
    // Test list of error results, but without a MessageLogModel
    results.add(new ErrorListHelperModel(modelE001, errorListE001));
    TestUtils.assertResults(expected, results);
    // Test list of error results, with one MessageLogModel
    errorListE001.add(errorE001);
    expected.put(E001, 1);
    TestUtils.assertResults(expected, results);
    // Test list of error results, with two MessageLogModels
    errorListE001.add(errorE001);
    expected.put(E001, 2);
    TestUtils.assertResults(expected, results);
}
Also used : MessageLogModel(edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel) ErrorListHelperModel(edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel) OccurrenceModel(edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test)

Example 55 with ValidationRule

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

the class UtilTest method testAssertResultsThrowExceptionMoreExpected.

@Test(expected = AssertionError.class)
public void testAssertResultsThrowExceptionMoreExpected() {
    // Make sure we fail if we have expected occurrences that aren't included in results
    List<ErrorListHelperModel> results = new ArrayList<>();
    MessageLogModel modelE001 = new MessageLogModel(E001);
    OccurrenceModel errorE001 = new OccurrenceModel(String.valueOf(MIN_POSIX_TIME));
    List<OccurrenceModel> errorListE001 = new ArrayList<>();
    errorListE001.add(errorE001);
    results.add(new ErrorListHelperModel(modelE001, errorListE001));
    Map<ValidationRule, Integer> expected = new HashMap<>();
    expected.put(E001, 1);
    // We're expecting 1 error for E001 and 1 error for E002, but get one actual error for E001 - this should throw an AssertionError
    expected.put(E002, 1);
    TestUtils.assertResults(expected, results);
}
Also used : ErrorListHelperModel(edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel) MessageLogModel(edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel) OccurrenceModel(edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel) ValidationRule(edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule) Test(org.junit.Test)

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