use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldBuildGraphUsingGraphIdAndLookupSchema.
@Test
public void shouldBuildGraphUsingGraphIdAndLookupSchema() throws Exception {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
final Schema schemaModule1 = new Schema.Builder().type(TestTypes.PROP_STRING, new TypeDefinition.Builder().clazz(String.class).build()).type("vertex", new TypeDefinition.Builder().clazz(String.class).build()).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).build();
final Schema schemaModule2 = new Schema.Builder().type(TestTypes.PROP_INTEGER, new TypeDefinition.Builder().clazz(Integer.class).build()).type("vertex2", new TypeDefinition.Builder().clazz(String.class).build()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_2, TestTypes.PROP_INTEGER).aggregate(false).source("vertex2").destination("vertex2").directed(DIRECTED_EITHER).build()).build();
final Schema schemaModule3 = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).vertex("vertex3").build()).type("vertex3", new TypeDefinition.Builder().clazz(String.class).build()).build();
final Schema schemaModule4 = new Schema.Builder().entity(TestGroups.ENTITY_2, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_2, TestTypes.PROP_INTEGER).aggregate(false).vertex("vertex4").build()).type("vertex4", new TypeDefinition.Builder().clazz(String.class).build()).type(DIRECTED_EITHER, Boolean.class).build();
// When
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).library(new HashMapGraphLibrary()).build()).addSchema(schemaModule1).addSchema(schemaModule2).addSchema(schemaModule3).addSchema(schemaModule4).storeProperties(storeProperties).build();
final Graph graph2 = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).library(new HashMapGraphLibrary()).build()).storeProperties(storeProperties).build();
// Then
JsonAssert.assertEquals(graph.getSchema().toJson(false), graph2.getSchema().toJson(false));
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldThrowExceptionIfStoreClassPropertyIsNotSet.
@Test
public void shouldThrowExceptionIfStoreClassPropertyIsNotSet() throws OperationException {
try {
new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).addSchema(new Schema()).storeProperties(new StoreProperties()).build();
fail("exception expected");
} catch (final IllegalArgumentException e) {
assertEquals("The Store class name was not found in the store properties for key: " + StoreProperties.STORE_CLASS + ", GraphId: " + GRAPH_ID, e.getMessage());
}
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldAddSchemaGroupsIfNotIncludedInJob.
@Test
public void shouldAddSchemaGroupsIfNotIncludedInJob() throws OperationException {
// given
final Job job = new Job(null, new OperationChain.Builder().first(new GetAllElements()).build());
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition()).edge(TestGroups.EDGE, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition()).build());
given(store.getProperties()).willReturn(new StoreProperties());
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).build();
final ArgumentCaptor<Job> jobCaptor = ArgumentCaptor.forClass(Job.class);
final ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
given(store.executeJob(jobCaptor.capture(), contextCaptor.capture())).willReturn(new JobDetail());
// when
graph.executeJob(job, context);
// then
final GetAllElements operation = (GetAllElements) ((OperationChain) jobCaptor.getValue().getOperation()).getOperations().get(0);
assertEquals(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition()).edge(TestGroups.EDGE, new ViewElementDefinition()).edge(TestGroups.EDGE_2, new ViewElementDefinition()).build(), operation.getView());
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldExpandGlobalEdges.
@Test
public void shouldExpandGlobalEdges() throws OperationException {
final Schema twoEdgesNoEntities = new Schema.Builder().type(TestTypes.PROP_STRING, new TypeDefinition.Builder().clazz(String.class).build()).type("vertex", new TypeDefinition.Builder().clazz(String.class).build()).edge("firstEdge", new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).edge("secondEdge", new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).build();
final Store store = mock(Store.class);
final ArgumentCaptor<OperationChain> capturedOperation = ArgumentCaptor.forClass(OperationChain.class);
final ArgumentCaptor<Context> capturedContext = ArgumentCaptor.forClass(Context.class);
given(store.getSchema()).willReturn(twoEdgesNoEntities);
given(store.getProperties()).willReturn(mock(StoreProperties.class));
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(twoEdgesNoEntities).build();
final ElementFilter filter = mock(ElementFilter.class);
final GlobalViewElementDefinition globalEdgeAggregate = new GlobalViewElementDefinition.Builder().postAggregationFilter(filter).build();
final View view = new View.Builder().globalEdges(globalEdgeAggregate).build();
operation = new GetElements.Builder().view(view).build();
opChain = new OperationChain.Builder().first(operation).build();
graph.execute(opChain, context);
Mockito.verify(store, Mockito.times(1)).execute(capturedOperation.capture(), capturedContext.capture());
assertEquals(1, capturedOperation.getAllValues().size());
final OperationChain transformedOpChain = capturedOperation.getAllValues().get(0);
assertEquals(1, transformedOpChain.getOperations().size());
assertEquals(GetElements.class, transformedOpChain.getOperations().get(0).getClass());
final View mergedView = ((GetElements) transformedOpChain.getOperations().get(0)).getView();
assertTrue(mergedView.getGlobalEdges() == null || mergedView.getGlobalEdges().size() == 0);
assertEquals(2, mergedView.getEdges().size());
for (final Map.Entry<String, ViewElementDefinition> e : mergedView.getEdges().entrySet()) {
assertNotNull(e.getValue().getPostAggregationFilter());
}
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldBuildGraphFromConfigAndSetIdsToGraphsWhenDifferent.
@Test
public void shouldBuildGraphFromConfigAndSetIdsToGraphsWhenDifferent() {
// Given
final StoreProperties libraryStoreProperties = new StoreProperties();
libraryStoreProperties.setStoreClass(TestStoreImpl.class.getName());
final StoreProperties graphStoreProperties = new StoreProperties();
graphStoreProperties.setStoreClass(TestStoreImpl.class.getName());
final Schema librarySchema = new Schema.Builder().build();
final Schema graphSchema = new Schema.Builder().build();
final String graphId1 = "graphId1";
final HashMapGraphLibrary library = new HashMapGraphLibrary();
library.addSchema(SCHEMA_ID_1, librarySchema);
library.addProperties(STORE_PROPERTIES_ID_1, libraryStoreProperties);
// 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(graphStoreProperties).addParentSchemaIds(SCHEMA_ID_1).addSchemas(graphSchema).build();
// Then
assertEquals(graphId1, graph1.getGraphId());
JsonAssert.assertEquals(library.getSchema(SCHEMA_ID_1).toJson(false), librarySchema.toJson(false));
final Pair<String, String> ids = library.getIds(graphId1);
// Check that the schemaIds are different between the parent and supplied schema
assertEquals(graphId1, ids.getFirst());
// Check that the storePropsIds are different between the parent and supplied storeProps
assertEquals(graphId1, ids.getSecond());
}
Aggregations