Search in sources :

Example 6 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class ExamplesServiceTest method shouldSerialiseAndDeserialiseOperation.

private void shouldSerialiseAndDeserialiseOperation(Operation operation) throws IOException {
    //Given
    // When
    byte[] bytes = serialiser.serialise(operation);
    final Operation deserialisedOp = serialiser.deserialise(bytes, operation.getClass());
    // Then
    assertNotNull(deserialisedOp);
}
Also used : Operation(uk.gov.gchq.gaffer.operation.Operation)

Example 7 with Operation

use of uk.gov.gchq.gaffer.operation.Operation 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));
}
Also used : User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Operation(uk.gov.gchq.gaffer.operation.Operation) Test(org.junit.Test)

Example 8 with Operation

use of uk.gov.gchq.gaffer.operation.Operation 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);
}
Also used : User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) Operation(uk.gov.gchq.gaffer.operation.Operation) Test(org.junit.Test)

Example 9 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class Graph method updateOperationChainView.

private <OUTPUT> void updateOperationChainView(final OperationChain<OUTPUT> operationChain) {
    for (final Operation operation : operationChain.getOperations()) {
        final View opView;
        if (null == operation.getView()) {
            opView = view;
        } else if (!operation.getView().hasGroups()) {
            opView = new View.Builder().merge(view).merge(operation.getView()).build();
        } else {
            opView = operation.getView();
        }
        opView.expandGlobalDefinitions();
        operation.setView(opView);
    }
}
Also used : Operation(uk.gov.gchq.gaffer.operation.Operation) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

Example 10 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class NamedOperationHandler method exposeNamedOperations.

private List<Operation> exposeNamedOperations(final OperationChain<?> opChain, final User user, final INamedOperationCache cache) throws CacheOperationFailedException {
    ArrayList<Operation> operations = new ArrayList<>();
    for (final Operation operation : opChain.getOperations()) {
        if (operation instanceof NamedOperation) {
            final NamedOperation namedOp = ((NamedOperation) operation);
            OperationChain<?> innerChain = cache.getNamedOperation(namedOp.getOperationName(), user).getOperationChain();
            updateOperationInput(innerChain.getOperations().get(0), namedOp.getSeeds());
            operations.addAll(exposeNamedOperations(innerChain, user, cache));
        } else {
            operations.add(operation);
        }
    }
    return operations;
}
Also used : ArrayList(java.util.ArrayList) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)12 Schema (uk.gov.gchq.gaffer.store.schema.Schema)5 Test (org.junit.Test)4 User (uk.gov.gchq.gaffer.user.User)3 InOrder (org.mockito.InOrder)2 GraphHook (uk.gov.gchq.gaffer.graph.hook.GraphHook)2 ExtendedNamedOperation (uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation)2 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)2 GetOperation (uk.gov.gchq.gaffer.operation.GetOperation)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 Store (uk.gov.gchq.gaffer.store.Store)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)1 AddNamedOperation (uk.gov.gchq.gaffer.named.operation.AddNamedOperation)1