use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldReturnClonedViewFromConfig.
@Test
public void shouldReturnClonedViewFromConfig() throws Exception {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
final String graphId = "graphId";
final View view = new View.Builder().entity(TestGroups.ENTITY).build();
// When
final GraphConfig config = new GraphConfig.Builder().graphId(graphId).view(view).build();
final Graph graph = new Graph.Builder().config(config).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).build();
// Then
assertEquals(graphId, graph.getGraphId());
assertEquals(view, graph.getView());
assertNotSame(view, graph.getView());
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldManipulateViewRemovingBlacklistedEdgeLeavingEmptyViewUsingUpdateViewHook.
@Test
public void shouldManipulateViewRemovingBlacklistedEdgeLeavingEmptyViewUsingUpdateViewHook() throws OperationException {
// Given
operation = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).build()).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());
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().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 shouldDelegateGetSupportedOperationsToStore.
@Test
public void shouldDelegateGetSupportedOperationsToStore() {
// Given
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema());
given(store.getProperties()).willReturn(new StoreProperties());
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).store(store).build();
final Set<Class<? extends Operation>> expectedSupportedOperations = mock(Set.class);
given(store.getSupportedOperations()).willReturn(expectedSupportedOperations);
// When
final Set<Class<? extends Operation>> supportedOperations = graph.getSupportedOperations();
// Then
assertSame(expectedSupportedOperations, supportedOperations);
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldAddHookFromPathAndGetGraphHooks.
@Test
public void shouldAddHookFromPathAndGetGraphHooks() throws Exception {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
final File graphHook1File = tempDir.resolve("opChainLimiter.json").toFile();
FileUtils.writeLines(graphHook1File, IOUtils.readLines(StreamUtil.openStream(getClass(), "opChainLimiter.json")));
final File graphHook2File = tempDir.resolve("opAuthoriser.json").toFile();
FileUtils.writeLines(graphHook2File, IOUtils.readLines(StreamUtil.openStream(getClass(), "opAuthoriser.json")));
// When
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId("graphId").addHook(Paths.get(graphHook1File.getPath())).addHook(Paths.get(graphHook2File.getPath())).build()).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).build();
// Then
assertEquals(Arrays.asList(NamedViewResolver.class, OperationChainLimiter.class, OperationAuthoriser.class, FunctionAuthoriser.class), graph.getGraphHooks());
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldBuildGraphFromConfigAndSetIdsToGraphsWhenIdentical.
@Test
public void shouldBuildGraphFromConfigAndSetIdsToGraphsWhenIdentical() {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
String storePropertiesId1 = "storePropertiesId1";
final Schema schema = new Schema.Builder().build();
final String graphId1 = "graphId1";
final HashMapGraphLibrary library = new HashMapGraphLibrary();
library.addSchema(SCHEMA_ID_1, schema);
library.addProperties(storePropertiesId1, storeProperties);
// When
final GraphConfig config = new GraphConfig.Builder().graphId(graphId1).library(library).build();
final Graph graph1 = new Graph.Builder().config(config).addToLibrary(true).parentStorePropertiesId(storePropertiesId1).storeProperties(storeProperties).addParentSchemaIds(SCHEMA_ID_1).addSchemas(schema).build();
// Then
assertEquals(graphId1, graph1.getGraphId());
JsonAssert.assertEquals(library.getSchema(SCHEMA_ID_1).toJson(false), schema.toJson(false));
// Check that the schemaId = schemaId1 as both the parent and supplied schema have same id's
// Check that the storePropsId = storePropertiesId1 as both parent and supplied storeProps have same id's
assertThat(graphId1).isEqualTo(library.getIds(graphId1).getFirst()).isEqualTo(library.getIds(graphId1).getSecond());
}
Aggregations