use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class ExportToOtherAuthorisedGraphHandlerTest method shouldThrowExceptionWithParentStorePropertiesIdWithNoParentSchemaIdAndAuths.
@Test
public void shouldThrowExceptionWithParentStorePropertiesIdWithNoParentSchemaIdAndAuths(@TempDir Path tmpPath) {
GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
// Given
Schema schema1 = new Schema.Builder().build();
graphLibrary.addOrUpdate(GRAPH_ID + 1, schema, storeProperties);
graphLibrary.addSchema(SCHEMA_ID_1, schema1);
given(store.getGraphLibrary()).willReturn(graphLibrary);
List<String> opAuths = Lists.newArrayList("auth1");
idAuths.put(GRAPH_ID + 2, opAuths);
idAuths.put(SCHEMA_ID_1, opAuths);
idAuths.put(STORE_PROPS_ID, opAuths);
final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 2).parentStorePropertiesId(STORE_PROPS_ID).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessageContaining("parentSchemaIds must be specified with parentStorePropertiesId");
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class FederatedAddGraphWithHooksHandlerTest method shouldAddGraphUsingLibrary.
@Test
public void shouldAddGraphUsingLibrary() throws Exception {
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
Schema expectedSchema = new Schema.Builder().build();
assertEquals(0, store.getGraphs(testUser, null, ignore).size());
assertEquals(0, store.getGraphs(testUser, null, ignore).size());
FederatedAddGraphWithHooksHandler federatedAddGraphWithHooksHandler = new FederatedAddGraphWithHooksHandler();
federatedAddGraphWithHooksHandler.doOperation(new AddGraphWithHooks.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).build(), new Context(testUser), store);
Collection<Graph> graphs = store.getGraphs(testUser, null, ignore);
assertThat(graphs).hasSize(1);
Graph next = graphs.iterator().next();
assertEquals(EXPECTED_GRAPH_ID, next.getGraphId());
assertEquals(expectedSchema, next.getSchema());
final GraphLibrary library = new HashMapGraphLibrary();
library.add(EXPECTED_GRAPH_ID_3, expectedSchema, PROPERTIES);
store.setGraphLibrary(library);
federatedAddGraphWithHooksHandler.doOperation(new AddGraphWithHooks.Builder().graphId(EXPECTED_GRAPH_ID_3).build(), new Context(testUser), store);
graphs = store.getGraphs(testUser, null, ignore);
assertThat(graphs).hasSize(2);
Iterator<Graph> iterator = graphs.iterator();
final HashSet<String> set = Sets.newHashSet();
while (iterator.hasNext()) {
set.add(iterator.next().getGraphId());
}
assertThat(set).contains(EXPECTED_GRAPH_ID, EXPECTED_GRAPH_ID_3);
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class GraphTest method shouldBuildGraphFromConfigAndMergeConfigWithExistingConfig.
@Test
public void shouldBuildGraphFromConfigAndMergeConfigWithExistingConfig() throws Exception {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
final String graphId1 = "graphId1";
final String graphId2 = "graphId2";
final GraphLibrary library1 = mock(GraphLibrary.class);
final GraphLibrary library2 = mock(GraphLibrary.class);
final View view1 = new View.Builder().entity(TestGroups.ENTITY).build();
final View view2 = new View.Builder().edge(TestGroups.EDGE).build();
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
final GraphHook hook3 = mock(GraphHook.class);
// When
final GraphConfig config = new GraphConfig.Builder().graphId(graphId2).library(library2).addHook(hook2).view(view2).build();
final Graph graph = new Graph.Builder().graphId(graphId1).library(library1).view(view1).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).addHook(hook1).config(config).addHook(hook3).build();
// Then
assertEquals(graphId2, graph.getGraphId());
assertEquals(view2, graph.getView());
assertEquals(library2, graph.getGraphLibrary());
assertEquals(Arrays.asList(NamedViewResolver.class, hook1.getClass(), hook2.getClass(), hook3.getClass(), FunctionAuthoriser.class), graph.getGraphHooks());
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class GraphConfigTest method getTestObject.
@Override
protected GraphConfig getTestObject() {
final String graphId = "graphId";
final GraphLibrary library = new HashMapGraphLibrary();
final View view = new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groupBy().build()).build();
final GraphHook hook1 = new AddOperationsToChain();
final GraphHook hook2 = new OperationChainLimiter();
return new GraphConfig.Builder().graphId(graphId).library(library).description("testGraphConfig").addHook(hook1).addHook(hook2).view(view).build();
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class GraphDelegate method createGraphSerialisable.
public GraphSerialisable createGraphSerialisable(final Store store, final String graphId, final Schema schema, final StoreProperties storeProperties, final List<String> parentSchemaIds, final String parentStorePropertiesId, final GraphHook[] hooks) {
final GraphLibrary graphLibrary = store.getGraphLibrary();
final Pair<Schema, StoreProperties> existingGraphPair = null != graphLibrary ? graphLibrary.get(graphId) : null;
validateGraph(store, graphId, schema, storeProperties, parentSchemaIds, parentStorePropertiesId, existingGraphPair);
final Schema resolvedSchema = resolveSchemaForGraph(store, schema, parentSchemaIds, existingGraphPair);
final StoreProperties resolvedStoreProperties = resolveStorePropertiesForGraph(store, storeProperties, parentStorePropertiesId, existingGraphPair);
return new GraphSerialisable.Builder().config(new GraphConfig.Builder().graphId(graphId).library(graphLibrary).addHooks(hooks).build()).schema(resolvedSchema).properties(resolvedStoreProperties).build();
}
Aggregations