Search in sources :

Example 41 with StoreProperties

use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.

the class GraphTest method shouldCallAllGraphHooksBeforeJobExecuted.

@Test
public void shouldCallAllGraphHooksBeforeJobExecuted() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    final Schema schema = new Schema();
    given(store.getSchema()).willReturn(schema);
    given(store.getProperties()).willReturn(new StoreProperties());
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(hook1).addHook(hook2).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(new Schema.Builder().build()).build();
    // When
    graph.executeJob(opChain, context);
    // Then
    final InOrder inOrder = inOrder(hook1, hook2, operation);
    inOrder.verify(hook1).preExecute(clonedOpChain, clonedContext);
    inOrder.verify(hook2).preExecute(clonedOpChain, clonedContext);
    inOrder.verify(operation).setView(Mockito.any(View.class));
    verify(context).setOriginalOpChain(opChain);
}
Also used : InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 42 with StoreProperties

use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.

the class GraphTest method shouldAddHookAndGetGraphHooks.

@Test
public void shouldAddHookAndGetGraphHooks() throws Exception {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStore.class.getName());
    TestStore.mockStore = mock(Store.class);
    given(TestStore.mockStore.isSupported(NamedOperation.class)).willReturn(true);
    final GraphHook graphHook1 = mock(GraphHook.class);
    final NamedOperationResolver graphHook2 = new NamedOperationResolver();
    final Log4jLogger graphHook3 = mock(Log4jLogger.class);
    // When
    final Graph graph = new Graph.Builder().graphId("graphId").storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).addHook(graphHook1).addHook(graphHook2).addHook(graphHook3).build();
    // Then
    assertEquals(Arrays.asList(NamedViewResolver.class, graphHook1.getClass(), graphHook2.getClass(), graphHook3.getClass(), FunctionAuthoriser.class), graph.getGraphHooks());
}
Also used : NamedOperationResolver(uk.gov.gchq.gaffer.graph.hook.NamedOperationResolver) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Log4jLogger(uk.gov.gchq.gaffer.graph.hook.Log4jLogger) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) Test(org.junit.jupiter.api.Test)

Example 43 with StoreProperties

use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.

the class GraphTest method shouldAddHooksFromPathAndGetGraphHooks.

@Test
public void shouldAddHooksFromPathAndGetGraphHooks() throws Exception {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStoreImpl.class.getName());
    final File graphHooks = tempDir.resolve("graphHooks.json").toFile();
    FileUtils.writeLines(graphHooks, IOUtils.readLines(StreamUtil.openStream(getClass(), "graphHooks.json")));
    // When
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId("graphId").addHooks(Paths.get(graphHooks.getPath())).build()).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).build();
    // Then
    assertEquals(Arrays.asList(NamedViewResolver.class, OperationChainLimiter.class, AddOperationsToChain.class, OperationAuthoriser.class, FunctionAuthoriser.class), graph.getGraphHooks());
}
Also used : OperationAuthoriser(uk.gov.gchq.gaffer.graph.hook.OperationAuthoriser) AddOperationsToChain(uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) File(java.io.File) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) OperationChainLimiter(uk.gov.gchq.gaffer.graph.hook.OperationChainLimiter) Test(org.junit.jupiter.api.Test)

Example 44 with StoreProperties

use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.

the class GraphTest method shouldNotAddExtraGroupsFromSchemaViewWithUpdateViewHookWhenInBlacklist.

@Test
public void shouldNotAddExtraGroupsFromSchemaViewWithUpdateViewHookWhenInBlacklist() throws OperationException {
    // Given
    operation = new GetElements.Builder().build();
    final UpdateViewHook updateViewHook = new UpdateViewHook.Builder().addExtraGroups(true).blackListElementGroups(Sets.newHashSet(TestGroups.EDGE_4, 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_4, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_5, new SchemaEdgeDefinition()).edge(TestGroups.EDGE, 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) Schema(uk.gov.gchq.gaffer.store.schema.Schema) 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)

Example 45 with StoreProperties

use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.

the class GraphTest method shouldCallAllGraphHooksOnGraphHookPostExecuteFailure.

@Test
public void shouldCallAllGraphHooksOnGraphHookPostExecuteFailure() throws OperationException {
    // Given
    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(store.getProperties()).willReturn(new StoreProperties());
    given(hook1.postExecute(result1, clonedOpChain, clonedContext)).willReturn(result2);
    final RuntimeException e = new RuntimeException("Hook2 failed in postExecute");
    given(hook2.postExecute(result2, clonedOpChain, clonedContext)).willThrow(e);
    given(hook1.onFailure(result2, clonedOpChain, clonedContext, e)).willThrow(new RuntimeException("Hook1 failed in onFailure"));
    given(hook2.onFailure(result2, clonedOpChain, clonedContext, e)).willReturn(result3);
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(hook1).addHook(hook2).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(schema).build();
    final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
    given(store.execute(captor.capture(), eq(clonedContext))).willReturn(result1);
    // When / Then
    try {
        graph.execute(opChain, context);
        fail("Exception expected");
    } catch (final RuntimeException runtimeE) {
        final InOrder inOrder = inOrder(context, hook1, hook2);
        inOrder.verify(context).setOriginalOpChain(opChain);
        inOrder.verify(hook1).postExecute(result1, captor.getValue(), clonedContext);
        inOrder.verify(hook2).postExecute(result2, captor.getValue(), clonedContext);
        inOrder.verify(hook1).onFailure(result2, captor.getValue(), clonedContext, e);
        inOrder.verify(hook2).onFailure(result2, captor.getValue(), clonedContext, e);
        final List<Operation> ops = captor.getValue().getOperations();
        assertThat(ops).hasSize(1);
        assertSame(operation, ops.get(0));
    }
}
Also used : InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) CreateObject(uk.gov.gchq.koryphe.impl.function.CreateObject) ArrayList(java.util.ArrayList) List(java.util.List) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)170 Test (org.junit.jupiter.api.Test)136 Schema (uk.gov.gchq.gaffer.store.schema.Schema)102 Store (uk.gov.gchq.gaffer.store.Store)74 Context (uk.gov.gchq.gaffer.store.Context)47 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)42 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)39 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)26 Graph (uk.gov.gchq.gaffer.graph.Graph)26 Operation (uk.gov.gchq.gaffer.operation.Operation)24 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)20 User (uk.gov.gchq.gaffer.user.User)18 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)17 BeforeEach (org.junit.jupiter.api.BeforeEach)16 GraphHook (uk.gov.gchq.gaffer.graph.hook.GraphHook)16 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)16 ExportToOtherGraph (uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph)14 HashSet (java.util.HashSet)13 FunctionAuthoriser (uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser)13