public void setUp() throws Exception { context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS)); graph = new Graph(); GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context); factory.run(graph); graph.putService( CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao())); String[] stops = { "agency:A", "agency:B", "agency:C", "agency:D", "agency:E", "agency:entrance_a", "agency:entrance_b" }; for (int i = 0; i < stops.length; ++i) { TransitStop stop = (TransitStop) (graph.getVertex(stops[i])); IntersectionVertex front = new IntersectionVertex( graph, "near_1_" + stop.getStopId(), stop.getX() + 0.0001, stop.getY() + 0.0001); IntersectionVertex back = new IntersectionVertex( graph, "near_2_" + stop.getStopId(), stop.getX() - 0.0001, stop.getY() - 0.0001); StreetEdge street1 = new StreetEdge( front, back, GeometryUtils.makeLineString( stop.getX() + 0.0001, stop.getY() + 0.0001, stop.getX() - 0.0001, stop.getY() - 0.0001), "street", 100, StreetTraversalPermission.ALL, false); StreetEdge street2 = new StreetEdge( back, front, GeometryUtils.makeLineString( stop.getX() - 0.0001, stop.getY() - 0.0001, stop.getX() + 0.0001, stop.getY() + 0.0001), "street", 100, StreetTraversalPermission.ALL, true); } NetworkLinker nl = new NetworkLinker(graph); nl.createLinkage(); }
@Test public final void testOnBoardDepartureAtArrivalTime() { Coordinate[] coordinates = new Coordinate[2]; coordinates[0] = new Coordinate(0.0, 0.0); coordinates[1] = new Coordinate(0.0, 1.0); TransitStop station0 = mock(TransitStop.class); TransitStop station1 = mock(TransitStop.class); PatternDepartVertex depart = mock(PatternDepartVertex.class); PatternArriveVertex arrive = mock(PatternArriveVertex.class); Graph graph = mock(Graph.class); RoutingRequest routingRequest = mock(RoutingRequest.class); ServiceDay serviceDay = mock(ServiceDay.class); when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT")); when(station0.getX()).thenReturn(coordinates[0].x); when(station0.getY()).thenReturn(coordinates[0].y); when(station1.getX()).thenReturn(coordinates[1].x); when(station1.getY()).thenReturn(coordinates[1].y); RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive); AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID"); Route route = new Route(); ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(2); StopTime stopDepartTime = new StopTime(); StopTime stopArriveTime = new StopTime(); Stop stopDepart = new Stop(); Stop stopArrive = new Stop(); Trip trip = new Trip(); routingContext.serviceDays = new ArrayList<ServiceDay>(Collections.singletonList(serviceDay)); route.setId(agencyAndId); stopDepart.setId(new AgencyAndId("Station", "0")); stopArrive.setId(new AgencyAndId("Station", "1")); stopDepartTime.setStop(stopDepart); stopDepartTime.setDepartureTime(0); stopArriveTime.setArrivalTime(10); stopArriveTime.setStop(stopArrive); stopTimes.add(stopDepartTime); stopTimes.add(stopArriveTime); trip.setId(agencyAndId); TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator()); StopPattern stopPattern = new StopPattern(stopTimes); TripPattern tripPattern = new TripPattern(route, stopPattern); when(depart.getTripPattern()).thenReturn(tripPattern); PatternHop patternHop = new PatternHop(depart, arrive, stopDepart, stopArrive, 0); when(graph.getEdges()).thenReturn(Collections.<Edge>singletonList(patternHop)); when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0)); when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0)); when(routingRequest.getFrom()).thenReturn(new GenericLocation()); when(routingRequest.getStartingTransitTripId()).thenReturn(agencyAndId); when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(10); when(graph.getVertex("Station_0")).thenReturn(station0); when(graph.getVertex("Station_1")).thenReturn(station1); tripPattern.add(tripTimes); graph.index = new GraphIndex(graph); Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext); assertEquals(coordinates[1].x, vertex.getX(), 0.0); assertEquals(coordinates[1].y, vertex.getY(), 0.0); }