RouteBeanServiceImpl implements RouteBeanService { @Cacheable public StopsForRouteBean getStopsForRoute(AgencyAndId routeId) { RouteCollectionEntry routeCollectionEntry = _transitGraphDao.getRouteCollectionForId(routeId); RouteCollectionNarrative narrative = _narrativeService.getRouteCollectionForId(routeId); if (routeCollectionEntry == null || narrative == null) return null; return getStopsForRouteCollectionAndNarrative(routeCollectionEntry, narrative, null); }  @Autowired void setTransitGraphDao(TransitGraphDao transitGraphDao); @Autowired void setNarrativeService(NarrativeService narrativeService); @Autowired void setAgencyBeanService(AgencyBeanService agencyBeanService); @Autowired void setStopBeanService(StopBeanService stopBeanService); @Autowired void setShapeBeanService(ShapeBeanService shapeBeanService); @Autowired void setRouteService(RouteService routeService); @Autowired void setStopSequencesLibrary(StopSequencesService service); @Autowired void setStopSequencesBlocksService(
      StopSequenceCollectionService stopSequenceBlocksService); @Autowired void setBlockIndexService(BlockIndexService blockIndexService); @Autowired void setCalendarService(CalendarService calendarService); @Autowired void setExtCalendarService(ExtendedCalendarService extCalendarService); @Cacheable RouteBean getRouteForId(AgencyAndId id); @Cacheable StopsForRouteBean getStopsForRoute(AgencyAndId routeId); @Cacheable StopsForRouteBean getStopsForRouteForServiceDate(AgencyAndId routeId, ServiceDate serviceDate);  }
@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(), null)).thenReturn( stopBeanA); Mockito.when(_stopBeanService.getStopForId(stopB.getId(), null)).thenReturn( stopBeanB); Mockito.when(_stopBeanService.getStopForId(stopC.getId(), null)).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)); 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); }