Search in sources :

Example 1 with RouteCollectionSearchServiceImpl

use of org.onebusaway.transit_data_federation.impl.RouteCollectionSearchServiceImpl in project onebusaway-application-modules by camsys.

the class GenerateRouteCollectionSearchIndexTaskTest method testGenerateStopSearchIndex.

@Test
public void testGenerateStopSearchIndex() throws CorruptIndexException, IOException, ParseException {
    RouteCollectionEntryImpl routeA = routeCollection("routeA");
    RouteCollectionEntryImpl routeB = routeCollection("routeB");
    RouteCollectionEntryImpl routeC = routeCollection("routeC");
    RouteCollectionNarrative.Builder routeNarrativeA = RouteCollectionNarrative.builder();
    routeNarrativeA.setShortName("10");
    routeNarrativeA.setLongName("El Diez");
    RouteCollectionNarrative.Builder routeNarrativeB = RouteCollectionNarrative.builder();
    routeNarrativeB.setShortName("11");
    routeNarrativeB.setLongName("El Once");
    RouteCollectionNarrative.Builder routeNarrativeC = RouteCollectionNarrative.builder();
    routeNarrativeC.setShortName("100");
    Mockito.when(_transitGraphDao.getAllRouteCollections()).thenReturn(Arrays.asList((RouteCollectionEntry) routeA, routeB, routeC));
    Mockito.when(_narrativeService.getRouteCollectionForId(routeA.getId())).thenReturn(routeNarrativeA.create());
    Mockito.when(_narrativeService.getRouteCollectionForId(routeB.getId())).thenReturn(routeNarrativeB.create());
    Mockito.when(_narrativeService.getRouteCollectionForId(routeC.getId())).thenReturn(routeNarrativeC.create());
    _task.run();
    Mockito.verify(_refreshService).refresh(RefreshableResources.ROUTE_COLLECTION_SEARCH_DATA);
    RouteCollectionSearchServiceImpl searchService = new RouteCollectionSearchServiceImpl();
    searchService.setBundle(_bundle);
    searchService.initialize();
    SearchResult<AgencyAndId> ids = searchService.searchForRoutesByName("10", 10, MIN_SCORE);
    assertEquals(1, ids.size());
    assertEquals(routeA.getId(), ids.getResult(0));
    ids = searchService.searchForRoutesByName("el diez", 10, MIN_SCORE);
    assertEquals(1, ids.size());
    assertEquals(routeA.getId(), ids.getResult(0));
    ids = searchService.searchForRoutesByName("diez", 10, MIN_SCORE);
    assertEquals(1, ids.size());
    assertEquals(routeA.getId(), ids.getResult(0));
    ids = searchService.searchForRoutesByName("11", 10, MIN_SCORE);
    assertEquals(1, ids.size());
    assertEquals(routeB.getId(), ids.getResult(0));
    ids = searchService.searchForRoutesByName("100", 10, MIN_SCORE);
    assertEquals(1, ids.size());
    assertEquals(routeC.getId(), ids.getResult(0));
}
Also used : RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) RouteCollectionSearchServiceImpl(org.onebusaway.transit_data_federation.impl.RouteCollectionSearchServiceImpl) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 RouteCollectionSearchServiceImpl (org.onebusaway.transit_data_federation.impl.RouteCollectionSearchServiceImpl)1 RouteCollectionEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl)1 RouteCollectionNarrative (org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative)1 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)1