use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImplTest method testGetStopsForRoute.
@Test
public void testGetStopsForRoute() {
AgencyAndId routeId = new AgencyAndId("1", "route");
RouteEntryImpl route = new RouteEntryImpl();
route.setId(new AgencyAndId("1", "raw_route"));
List<RouteEntry> routes = Arrays.asList((RouteEntry) route);
RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
routeCollection.setId(routeId);
routeCollection.setChildren(routes);
route.setParent(routeCollection);
Mockito.when(_transitGraphDao.getRouteCollectionForId(routeId)).thenReturn(routeCollection);
RouteCollectionNarrative.Builder rcNarrative = RouteCollectionNarrative.builder();
Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(rcNarrative.create());
StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
StopEntryImpl stopC = stop("stopC", 47.2, -122.2);
BlockEntryImpl blockA = block("blockA");
TripEntryImpl tripA = trip("tripA", "sidA");
TripEntryImpl tripB = trip("tripB", "sidA");
tripA.setRoute(route);
tripA.setDirectionId("0");
tripB.setRoute(route);
tripB.setDirectionId("1");
route.setTrips(Arrays.asList((TripEntry) tripA, tripB));
TripNarrative.Builder tnA = TripNarrative.builder();
tnA.setTripHeadsign("Destination A");
Mockito.when(_narrativeService.getTripForId(tripA.getId())).thenReturn(tnA.create());
TripNarrative.Builder tnB = TripNarrative.builder();
tnB.setTripHeadsign("Destination B");
Mockito.when(_narrativeService.getTripForId(tripB.getId())).thenReturn(tnB.create());
stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
stopTime(2, stopC, tripA, time(10, 00), time(10, 00), 200);
stopTime(3, stopC, tripB, time(11, 30), time(11, 30), 0);
stopTime(4, stopA, tripB, time(12, 30), time(12, 30), 200);
linkBlockTrips(blockA, tripA, tripB);
List<BlockTripIndex> blockIndices = blockTripIndices(blockA);
Mockito.when(_blockIndexService.getBlockTripIndicesForRouteCollectionId(routeId)).thenReturn(blockIndices);
StopBean stopBeanA = getStopBean(stopA);
StopBean stopBeanB = getStopBean(stopB);
StopBean stopBeanC = getStopBean(stopC);
List<AgencyAndId> stopIds = Arrays.asList(stopA.getId(), stopB.getId(), stopC.getId());
Mockito.when(_routeService.getStopsForRouteCollection(routeId)).thenReturn(stopIds);
Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopBeanA);
Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBeanB);
Mockito.when(_stopBeanService.getStopForId(stopC.getId())).thenReturn(stopBeanC);
AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
shapeIds.add(shapeId);
tripA.setShapeId(shapeId);
EncodedPolylineBean polyline = new EncodedPolylineBean();
Mockito.when(_shapeBeanService.getMergedPolylinesForShapeIds(shapeIds)).thenReturn(Arrays.asList(polyline));
// Setup complete
StopsForRouteBean stopsForRoute = _service.getStopsForRoute(routeId);
List<StopBean> stops = stopsForRoute.getStops();
assertEquals(3, stops.size());
assertSame(stopBeanA, stops.get(0));
assertSame(stopBeanB, stops.get(1));
assertSame(stopBeanC, stops.get(2));
List<EncodedPolylineBean> polylines = stopsForRoute.getPolylines();
assertEquals(1, polylines.size());
assertSame(polyline, polylines.get(0));
List<StopGroupingBean> groupings = stopsForRoute.getStopGroupings();
assertEquals(1, groupings.size());
StopGroupingBean grouping = groupings.get(0);
assertEquals("direction", grouping.getType());
List<StopGroupBean> groups = grouping.getStopGroups();
assertEquals(2, groups.size());
StopGroupBean groupA = groups.get(0);
StopGroupBean groupB = groups.get(1);
NameBean nameA = groupA.getName();
assertEquals("destination", nameA.getType());
assertEquals("Destination A", nameA.getName());
List<String> stopIdsA = groupA.getStopIds();
assertEquals(3, stopIdsA.size());
assertEquals(ids(stopA.getId(), stopB.getId(), stopC.getId()), stopIdsA);
NameBean nameB = groupB.getName();
assertEquals("destination", nameB.getType());
assertEquals("Destination B", nameB.getName());
List<String> stopIdsB = groupB.getStopIds();
assertEquals(2, stopIdsB.size());
assertEquals(ids(stopC.getId(), stopA.getId()), stopIdsB);
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl in project onebusaway-application-modules by camsys.
the class UnitTestingSupport method routeCollection.
public static RouteCollectionEntryImpl routeCollection(String id, RouteEntry... routes) {
RouteCollectionEntryImpl route = new RouteCollectionEntryImpl();
route.setId(aid(id));
route.setChildren(Arrays.asList(routes));
for (RouteEntry routeEntry : routes) {
((RouteEntryImpl) routeEntry).setParent(route);
}
return route;
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl in project onebusaway-application-modules by camsys.
the class GtfsRealtimeEntitySourceTest method testGetRouteId.
@Test
public void testGetRouteId() {
RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
routeCollection.setId(new AgencyAndId("2", "R10C"));
RouteEntryImpl route = new RouteEntryImpl();
route.setId(new AgencyAndId("2", "R10"));
route.setParent(routeCollection);
Mockito.when(_dao.getRouteForId(route.getId())).thenReturn(route);
Id routeId = _source.getRouteId("R10");
assertEquals("2", routeId.getAgencyId());
assertEquals("R10C", routeId.getId());
routeId = _source.getRouteId("R11");
assertEquals("1", routeId.getAgencyId());
assertEquals("R11", routeId.getId());
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl in project onebusaway-application-modules by camsys.
the class RouteCollectionEntriesFactory method createRouteShortNameRouteCollectionMapping.
private void createRouteShortNameRouteCollectionMapping(TransitGraphImpl graph) {
Map<AgencyAndId, List<RouteEntryImpl>> routesByKey = new HashMap<AgencyAndId, List<RouteEntryImpl>>();
for (RouteEntryImpl routeEntry : graph.getRoutes()) {
Route route = _gtfsDao.getRouteForId(routeEntry.getId());
AgencyAndId key = getRouteCollectionIdForRoute(route);
List<RouteEntryImpl> forKey = routesByKey.get(key);
if (forKey == null) {
forKey = new ArrayList<RouteEntryImpl>();
routesByKey.put(key, forKey);
}
forKey.add(routeEntry);
}
for (Map.Entry<AgencyAndId, List<RouteEntryImpl>> entry : routesByKey.entrySet()) {
AgencyAndId key = entry.getKey();
List<RouteEntryImpl> routesForKey = entry.getValue();
ArrayList<RouteEntry> children = new ArrayList<RouteEntry>();
children.addAll(routesForKey);
children.trimToSize();
key = _uniqueService.unique(key);
RouteCollectionEntryImpl routeCollectionEntry = new RouteCollectionEntryImpl();
routeCollectionEntry.setId(key);
routeCollectionEntry.setChildren(children);
graph.putRouteCollectionEntry(routeCollectionEntry);
for (RouteEntryImpl route : routesForKey) route.setParent(routeCollectionEntry);
}
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl in project onebusaway-application-modules by camsys.
the class RouteCollectionEntriesFactory method createOneToOneRouteCollectionMapping.
private void createOneToOneRouteCollectionMapping(TransitGraphImpl graph) {
for (RouteEntryImpl routeEntry : graph.getRoutes()) {
RouteCollectionEntryImpl routeCollectionEntry = new RouteCollectionEntryImpl();
routeCollectionEntry.setId(routeEntry.getId());
ArrayList<RouteEntry> routes = new ArrayList<RouteEntry>();
routes.add(routeEntry);
routes.trimToSize();
routeCollectionEntry.setChildren(routes);
graph.putRouteCollectionEntry(routeCollectionEntry);
routeEntry.setParent(routeCollectionEntry);
}
}
Aggregations