use of org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao in project onebusaway-application-modules by camsys.
the class StopTimeServiceImplTest method setup.
@Before
public void setup() {
_factory = new BlockIndexFactoryServiceImpl();
_stop = stop("stopId", 47.0, -122.0);
_stopId = _stop.getId();
TransitGraphDao graph = Mockito.mock(TransitGraphDao.class);
Mockito.when(graph.getStopEntryForId(_stop.getId(), true)).thenReturn(_stop);
CalendarServiceData data = new CalendarServiceData();
data.putDatesForLocalizedServiceId(lsid("sA"), Arrays.asList(date("2009-09-01 00:00"), date("2009-09-02 00:00")));
data.putDatesForLocalizedServiceId(lsid("sB"), Arrays.asList(date("2009-09-03 00:00")));
CalendarServiceImpl calendarService = new CalendarServiceImpl();
calendarService.setData(data);
_calendarService = new ExtendedCalendarServiceImpl();
_calendarService.setCalendarService(calendarService);
_blockIndexService = Mockito.mock(BlockIndexService.class);
_service = new StopTimeServiceImpl();
_service.setTransitGraphDao(graph);
_service.setCalendarService(_calendarService);
_service.setBlockIndexService(_blockIndexService);
BlockConfigurationEntry bcA = blockConfiguration(block("bA"), serviceIds(lsids("sA"), lsids()));
BlockConfigurationEntry bcB = blockConfiguration(block("bB"), serviceIds(lsids("sB"), lsids()));
_transitGraphDao = Mockito.mock(TransitGraphDao.class);
Mockito.when(_transitGraphDao.getAllBlocks()).thenReturn(Arrays.asList(bcA.getBlock(), bcB.getBlock()));
_calendarService.setTransitGraphDao(_transitGraphDao);
_calendarService.start();
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao in project onebusaway-application-modules by camsys.
the class WhereGeospatialServiceImplTest method test.
@Test
public void test() {
WhereGeospatialServiceImpl service = new WhereGeospatialServiceImpl();
TransitGraphDao dao = Mockito.mock(TransitGraphDao.class);
service.setTransitGraphDao(dao);
StopEntry stopA = stop("a", -0.5, -0.5);
StopEntry stopB = stop("b", -0.5, 0.5);
StopEntry stopC = stop("c", 0.5, -0.5);
StopEntry stopD = stop("d", 0.5, 0.5);
List<StopEntry> allStops = Arrays.asList(stopA, stopB, stopC, stopD);
Mockito.when(dao.getAllStops()).thenReturn(allStops);
service.initialize();
List<AgencyAndId> stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 0, 0));
assertEquals(1, stops.size());
assertTrue(stops.contains(stopA.getId()));
stops = service.getStopsByBounds(new CoordinateBounds(0, -1, 1, 0));
assertEquals(1, stops.size());
assertTrue(stops.contains(stopC.getId()));
stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 1, 0));
assertEquals(2, stops.size());
assertTrue(stops.contains(stopA.getId()));
assertTrue(stops.contains(stopC.getId()));
stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 1, 1));
assertEquals(4, stops.size());
assertTrue(stops.contains(stopA.getId()));
assertTrue(stops.contains(stopB.getId()));
assertTrue(stops.contains(stopC.getId()));
assertTrue(stops.contains(stopD.getId()));
stops = service.getStopsByBounds(new CoordinateBounds(0.8, 0.8, 1, 1));
assertEquals(0, stops.size());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao in project onebusaway-application-modules by camsys.
the class ShapeGeospatialIndexTaskTest method test.
@Test
public void test() throws IOException, ClassNotFoundException {
ShapeGeospatialIndexTask task = new ShapeGeospatialIndexTask();
File path = File.createTempFile(ShapeGeospatialIndexTaskTest.class.getName(), ".tmp");
path.delete();
path.deleteOnExit();
FederatedTransitDataBundle bundle = Mockito.mock(FederatedTransitDataBundle.class);
Mockito.when(bundle.getShapeGeospatialIndexDataPath()).thenReturn(path);
task.setBundle(bundle);
RefreshService refreshService = Mockito.mock(RefreshService.class);
task.setRefreshService(refreshService);
ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
task.setShapePointHelper(shapePointHelper);
TransitGraphDao transitGraphDao = Mockito.mock(TransitGraphDao.class);
task.setTransitGraphDao(transitGraphDao);
StopEntry stopA = stop("stopA", 47.65, -122.32);
StopEntry stopB = stop("stopB", 47.67, -122.30);
Mockito.when(transitGraphDao.getAllStops()).thenReturn(Arrays.asList(stopA, stopB));
TripEntryImpl tripA = trip("tripA");
AgencyAndId shapeIdA = aid("shapeA");
tripA.setShapeId(shapeIdA);
TripEntryImpl tripB = trip("tripB");
AgencyAndId shapeIdB = aid("shapeB");
tripB.setShapeId(shapeIdB);
Mockito.when(transitGraphDao.getAllTrips()).thenReturn(Arrays.asList((TripEntry) tripA, tripB));
ShapePointsFactory factory = new ShapePointsFactory();
factory.addPoint(47.652300128129454, -122.30622018270873);
factory.addPoint(47.653181844549394, -122.30523312979125);
factory.addPoint(47.654265901710744, -122.30511511259459);
ShapePoints shapeA = factory.create();
factory = new ShapePointsFactory();
factory.addPoint(47.661275594717026, -122.31189573698424);
factory.addPoint(47.661347854692465, -122.3240622370758);
factory.addPoint(47.661368177792546, -122.32508885257624);
factory.addPoint(47.66496659665593, -122.32501375072383);
ShapePoints shapeB = factory.create();
Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeIdA)).thenReturn(shapeA);
Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeIdB)).thenReturn(shapeB);
task.run();
Mockito.verify(refreshService).refresh(RefreshableResources.SHAPE_GEOSPATIAL_INDEX);
Map<CoordinateBounds, List<AgencyAndId>> shapeIdsByBounds = ObjectSerializationLibrary.readObject(path);
assertEquals(5, shapeIdsByBounds.size());
CoordinateBounds b = new CoordinateBounds(47.65048049686506, -122.30767397879845, 47.654977097836735, -122.300997795721);
assertEquals(Arrays.asList(shapeIdA), shapeIdsByBounds.get(b));
b = new CoordinateBounds(47.65947369880841, -122.32102634495334, 47.66397029978009, -122.3143501618759);
assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
b = new CoordinateBounds(47.66397029978009, -122.32770252803078, 47.66846690075177, -122.32102634495334);
assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
b = new CoordinateBounds(47.65947369880841, -122.3143501618759, 47.66397029978009, -122.30767397879845);
assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
b = new CoordinateBounds(47.65947369880841, -122.32770252803078, 47.66397029978009, -122.32102634495334);
assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
}
Aggregations