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);
}
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());
}
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());
}
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());
}
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));
}
}
Aggregations