Search in sources :

Example 1 with MockGtfs

use of org.onebusaway.gtfs.services.MockGtfs in project OpenTripPlanner by opentripplanner.

the class GtfsGraphBuilderModuleTest method testBikesByDefault.

@Test
public void testBikesByDefault() throws IOException {
    // We configure two trip: one with unknown bikes_allowed and the second with no bikes
    // allowed.
    MockGtfs gtfs = getSimpleGtfs();
    gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,2");
    gtfs.putStopTimes("t0,t1", "s0,s1");
    List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
    bundleList.get(0).setDefaultBikesAllowed(true);
    _builder = new GtfsModule(bundleList);
    Graph graph = new Graph();
    _builder.buildGraph(graph, _extra);
    graph.index(new DefaultStreetVertexIndexFactory());
    // Feed id is used instead of the agency id for OBA entities.
    GtfsBundle gtfsBundle = bundleList.get(0);
    GtfsFeedId feedId = gtfsBundle.getFeedId();
    Trip trip = graph.index.tripForId.get(new AgencyAndId(feedId.getId(), "t0"));
    TripPattern pattern = graph.index.patternForTrip.get(trip);
    List<Trip> trips = pattern.getTrips();
    assertEquals(BikeAccess.ALLOWED, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t0"))));
    assertEquals(BikeAccess.NOT_ALLOWED, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t1"))));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Test(org.junit.Test)

Example 2 with MockGtfs

use of org.onebusaway.gtfs.services.MockGtfs in project OpenTripPlanner by opentripplanner.

the class GtfsGraphBuilderModuleTest method getSimpleGtfs.

private MockGtfs getSimpleGtfs() throws IOException {
    MockGtfs gtfs = MockGtfs.create();
    gtfs.putAgencies(1);
    gtfs.putRoutes(1);
    gtfs.putStops(2);
    gtfs.putCalendars(1);
    gtfs.putTrips(1, "r0", "sid0");
    gtfs.putStopTimes("t0", "s0,s1");
    return gtfs;
}
Also used : MockGtfs(org.onebusaway.gtfs.services.MockGtfs)

Example 3 with MockGtfs

use of org.onebusaway.gtfs.services.MockGtfs in project OpenTripPlanner by opentripplanner.

the class GTFSPatternHopFactoryTest method testBikesAllowed.

@Test
public void testBikesAllowed() throws IOException {
    MockGtfs gtfs = MockGtfs.create();
    gtfs.putAgencies(1);
    gtfs.putRoutes(1);
    gtfs.putStops(2);
    gtfs.putCalendars(1);
    gtfs.putTrips(1, "r0", "sid0", "bikes_allowed=1");
    gtfs.putStopTimes("t0", "s0,s1");
    gtfs.putLines("frequencies.txt", "trip_id,start_time,end_time,headway_secs", "t0,09:00:00,17:00:00,300");
    GtfsFeedId feedId = new GtfsFeedId.Builder().id("FEED").build();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(GtfsLibrary.createContext(feedId, gtfs.read()));
    Graph graph = new Graph();
    factory.run(graph);
    for (Edge edge : graph.getEdges()) {
        if (edge instanceof TransitBoardAlight) {
            TripPattern pattern = ((TransitBoardAlight) edge).getPattern();
        // TODO assertTrue(pattern.getBikesAllowed());
        }
    }
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) GtfsFeedId(org.opentripplanner.graph_builder.module.GtfsFeedId) TransitBoardAlight(org.opentripplanner.routing.edgetype.TransitBoardAlight) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) Edge(org.opentripplanner.routing.graph.Edge) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Test(org.junit.Test)

Example 4 with MockGtfs

use of org.onebusaway.gtfs.services.MockGtfs in project onebusaway-gtfs-modules by OneBusAway.

the class IntegrationTest method go.

@Test
public void go() throws IOException {
    MockGtfs gtfsA = MockGtfs.create();
    gtfsA.putAgencies(1);
    System.out.println("go");
}
Also used : MockGtfs(org.onebusaway.gtfs.services.MockGtfs) Test(org.junit.Test)

Example 5 with MockGtfs

use of org.onebusaway.gtfs.services.MockGtfs 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) 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

MockGtfs (org.onebusaway.gtfs.services.MockGtfs)12 Test (org.junit.Test)11 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)4 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)3 Graph (org.opentripplanner.routing.graph.Graph)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 DefaultEntitySchemaFactory (org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory)2 Stop (org.onebusaway.gtfs.model.Stop)2 Trip (org.onebusaway.gtfs.model.Trip)2 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)2 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)2 GtfsWriterTest (org.onebusaway.gtfs.serialization.GtfsWriterTest)2 GtfsDao (org.onebusaway.gtfs.services.GtfsDao)2 GtfsBundle (org.opentripplanner.graph_builder.model.GtfsBundle)2 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)2 CsvEntityIOException (org.onebusaway.csv_entities.exceptions.CsvEntityIOException)1 MissingRequiredFieldException (org.onebusaway.csv_entities.exceptions.MissingRequiredFieldException)1 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)1