use of org.onebusaway.transit_data_federation.impl.StopSearchServiceImpl in project onebusaway-application-modules by camsys.
the class GenerateStopSearchIndexTaskTest method testGenerateStopSearchIndex.
@Test
public void testGenerateStopSearchIndex() throws CorruptIndexException, IOException, ParseException {
StopEntryImpl stopA = stop("111", 0, 0);
StopEntryImpl stopB = stop("222", 0, 0);
StopEntryImpl stopC = stop("333", 0, 0);
StopNarrative.Builder stopNarrativeA = StopNarrative.builder();
stopNarrativeA.setCode("111");
stopNarrativeA.setName("AAA Station");
StopNarrative.Builder stopNarrativeB = StopNarrative.builder();
stopNarrativeB.setName("BBB Station");
StopNarrative.Builder stopNarrativeC = StopNarrative.builder();
stopNarrativeC.setCode("444");
stopNarrativeC.setName("CCC Station");
Mockito.when(_transitGraphDao.getAllStops()).thenReturn(Arrays.asList((StopEntry) stopA, stopB, stopC));
Mockito.when(_narrativeService.getStopForId(stopA.getId())).thenReturn(stopNarrativeA.create());
Mockito.when(_narrativeService.getStopForId(stopB.getId())).thenReturn(stopNarrativeB.create());
Mockito.when(_narrativeService.getStopForId(stopC.getId())).thenReturn(stopNarrativeC.create());
_task.run();
StopSearchServiceImpl searchService = new StopSearchServiceImpl();
searchService.setBundle(_bundle);
searchService.initialize();
SearchResult<AgencyAndId> ids = searchService.searchForStopsByCode("111", 10, MIN_SCORE);
assertEquals(1, ids.size());
assertEquals(new AgencyAndId("1", "111"), ids.getResult(0));
ids = searchService.searchForStopsByCode("222", 10, MIN_SCORE);
assertEquals(1, ids.size());
assertTrue(ids.getResults().contains(new AgencyAndId("1", "222")));
ids = searchService.searchForStopsByCode("333", 10, MIN_SCORE);
assertEquals(0, ids.size());
ids = searchService.searchForStopsByCode("444", 10, MIN_SCORE);
assertEquals(1, ids.size());
assertTrue(ids.getResults().contains(new AgencyAndId("1", "333")));
}
Aggregations