use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class FrequencyTypeZeroValidatorTest method testE013.
/**
* E013 - Frequency type 0 trip schedule_relationship should be UNSCHEDULED or empty
*/
@Test
public void testE013() {
FrequencyTypeZeroValidator frequencyTypeZeroValidator = new FrequencyTypeZeroValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
// Set valid trip_id, start_date, and start_time so no errors/warnings for these attributes
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("1");
tripDescriptorBuilder.setStartDate("4-24-2016");
tripDescriptorBuilder.setStartTime("08:00:00AM");
// FIXME - This should result in no SCHEDULE_RELATIONSHIP, but it results in SCHEDULED (see first assertion below)
tripDescriptorBuilder.clearScheduleRelationship();
// Set valid vehicle_id so no warnings for these
GtfsRealtime.VehicleDescriptor.Builder vehicleDescriptorBuilder = GtfsRealtime.VehicleDescriptor.newBuilder();
vehicleDescriptorBuilder.setId("vehicle_A");
feedHeaderBuilder.setTimestamp(TimestampUtils.MIN_POSIX_TIME);
feedMessageBuilder.setHeader(feedHeaderBuilder.build());
tripUpdateBuilder.setTimestamp(TimestampUtils.MIN_POSIX_TIME);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
tripUpdateBuilder.setVehicle(vehicleDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTimestamp(TimestampUtils.MIN_POSIX_TIME);
vehiclePositionBuilder.setVehicle(vehicleDescriptorBuilder.build());
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
// Start with an empty schedule relationship - that should be fine for exact_times=0 trips - no errors
// FIXME - For some reason it seems we can't clear the SCHEDULE_RELATIONSHIP, so right now we can't test for this scenario
// results = frequencyTypeZeroValidator.validate(MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null);
// TestUtils.assertResults(E013, results, 0);
// Change to UNSCHEDULED schedule relationship - this is also ok for exact_times=0 trips
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.UNSCHEDULED);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = frequencyTypeZeroValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Change to ADDED schedule relationship - not allowed for exact_times=0 trips - 2 errors
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.ADDED);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = frequencyTypeZeroValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(ValidationRules.E013, 2);
TestUtils.assertResults(expected, results);
// Change to CANCELED schedule relationship - not allowed for exact_times=0 trips - 2 errors
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.CANCELED);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = frequencyTypeZeroValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(ValidationRules.E013, 2);
TestUtils.assertResults(expected, results);
// Change to SCHEDULED schedule relationship - not allowed for exact_times=0 trips - 2 errors
tripDescriptorBuilder.setScheduleRelationship(GtfsRealtime.TripDescriptor.ScheduleRelationship.SCHEDULED);
tripUpdateBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setTripUpdate(tripUpdateBuilder);
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = frequencyTypeZeroValidator.validate(TimestampUtils.MIN_POSIX_TIME, bullRunnerGtfs, bullRunnerGtfsMetadata, feedMessageBuilder.build(), null, null);
expected.put(ValidationRules.E013, 2);
TestUtils.assertResults(expected, results);
clearAndInitRequiredFeedFields();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class FrequencyTypeOneValidatorTest method testE019.
/**
* E019 - GTFS-rt trip start_date and start_time must match GTFS data
* <p>
* testagency.zip (gtfsData) has exact_times = 1 trips for 15.1 with a 1 hr (3600 sec) headway
*/
@Test
public void testE019() {
Map<ValidationRule, Integer> expected = new HashMap<>();
/**
* Set start_time to match GTFS start_time exactly - 6am - no errors
*/
FrequencyTypeOneValidator frequencyTypeOneValidator = new FrequencyTypeOneValidator();
GtfsRealtime.TripDescriptor.Builder tripDescriptorBuilder = GtfsRealtime.TripDescriptor.newBuilder();
tripDescriptorBuilder.setTripId("15.1");
tripDescriptorBuilder.setStartTime("06:00:00");
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);
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = frequencyTypeOneValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Set start_time to be a multiple of headway_secs - 1 hr later at 7:00am - 0 errors
*/
tripDescriptorBuilder.setTripId("15.1");
tripDescriptorBuilder.setStartTime("07:00:00");
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);
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = frequencyTypeOneValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
/**
* Set start_time to NOT be a multiple of headway_secs - 2.5 hr later at 7:30am - 2 errors
*/
tripDescriptorBuilder.setTripId("15.1");
tripDescriptorBuilder.setStartTime("07:30:00");
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);
vehiclePositionBuilder.setTrip(tripDescriptorBuilder.build());
feedEntityBuilder.setVehicle(vehiclePositionBuilder.build());
feedMessageBuilder.setEntity(0, feedEntityBuilder.build());
results = frequencyTypeOneValidator.validate(MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(E019, 2);
TestUtils.assertResults(expected, results);
clearAndInitRequiredFeedFields();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class HeaderValidatorTest method testE039.
/**
* E039 - FULL_DATASET feeds should not include entity.is_deleted
*/
@Test
public void testE039() {
HeaderValidator headerValidator = new HeaderValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.FeedHeader.Builder headerBuilder = GtfsRealtime.FeedHeader.newBuilder();
headerBuilder.setGtfsRealtimeVersion("1.0");
// FULL_DATASET feed without any entities - no errors
headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET);
feedMessageBuilder.setHeader(headerBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// DIFFERENTIAL feed without any entities - no errors
headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.DIFFERENTIAL);
feedMessageBuilder.setHeader(headerBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// FULL_DATASET feed without is_deleted field in any entities - no errors
headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET);
feedMessageBuilder.setHeader(headerBuilder.build());
feedMessageBuilder.addEntity(feedEntityBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// DIFFERENTIAL feed without is_deleted field in any entities - no errors
headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.DIFFERENTIAL);
feedMessageBuilder.setHeader(headerBuilder.build());
feedMessageBuilder.addEntity(feedEntityBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// FULL_DATASET feed with is_deleted field in an entity - 1 error
headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET);
feedMessageBuilder.setHeader(headerBuilder.build());
feedEntityBuilder.setIsDeleted(true);
feedMessageBuilder.addEntity(feedEntityBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(ValidationRules.E039, 1);
TestUtils.assertResults(expected, results);
// DIFFERENTIAL feed with is_deleted field in an entity - 0 errors
feedMessageBuilder.clearEntity();
headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.DIFFERENTIAL);
feedMessageBuilder.setHeader(headerBuilder.build());
feedEntityBuilder.setIsDeleted(true);
feedMessageBuilder.addEntity(feedEntityBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
clearAndInitRequiredFeedFields();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class HeaderValidatorTest method testE049.
/**
* E038 - Invalid header.gtfs_realtime_version
*/
@Test
public void testE049() {
HeaderValidator headerValidator = new HeaderValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.FeedHeader.Builder headerBuilder = GtfsRealtime.FeedHeader.newBuilder();
// GTFS-rt v1.0, and no incrementality - no errors
headerBuilder.setGtfsRealtimeVersion("1.0");
feedMessageBuilder.setHeader(headerBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// GTFS-rt v2.0, and no incrementality - 1 error
headerBuilder.setGtfsRealtimeVersion("2.0");
feedMessageBuilder.setHeader(headerBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(ValidationRules.E049, 1);
TestUtils.assertResults(expected, results);
// GTFS-rt v2.0, and has incrementality - no errors
headerBuilder.setGtfsRealtimeVersion("2.0");
headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET);
feedMessageBuilder.setHeader(headerBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
clearAndInitRequiredFeedFields();
}
use of edu.usf.cutr.gtfsrtvalidator.lib.model.ValidationRule in project gtfs-realtime-validator by CUTR-at-USF.
the class HeaderValidatorTest method testE038.
/**
* E038 - Invalid header.gtfs_realtime_version
*/
@Test
public void testE038() {
HeaderValidator headerValidator = new HeaderValidator();
Map<ValidationRule, Integer> expected = new HashMap<>();
GtfsRealtime.FeedHeader.Builder headerBuilder = GtfsRealtime.FeedHeader.newBuilder();
// Valid version - no errors
headerBuilder.setGtfsRealtimeVersion("1.0");
feedMessageBuilder.setHeader(headerBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Valid version, and set incrementality to avoid E049 - no errors
headerBuilder.setGtfsRealtimeVersion("2.0");
headerBuilder.setIncrementality(GtfsRealtime.FeedHeader.Incrementality.FULL_DATASET);
feedMessageBuilder.setHeader(headerBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.clear();
TestUtils.assertResults(expected, results);
// Bad version - 1 error
headerBuilder.setGtfsRealtimeVersion("3.0");
feedMessageBuilder.setHeader(headerBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(ValidationRules.E038, 1);
TestUtils.assertResults(expected, results);
// Bad version - one error
headerBuilder.setGtfsRealtimeVersion("1");
feedMessageBuilder.setHeader(headerBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(ValidationRules.E038, 1);
TestUtils.assertResults(expected, results);
// Bad version - one error
headerBuilder.setGtfsRealtimeVersion("abcd");
feedMessageBuilder.setHeader(headerBuilder.build());
results = headerValidator.validate(TimestampUtils.MIN_POSIX_TIME, gtfsData, gtfsDataMetadata, feedMessageBuilder.build(), null, null);
expected.put(ValidationRules.E038, 1);
TestUtils.assertResults(expected, results);
clearAndInitRequiredFeedFields();
}
Aggregations