Search in sources :

Example 1 with StopSearchServiceImpl

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")));
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopSearchServiceImpl(org.onebusaway.transit_data_federation.impl.StopSearchServiceImpl) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 StopSearchServiceImpl (org.onebusaway.transit_data_federation.impl.StopSearchServiceImpl)1 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)1 StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)1 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)1