use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.
the class FederatedAggregateHandlerTest method shouldDelegateToHandler.
@Test
public void shouldDelegateToHandler() throws OperationException {
// Given
final FederatedStore store = mock(FederatedStore.class);
final AggregateHandler handler = mock(AggregateHandler.class);
final Aggregate op = mock(Aggregate.class);
final Context context = mock(Context.class);
final Iterable expectedResult = mock(Iterable.class);
final Schema schema = mock(Schema.class);
given(store.getSchema(op, context)).willReturn(schema);
given(handler.doOperation(op, schema)).willReturn(expectedResult);
final FederatedAggregateHandler federatedHandler = new FederatedAggregateHandler(handler);
// When
final Object result = federatedHandler.doOperation(op, context, store);
// Then
assertSame(expectedResult, result);
verify(handler).doOperation(op, schema);
}
use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.
the class FederatedGetAllGraphsIDHandlerTest method shouldGetGraphIds.
@Test
public void shouldGetGraphIds() throws Exception {
FederatedGetAllGraphIDHandler federatedGetAllGraphIDHandler = new FederatedGetAllGraphIDHandler();
GetAllGraphIds op = Mockito.mock(GetAllGraphIds.class);
Context context = Mockito.mock(Context.class);
BDDMockito.given(context.getUser()).willReturn(testUser);
FederatedStore store = Mockito.mock(FederatedStore.class);
Set<String> expected = Sets.newHashSet();
expected.add("value1");
BDDMockito.given(store.getAllGraphIds(testUser, false)).willReturn(expected);
Iterable<? extends String> actual = federatedGetAllGraphIDHandler.doOperation(op, context, store);
assertEquals(expected, actual);
Mockito.verify(store).getAllGraphIds(testUser, false);
}
use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.
the class FederatedOperationOutputHandlerTest method shouldThrowException.
@Test
public void shouldThrowException() throws Exception {
// Given
final String message = "Test Exception";
final OP op = getExampleOperation();
op.addOption(KEY_OPERATION_OPTIONS_GRAPH_IDS, TEST_GRAPH_ID);
Schema unusedSchema = new Schema.Builder().build();
StoreProperties storeProperties = new StoreProperties();
Store mockStoreInner = Mockito.mock(Store.class);
given(mockStoreInner.getSchema()).willReturn(unusedSchema);
given(mockStoreInner.getProperties()).willReturn(storeProperties);
given(mockStoreInner.execute(any(OperationChain.class), any(Context.class))).willThrow(new RuntimeException(message));
FederatedStore mockStore = Mockito.mock(FederatedStore.class);
HashSet<Graph> filteredGraphs = Sets.newHashSet(getGraphWithMockStore(mockStoreInner));
Mockito.when(mockStore.getGraphs(user, TEST_GRAPH_ID, op)).thenReturn(filteredGraphs);
// When
try {
getFederatedHandler().doOperation(op, context, mockStore);
fail("Exception not thrown");
} catch (OperationException e) {
assertEquals(message, e.getCause().getMessage());
}
}
use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.
the class FederatedOperationOutputHandlerTest method shouldReturnEmptyIterableWhenNoResults.
@Test
public void shouldReturnEmptyIterableWhenNoResults() throws Exception {
// Given
final OP op = getExampleOperation();
op.addOption(KEY_OPERATION_OPTIONS_GRAPH_IDS, TEST_GRAPH_ID);
Schema unusedSchema = new Schema.Builder().build();
StoreProperties storeProperties = new StoreProperties();
Store mockStoreInner = Mockito.mock(Store.class);
given(mockStoreInner.getSchema()).willReturn(unusedSchema);
given(mockStoreInner.getProperties()).willReturn(storeProperties);
given(mockStoreInner.execute(any(OperationChain.class), eq(context))).willReturn(null);
FederatedStore mockStore = Mockito.mock(FederatedStore.class);
HashSet<Graph> filteredGraphs = Sets.newHashSet(getGraphWithMockStore(mockStoreInner));
Mockito.when(mockStore.getGraphs(user, TEST_GRAPH_ID, op)).thenReturn(filteredGraphs);
// When
final O results = getFederatedHandler().doOperation(op, context, mockStore);
assertEquals(0, Iterables.size((Iterable) results));
}
use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.
the class FederatedOperationOutputHandlerTest method shouldNotThrowException.
@Test
public void shouldNotThrowException() throws Exception {
// Given
// Given
final OP op = getExampleOperation();
op.addOption(KEY_OPERATION_OPTIONS_GRAPH_IDS, "1,3");
op.addOption(KEY_SKIP_FAILED_FEDERATED_STORE_EXECUTE, String.valueOf(true));
Schema unusedSchema = new Schema.Builder().build();
StoreProperties storeProperties = new StoreProperties();
Store mockStore1 = getMockStore(unusedSchema, storeProperties, o1);
Store mockStore2 = getMockStore(unusedSchema, storeProperties, o2);
Store mockStore3 = Mockito.mock(Store.class);
given(mockStore3.getSchema()).willReturn(unusedSchema);
given(mockStore3.getProperties()).willReturn(storeProperties);
given(mockStore3.execute(any(OperationChain.class), eq(context))).willThrow(new RuntimeException("Test Exception"));
Store mockStore4 = getMockStore(unusedSchema, storeProperties, o4);
FederatedStore mockStore = Mockito.mock(FederatedStore.class);
LinkedHashSet<Graph> filteredGraphs = Sets.newLinkedHashSet();
filteredGraphs.add(getGraphWithMockStore(mockStore1));
filteredGraphs.add(getGraphWithMockStore(mockStore3));
Mockito.when(mockStore.getGraphs(user, "1,3", op)).thenReturn(filteredGraphs);
// When
O theMergedResultsOfOperation = null;
try {
theMergedResultsOfOperation = getFederatedHandler().doOperation(op, context, mockStore);
} catch (Exception e) {
fail("Exception should not have been thrown: " + e.getMessage());
}
// Then
validateMergeResultsFromFieldObjects(theMergedResultsOfOperation, o1);
ArgumentCaptor<Context> context1Captor = ArgumentCaptor.forClass(Context.class);
verify(mockStore1).execute(any(OperationChain.class), context1Captor.capture());
assertNotEquals(context.getJobId(), context1Captor.getValue().getJobId());
assertEquals(context.getUser(), context1Captor.getValue().getUser());
verify(mockStore2, never()).execute(any(OperationChain.class), any(Context.class));
ArgumentCaptor<Context> context3Captor = ArgumentCaptor.forClass(Context.class);
verify(mockStore3).execute(any(OperationChain.class), context3Captor.capture());
assertNotEquals(context.getJobId(), context3Captor.getValue().getJobId());
assertEquals(context.getUser(), context3Captor.getValue().getUser());
verify(mockStore4, never()).execute(any(OperationChain.class), any(Context.class));
}
Aggregations