Search in sources :

Example 41 with Operation

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

the class AddOperationsToChainTest method shouldAddAllOperationsWithSecondAuthsGivenPath.

@Test
public void shouldAddAllOperationsWithSecondAuthsGivenPath() throws IOException {
    // Given
    AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
    User user = new User.Builder().opAuths("auth2").build();
    Operation splitStore = new SplitStoreFromFile();
    Operation validate = new Validate();
    Operation getAdjacentIds = new GetAdjacentIds();
    Operation countGroups = new CountGroups();
    Operation getElements = new GetElements();
    Operation getAllElements = new GetAllElements();
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getElements).then(getAllElements).build();
    // When
    hook.preExecute(opChain, new Context(user));
    // Then
    final OperationChain expectedOpChain = new OperationChain.Builder().first(validate).then(getAdjacentIds).then(countGroups).then(getElements).then(getAllElements).then(splitStore).build();
    JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Test(org.junit.jupiter.api.Test)

Example 42 with Operation

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

the class AddOperationsToChainTest method shouldAddAllOperationsWithFirstAuthsGivenPath.

@Test
public void shouldAddAllOperationsWithFirstAuthsGivenPath() throws IOException {
    // Given
    AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
    User user = new User.Builder().opAuths("auth1", "auth2").build();
    Operation discardOutput = new DiscardOutput();
    Operation splitStore = new SplitStoreFromFile();
    Operation getAdjacentIds = new GetAdjacentIds();
    Operation getElements = new GetElements();
    Operation getAllElements = new GetAllElements();
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getElements).then(getAllElements).build();
    // When
    hook.preExecute(opChain, new Context(user));
    // Then
    final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(getAdjacentIds).then(getElements).then(getAllElements).then(splitStore).build();
    JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) Test(org.junit.jupiter.api.Test)

Example 43 with Operation

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

the class AddOperationsToChainTest method shouldClearListWhenAddingOperations.

@Test
public void shouldClearListWhenAddingOperations() throws IOException {
    // Given
    final AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
    hook.setBefore(null);
    hook.setAfter(null);
    Operation discardOutput = new DiscardOutput();
    Operation splitStore = new SplitStoreFromFile();
    Operation count = new Count<>();
    Operation getElements = new GetElements();
    final OperationChain opChain = new OperationChain.Builder().first(getElements).build();
    // When
    hook.preExecute(opChain, new Context(new User()));
    // Then
    final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(getElements).then(count).build();
    JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) Count(uk.gov.gchq.gaffer.operation.impl.Count) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) Test(org.junit.jupiter.api.Test)

Example 44 with Operation

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

the class AddOperationsToChainTest method shouldHandleNestedOperationChain.

@Test
public void shouldHandleNestedOperationChain() throws SerialisationException {
    // Given
    AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
    Operation discardOutput = new DiscardOutput();
    Operation splitStore = new SplitStoreFromFile();
    Operation validate = new Validate();
    Operation getAdjacentIds = new GetAdjacentIds();
    Operation count = new Count<>();
    Operation countGroups = new CountGroups();
    Operation getElements = new GetElements();
    If ifOp = new If.Builder<>().conditional(new Conditional(new Exists(), new GetElements())).then(new GetElements()).otherwise(new GetAllElements()).build();
    Operation getAllElements = new GetAllElements();
    Operation limit = new Limit<>();
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(new OperationChain.Builder().first(getElements).then(getAllElements).build()).then(ifOp).build();
    // When
    hook.preExecute(opChain, new Context(new User()));
    // Then
    final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then((Operation) new OperationChain.Builder().first(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).build()).then(new If.Builder<>().conditional(new Conditional(new Exists(), new OperationChain<>(new CountGroups(), new GetElements()))).then(new OperationChain<>(new CountGroups(), new GetElements())).otherwise(new OperationChain<>(new GetAllElements(), new Limit<>(), new Validate())).build()).then(new Count()).build();
    JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Operation(uk.gov.gchq.gaffer.operation.Operation) Count(uk.gov.gchq.gaffer.operation.impl.Count) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 45 with Operation

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

the class GraphTest method shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook.

@Test
public void shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook() throws OperationException {
    // Given
    operation = new GetElements.Builder().build();
    final UpdateViewHook updateViewHook = new UpdateViewHook.Builder().blackListElementGroups(Collections.singleton(TestGroups.EDGE)).build();
    given(opChain.getOperations()).willReturn(Lists.newArrayList(operation));
    given(opChain.shallowClone()).willReturn(clonedOpChain);
    given(clonedOpChain.getOperations()).willReturn(Lists.newArrayList(operation));
    given(clonedOpChain.flatten()).willReturn(Arrays.asList(operation));
    final Store store = mock(Store.class);
    given(store.getSchema()).willReturn(new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_5, new SchemaEdgeDefinition()).build());
    given(store.getProperties()).willReturn(new StoreProperties());
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(updateViewHook).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).build();
    final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
    final ArgumentCaptor<Context> contextCaptor1 = ArgumentCaptor.forClass(Context.class);
    given(store.execute(captor.capture(), contextCaptor1.capture())).willReturn(new ArrayList<>());
    // When / Then
    graph.execute(opChain, user);
    final List<Operation> ops = captor.getValue().getOperations();
    JsonAssert.assertEquals(new View.Builder().edge(TestGroups.EDGE_5).build().toCompactJson(), ((GetElements) ops.get(0)).getView().toCompactJson());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) UpdateViewHook(uk.gov.gchq.gaffer.graph.hook.UpdateViewHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)136 Test (org.junit.jupiter.api.Test)88 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)49 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)44 Schema (uk.gov.gchq.gaffer.store.schema.Schema)41 Context (uk.gov.gchq.gaffer.store.Context)35 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)34 Store (uk.gov.gchq.gaffer.store.Store)28 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)26 LinkedHashMap (java.util.LinkedHashMap)21 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)21 User (uk.gov.gchq.gaffer.user.User)21 ArrayList (java.util.ArrayList)18 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)18 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)17 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)16 HashSet (java.util.HashSet)15 HashMap (java.util.HashMap)13 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)13 OperationException (uk.gov.gchq.gaffer.operation.OperationException)13