Search in sources :

Example 6 with FederatedServiceCollection

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

the class FederatedByAgencyIdMethodInvocationHandlerImplTest method testArgumentIndex.

@Test
public void testArgumentIndex() throws Exception {
    SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class);
    FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class);
    Mockito.when(mockCollection.getServiceForAgencyId("agency")).thenReturn(mockService);
    Method method = SimpleFederatedService.class.getDeclaredMethod("getValueForValueAndId", String.class, String.class);
    Object[] args = { "value", "agency_entity" };
    FederatedServiceMethodInvocationHandler handler = new FederatedByEntityIdMethodInvocationHandlerImpl(method, 1, "");
    handler.invoke(mockCollection, method, args);
    Mockito.verify(mockService).getValueForValueAndId("value", "agency_entity");
}
Also used : FederatedServiceCollection(org.onebusaway.federations.FederatedServiceCollection) Method(java.lang.reflect.Method) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) Test(org.junit.Test)

Example 7 with FederatedServiceCollection

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

the class FederatedByAgencyIdMethodInvocationHandlerImplTest method testPropertyExpression.

@Test
public void testPropertyExpression() throws Exception {
    SimpleFederatedService mockService = Mockito.mock(SimpleFederatedService.class);
    FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class);
    Mockito.when(mockCollection.getServiceForAgencyId("agency")).thenReturn(mockService);
    Method method = SimpleFederatedService.class.getDeclaredMethod("getValueForValueBean", EntityIdTestBean.class);
    EntityIdTestBean value = new EntityIdTestBean("agency_entity");
    Object[] args = { value };
    FederatedServiceMethodInvocationHandler handler = new FederatedByEntityIdMethodInvocationHandlerImpl(method, 0, "id");
    handler.invoke(mockCollection, method, args);
    Mockito.verify(mockService).getValueForValueBean(value);
}
Also used : EntityIdTestBean(org.onebusaway.federations.EntityIdTestBean) FederatedServiceCollection(org.onebusaway.federations.FederatedServiceCollection) Method(java.lang.reflect.Method) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) Test(org.junit.Test)

Example 8 with FederatedServiceCollection

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

the class FederatedByAgencyIdsMethodInvocationHandlerImplTest method testArgumentIndex.

@Test
public void testArgumentIndex() 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("getValueForValueAndIds", String.class, Set.class);
    Object[] args = { "value", ids };
    FederatedServiceMethodInvocationHandler handler = new FederatedByEntityIdsMethodInvocationHandlerImpl(1);
    handler.invoke(mockCollection, method, args);
    Mockito.verify(mockService).getValueForValueAndIds("value", 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 9 with FederatedServiceCollection

use of org.onebusaway.federations.FederatedServiceCollection 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"));
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) FederatedService(org.onebusaway.federations.FederatedService) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) FederatedServiceCollection(org.onebusaway.federations.FederatedServiceCollection) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with FederatedServiceCollection

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

the class FederatedByBoundsMethodInvocationHandlerImplTest method testSimple.

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

Aggregations

Method (java.lang.reflect.Method)11 Test (org.junit.Test)11 FederatedServiceCollection (org.onebusaway.federations.FederatedServiceCollection)11 SimpleFederatedService (org.onebusaway.federations.SimpleFederatedService)11 HashSet (java.util.HashSet)4 FederatedService (org.onebusaway.federations.FederatedService)2 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