use of uk.gov.gchq.gaffer.graph.hook.GraphHook in project Gaffer by gchq.
the class GraphTest method shouldCallAllGraphHooksBeforeOperationExecuted.
@Test
public void shouldCallAllGraphHooksBeforeOperationExecuted() throws OperationException {
// Given
final Operation operation = mock(Operation.class);
final OperationChain opChain = mock(OperationChain.class);
given(opChain.getOperations()).willReturn(Collections.singletonList(operation));
final User user = mock(User.class);
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
final Graph graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).addSchema(new Schema.Builder().build()).addHook(hook1).addHook(hook2).build();
// When
graph.execute(opChain, user);
// Then
final ArgumentCaptor<OperationChain> captor1 = ArgumentCaptor.forClass(OperationChain.class);
final ArgumentCaptor<OperationChain> captor2 = ArgumentCaptor.forClass(OperationChain.class);
final InOrder inOrder = inOrder(hook1, hook2);
inOrder.verify(hook1).preExecute(captor1.capture(), Mockito.eq(user));
inOrder.verify(hook2).preExecute(captor2.capture(), Mockito.eq(user));
assertSame(captor1.getValue(), captor2.getValue());
final List<Operation> ops = captor1.getValue().getOperations();
assertEquals(1, ops.size());
assertSame(operation, ops.get(0));
}
use of uk.gov.gchq.gaffer.graph.hook.GraphHook in project Gaffer by gchq.
the class GraphTest method shouldCallAllGraphHooksAfterOperationChainExecuted.
@Test
public void shouldCallAllGraphHooksAfterOperationChainExecuted() throws OperationException {
// Given
final User user = mock(User.class);
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
final Store store = mock(Store.class);
final Schema schema = new Schema();
final Object result1 = mock(Object.class);
final Object result2 = mock(Object.class);
final Object result3 = mock(Object.class);
final OperationChain opChain = mock(OperationChain.class);
given(store.getSchema()).willReturn(schema);
given(hook1.postExecute(result1, opChain, user)).willReturn(result2);
given(hook2.postExecute(result2, opChain, user)).willReturn(result3);
final Graph graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(schema).addHook(hook1).addHook(hook2).build();
given(opChain.getOperations()).willReturn(Collections.singletonList(mock(Operation.class)));
given(store.execute(opChain, user)).willReturn(result1);
// When
final Object actualResult = graph.execute(opChain, user);
// Then
final InOrder inOrder = inOrder(hook1, hook2);
inOrder.verify(hook1).postExecute(result1, opChain, user);
inOrder.verify(hook2).postExecute(result2, opChain, user);
assertSame(actualResult, result3);
}
use of uk.gov.gchq.gaffer.graph.hook.GraphHook in project Gaffer by gchq.
the class GraphTest method shouldCallAllGraphHooksAfterOperationExecuted.
@Test
public void shouldCallAllGraphHooksAfterOperationExecuted() throws OperationException {
// Given
final Operation operation = mock(Operation.class);
final OperationChain opChain = mock(OperationChain.class);
given(opChain.getOperations()).willReturn(Collections.singletonList(operation));
final User user = mock(User.class);
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
final Store store = mock(Store.class);
final Object result1 = mock(Object.class);
final Object result2 = mock(Object.class);
final Object result3 = mock(Object.class);
final Schema schema = new Schema();
given(store.getSchema()).willReturn(schema);
given(hook1.postExecute(result1, opChain, user)).willReturn(result2);
given(hook2.postExecute(result2, opChain, user)).willReturn(result3);
final Graph graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(schema).addHook(hook1).addHook(hook2).build();
final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
given(store.execute(captor.capture(), Mockito.eq(user))).willReturn(result1);
// When
final Object actualResult = graph.execute(opChain, user);
// Then
final InOrder inOrder = inOrder(hook1, hook2);
inOrder.verify(hook1).postExecute(result1, captor.getValue(), user);
inOrder.verify(hook2).postExecute(result2, captor.getValue(), user);
final List<Operation> ops = captor.getValue().getOperations();
assertEquals(1, ops.size());
assertSame(operation, ops.get(0));
assertSame(actualResult, result3);
}
Aggregations