Search in sources :

Example 11 with ErrorListHelperModel

use of edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel 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 12 with ErrorListHelperModel

use of edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel 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 13 with ErrorListHelperModel

use of edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel 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)

Example 14 with ErrorListHelperModel

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

the class StopLocationTypeValidatorTest method testE010.

/**
 * E010 - If location_type is used in stops.txt, all stops referenced in stop_times.txt must have location_type of 0
 */
@Test
public void testE010() {
    StopLocationTypeValidator stopLocationValidator = new StopLocationTypeValidator();
    Map<ValidationRule, Integer> expected = new HashMap<>();
    // gtfsData does not contain location_type = 1 for stop_id. Therefore returns 0 results
    results = stopLocationValidator.validate(gtfsData);
    for (ErrorListHelperModel error : results) {
        assertEquals(0, error.getOccurrenceList().size());
    }
    // gtfsData2 contains location_type = 1 for stop_ids. Therefore returns errorcount = (number of location_type = 1 for stop_ids)
    results = stopLocationValidator.validate(gtfsData2);
    expected.put(E010, 1);
    TestUtils.assertResults(expected, results);
    clearAndInitRequiredFeedFields();
}
Also used : ErrorListHelperModel(edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel) StopLocationTypeValidator(edu.usf.cutr.gtfsrtvalidator.lib.validation.gtfs.StopLocationTypeValidator) 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 15 with ErrorListHelperModel

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

the class StopLocationTypeValidator method validate.

@Override
public List<ErrorListHelperModel> validate(GtfsDaoImpl gtfsData) {
    List<OccurrenceModel> e010List = new ArrayList<>();
    Collection<StopTime> stopTimes = gtfsData.getAllStopTimes();
    Set<Stop> checkedStops = new HashSet<>();
    for (StopTime stopTime : stopTimes) {
        if (!checkedStops.contains(stopTime.getStop())) {
            checkedStops.add(stopTime.getStop());
            if (stopTime.getStop().getLocationType() != 0) {
                RuleUtils.addOccurrence(E010, "stop_id " + stopTime.getStop().getId(), e010List, _log);
            }
        }
    }
    List<ErrorListHelperModel> errors = new ArrayList<>();
    if (!e010List.isEmpty()) {
        errors.add(new ErrorListHelperModel(new MessageLogModel(E010), e010List));
    }
    return errors;
}
Also used : ErrorListHelperModel(edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel) MessageLogModel(edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel) Stop(org.onebusaway.gtfs.model.Stop) OccurrenceModel(edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel) StopTime(org.onebusaway.gtfs.model.StopTime)

Aggregations

ErrorListHelperModel (edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel)19 MessageLogModel (edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel)14 OccurrenceModel (edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel)14 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)10 ArrayList (java.util.ArrayList)9 ValidationRule (edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule)6 Test (org.junit.Test)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 HashMap (java.util.HashMap)2 List (java.util.List)2 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 TextFormat (com.google.protobuf.TextFormat)1 BatchProcessor (edu.usf.cutr.gtfsrtvalidator.lib.batch.BatchProcessor)1 FeedMessageTest (edu.usf.cutr.gtfsrtvalidator.lib.test.FeedMessageTest)1 GtfsUtils (edu.usf.cutr.gtfsrtvalidator.lib.util.GtfsUtils)1 SortUtils (edu.usf.cutr.gtfsrtvalidator.lib.util.SortUtils)1 TimestampUtils (edu.usf.cutr.gtfsrtvalidator.lib.util.TimestampUtils)1 TimestampUtils.getElapsedTime (edu.usf.cutr.gtfsrtvalidator.lib.util.TimestampUtils.getElapsedTime)1 TimestampUtils.getElapsedTimeString (edu.usf.cutr.gtfsrtvalidator.lib.util.TimestampUtils.getElapsedTimeString)1