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);
}
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);
}
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));
}
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);
}
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());
}
Aggregations