use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.
the class FederatedByLocationMethodInvocationHandlerImpl method invoke.
public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
double lat = arg(args, _latArgumentIndex);
double lon = arg(args, _lonArgumentIndex);
FederatedService service = collection.getServiceForLocation(lat, lon);
return method.invoke(service, args);
}
use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.
the class FederatedByAggregateMethodInvocationHandlerImplTest method testMap.
@SuppressWarnings("unchecked")
@Test
public void testMap() throws Exception {
Map<String, String> vA = new HashMap<String, String>();
vA.put("a", "a1");
vA.put("b", "b2");
Map<String, String> vB = new HashMap<String, String>();
vB.put("c", "c3");
vB.put("d", "d4");
SimpleFederatedService mockServiceA = Mockito.mock(SimpleFederatedService.class);
Mockito.when(mockServiceA.getValuesAsMap()).thenReturn(vA);
SimpleFederatedService mockServiceB = Mockito.mock(SimpleFederatedService.class);
Mockito.when(mockServiceB.getValuesAsMap()).thenReturn(vB);
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("getValuesAsMap");
FederatedServiceMethodInvocationHandler handler = new FederatedByAggregateMethodInvocationHandlerImpl(EMethodAggregationType.MAP);
Map<String, String> results = (Map<String, String>) handler.invoke(mockCollection, method, new Object[] {});
Mockito.verify(mockServiceA).getValuesAsMap();
Mockito.verify(mockServiceB).getValuesAsMap();
assertEquals(4, results.size());
assertEquals("a1", results.get("a"));
assertEquals("b2", results.get("b"));
assertEquals("c3", results.get("c"));
assertEquals("d4", results.get("d"));
}
use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.
the class FederatedByBoundsMethodInvocationHandlerImpl method invoke.
public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
double lat1 = arg(args, _lat1ArgumentIndex);
double lon1 = arg(args, _lon1ArgumentIndex);
double lat2 = arg(args, _lat2ArgumentIndex);
double lon2 = arg(args, _lon2ArgumentIndex);
FederatedService service = collection.getServiceForBounds(lat1, lon1, lat2, lon2);
return method.invoke(service, args);
}
use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.
the class FederatedByCoordinatePointsMethodInvocationHandlerImpl method invoke.
public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
for (int i = 0; i < _argumentIndices.length; i++) {
Object value = args[_argumentIndices[i]];
PropertyPathExpression expression = _expressions[i];
if (expression != null)
value = expression.invoke(value);
CoordinatePoint point = (CoordinatePoint) value;
points.add(point);
}
FederatedService service = collection.getServiceForLocations(points);
return method.invoke(service, args);
}
Aggregations