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"))));
}
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;
}
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());
}
}
}
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");
}
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);
}
}
}
Aggregations