Search in sources :

Example 1 with AgencyNotFoundForRouteException

use of org.onebusaway.gtfs.serialization.mappings.AgencyNotFoundForRouteException in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsReaderTest method testDefaultAgencyForRoutes.

@Test
public void testDefaultAgencyForRoutes() throws IOException {
    MockGtfs gtfs = MockGtfs.create();
    gtfs.putAgencies(1);
    gtfs.putRoutes(1);
    gtfs.putTrips(1, "r0", "sid0");
    gtfs.putStops(1);
    gtfs.putStopTimes("t0", "s0");
    {
        GtfsMutableRelationalDao dao = gtfs.read(newReader("tacos"));
        assertNotNull(dao.getRouteForId(new AgencyAndId("a0", "r0")));
    }
    {
        gtfs.putAgencies(2);
        try {
            gtfs.read(newReader("tacos"));
            fail();
        } catch (CsvEntityIOException e) {
            MissingRequiredFieldException ex = (MissingRequiredFieldException) e.getCause();
            assertEquals("agency_id", ex.getFieldName());
            assertEquals(Route.class, ex.getEntityType());
        }
    }
    {
        gtfs.putAgencies(2);
        gtfs.putRoutes(1, "agency_id=a1");
        GtfsMutableRelationalDao dao = gtfs.read(newReader("tacos"));
        assertNotNull(dao.getRouteForId(new AgencyAndId("a1", "r0")));
    }
    {
        gtfs.putAgencies(2);
        gtfs.putRoutes(1, "agency_id=a2");
        try {
            gtfs.read(newReader("tacos"));
            fail();
        } catch (CsvEntityIOException e) {
            assertTrue(e.getCause() instanceof AgencyNotFoundForRouteException);
        }
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) MissingRequiredFieldException(org.onebusaway.csv_entities.exceptions.MissingRequiredFieldException) CsvEntityIOException(org.onebusaway.csv_entities.exceptions.CsvEntityIOException) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) AgencyNotFoundForRouteException(org.onebusaway.gtfs.serialization.mappings.AgencyNotFoundForRouteException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 CsvEntityIOException (org.onebusaway.csv_entities.exceptions.CsvEntityIOException)1 MissingRequiredFieldException (org.onebusaway.csv_entities.exceptions.MissingRequiredFieldException)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 AgencyNotFoundForRouteException (org.onebusaway.gtfs.serialization.mappings.AgencyNotFoundForRouteException)1 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)1 MockGtfs (org.onebusaway.gtfs.services.MockGtfs)1