Search in sources :

Example 31 with StoreProperties

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

the class GraphTest method shouldSetGraphViewOnOperationAndDelegateDoOperationToStore.

@Test
public void shouldSetGraphViewOnOperationAndDelegateDoOperationToStore() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    given(store.getSchema()).willReturn(new Schema());
    given(store.getProperties()).willReturn(new StoreProperties());
    final View view = new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build();
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).view(view).build()).store(store).build();
    final Integer expectedResult = 5;
    final GetElements operation = new GetElements();
    final OperationChain<Integer> opChain = mock(OperationChain.class);
    final OperationChain clonedOpChain = mock(OperationChain.class);
    given(opChain.shallowClone()).willReturn(clonedOpChain);
    given(clonedOpChain.getOperations()).willReturn(Lists.newArrayList(operation));
    given(store.execute(clonedOpChain, clonedContext)).willReturn(expectedResult);
    // When
    Integer result = graph.execute(opChain, context);
    // Then
    assertEquals(expectedResult, result);
    verify(store).execute(clonedOpChain, clonedContext);
    JsonAssert.assertEquals(view.toJson(false), operation.getView().toJson(false));
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) 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 32 with StoreProperties

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

the class GraphTest method shouldCallAllGraphHooksOnGraphHookPostExecuteFailureWhenRunningJob.

@Test
public void shouldCallAllGraphHooksOnGraphHookPostExecuteFailureWhenRunningJob() throws OperationException {
    // Given
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final Store store = mock(Store.class);
    final JobDetail result1 = mock(JobDetail.class);
    final JobDetail result2 = mock(JobDetail.class);
    final JobDetail result3 = mock(JobDetail.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.executeJob(captor.capture(), eq(clonedContext))).willReturn(result1);
    // When / Then
    try {
        graph.executeJob(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) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ArrayList(java.util.ArrayList) List(java.util.List) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 33 with StoreProperties

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

the class GraphTest method shouldThrowExceptionIfGraphIdIsInvalid.

@Test
public void shouldThrowExceptionIfGraphIdIsInvalid() throws Exception {
    final StoreProperties properties = mock(StoreProperties.class);
    given(properties.getJobExecutorThreadCount()).willReturn(1);
    try {
        new Graph.Builder().config(new GraphConfig.Builder().graphId("invalid-id").build()).build();
        fail("Exception expected");
    } catch (final IllegalArgumentException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 34 with StoreProperties

use of uk.gov.gchq.gaffer.store.StoreProperties 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)

Example 35 with StoreProperties

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

the class GafferResultCacheExporterTest method before.

@BeforeEach
public void before() {
    given(store.getSchema()).willReturn(new Schema());
    given(store.getProperties()).willReturn(new StoreProperties());
    resultCache = new Graph.Builder().config(new GraphConfig.Builder().graphId("resultCacheGraph").build()).store(store).build();
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) BeforeEach(org.junit.jupiter.api.BeforeEach)

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