Search in sources :

Example 1 with SimpleFederatedService

use of org.onebusaway.federations.SimpleFederatedService in project onebusaway-application-modules by camsys.

the class FederatedByLocationMethodInvocationHandlerImplTest method testSimple.

@Test
public void testSimple() throws Exception {
    SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class);
    FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class);
    Mockito.when(mockCollection.getServiceForLocation(0.0, 1.0)).thenReturn(mockService);
    Method method = SimpleFederatedService.class.getDeclaredMethod("getValueForLocation", Double.TYPE, Double.TYPE);
    Object[] args = { 0.0, 1.0 };
    FederatedServiceMethodInvocationHandler handler = new FederatedByLocationMethodInvocationHandlerImpl(0, 1);
    handler.invoke(mockCollection, method, args);
    Mockito.verify(mockService).getValueForLocation(0.0, 1.0);
}
Also used : FederatedServiceCollection(org.onebusaway.federations.FederatedServiceCollection) Method(java.lang.reflect.Method) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) Test(org.junit.Test)

Example 2 with SimpleFederatedService

use of org.onebusaway.federations.SimpleFederatedService in project onebusaway-application-modules by camsys.

the class FederatedByAgencyIdsMethodInvocationHandlerImplTest method testSimple.

@Test
public void testSimple() throws Exception {
    Set<String> agencyIds = new HashSet<String>();
    agencyIds.add("agency");
    Set<String> ids = new HashSet<String>();
    ids.add("agency_entity");
    SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class);
    FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class);
    Mockito.when(mockCollection.getServiceForAgencyIds(agencyIds)).thenReturn(mockService);
    Method method = SimpleFederatedService.class.getDeclaredMethod("getValueForIds", Set.class);
    Object[] args = { ids };
    FederatedServiceMethodInvocationHandler handler = new FederatedByEntityIdsMethodInvocationHandlerImpl(0);
    handler.invoke(mockCollection, method, args);
    Mockito.verify(mockService).getValueForIds(ids);
}
Also used : FederatedServiceCollection(org.onebusaway.federations.FederatedServiceCollection) Method(java.lang.reflect.Method) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with SimpleFederatedService

use of org.onebusaway.federations.SimpleFederatedService in project onebusaway-application-modules by camsys.

the class FederatedByAggregateMethodInvocationHandlerImplTest method testList.

@SuppressWarnings("unchecked")
@Test
public void testList() throws Exception {
    SimpleFederatedService mockServiceA = Mockito.mock(SimpleFederatedService.class);
    Mockito.when(mockServiceA.getValuesAsList()).thenReturn(Arrays.asList("a", "b"));
    SimpleFederatedService mockServiceB = Mockito.mock(SimpleFederatedService.class);
    Mockito.when(mockServiceB.getValuesAsList()).thenReturn(Arrays.asList("c", "d", "a"));
    Set<FederatedService> services = new HashSet<FederatedService>();
    services.add(mockServiceA);
    services.add(mockServiceB);
    FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class);
    Mockito.when(mockCollection.getAllServices()).thenReturn(services);
    Method method = SimpleFederatedService.class.getDeclaredMethod("getValuesAsList");
    FederatedServiceMethodInvocationHandler handler = new FederatedByAggregateMethodInvocationHandlerImpl(EMethodAggregationType.LIST);
    List<String> results = (List<String>) handler.invoke(mockCollection, method, new Object[] {});
    Mockito.verify(mockServiceA).getValuesAsList();
    Mockito.verify(mockServiceB).getValuesAsList();
    assertEquals(5, results.size());
    Collections.sort(results);
    assertEquals("a", results.get(0));
    assertEquals("a", results.get(1));
    assertEquals("b", results.get(2));
    assertEquals("c", results.get(3));
    assertEquals("d", results.get(4));
}
Also used : FederatedService(org.onebusaway.federations.FederatedService) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) FederatedServiceCollection(org.onebusaway.federations.FederatedServiceCollection) List(java.util.List) Method(java.lang.reflect.Method) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with SimpleFederatedService

use of org.onebusaway.federations.SimpleFederatedService in project onebusaway-application-modules by camsys.

the class FederatedByCoordinateBoundsMethodInvocationHandlerImplTest method test01.

@Test
public void test01() throws Exception {
    CoordinateBounds bounds = new CoordinateBounds(0, 1, 2, 3);
    SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class);
    FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class);
    Mockito.when(mockCollection.getServiceForBounds(bounds)).thenReturn(mockService);
    Method method = SimpleFederatedService.class.getDeclaredMethod("getValueForCoordinateBounds", CoordinateBounds.class);
    Object[] args = { bounds };
    FederatedServiceMethodInvocationHandler handler = new FederatedByCoordinateBoundsMethodInvocationHandlerImpl(method, 0, "");
    handler.invoke(mockCollection, method, args);
    Mockito.verify(mockService).getValueForCoordinateBounds(bounds);
}
Also used : FederatedServiceCollection(org.onebusaway.federations.FederatedServiceCollection) Method(java.lang.reflect.Method) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Test(org.junit.Test)

Example 5 with SimpleFederatedService

use of org.onebusaway.federations.SimpleFederatedService in project onebusaway-application-modules by camsys.

the class DynamicFederatedServiceCollectionImplTest method test.

@Test
public void test() throws Exception {
    Set<FederatedService> services = _collection.getAllServices();
    assertTrue(services.isEmpty());
    _registry.addService("http://localhost:" + PORT + "/service-A/service", SimpleFederatedService.class.getName(), new HashMap<String, String>());
    Thread.sleep(TIMEOUT);
    services = _collection.getAllServices();
    assertEquals(1, services.size());
    SimpleFederatedService service = (SimpleFederatedService) _collection.getServiceForAgencyId("A");
    assertEquals("A", service.getValueForId(""));
    _registry.addService("http://localhost:" + PORT + "/service-B/service", SimpleFederatedService.class.getName(), new HashMap<String, String>());
    Thread.sleep(TIMEOUT);
    services = _collection.getAllServices();
    assertEquals(2, services.size());
    service = (SimpleFederatedService) _collection.getServiceForAgencyId("A");
    assertEquals("A", service.getValueForId(""));
    service = (SimpleFederatedService) _collection.getServiceForAgencyId("B");
    assertEquals("B", service.getValueForId(""));
    // Simulate a server crash
    _server.stop();
    _server = null;
    Thread.sleep(TIMEOUT);
    services = _collection.getAllServices();
    assertTrue(services.isEmpty());
}
Also used : FederatedService(org.onebusaway.federations.FederatedService) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 SimpleFederatedService (org.onebusaway.federations.SimpleFederatedService)12 Method (java.lang.reflect.Method)11 FederatedServiceCollection (org.onebusaway.federations.FederatedServiceCollection)11 HashSet (java.util.HashSet)4 FederatedService (org.onebusaway.federations.FederatedService)3 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CoordinateBoundsTestBean (org.onebusaway.federations.CoordinateBoundsTestBean)1 EntityIdTestBean (org.onebusaway.federations.EntityIdTestBean)1