use of org.onebusaway.federations.SimpleFederatedService in project onebusaway-application-modules by camsys.
the class FederatedByAgencyIdMethodInvocationHandlerImplTest method testSimple.
@Test
public void testSimple() 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("getValueForId", String.class);
Object[] args = { "agency_entity" };
FederatedServiceMethodInvocationHandler handler = new FederatedByEntityIdMethodInvocationHandlerImpl(method, 0, "");
handler.invoke(mockCollection, method, args);
Mockito.verify(mockService).getValueForId("agency_entity");
}
use of org.onebusaway.federations.SimpleFederatedService 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");
}
use of org.onebusaway.federations.SimpleFederatedService 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);
}
use of org.onebusaway.federations.SimpleFederatedService 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);
}
use of org.onebusaway.federations.SimpleFederatedService 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"));
}
Aggregations