Search in sources :

Example 26 with StoreProperties

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));
}
Also used : HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 27 with StoreProperties

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());
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 28 with StoreProperties

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());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Job(uk.gov.gchq.gaffer.jobtracker.Job) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 29 with StoreProperties

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());
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Context(uk.gov.gchq.gaffer.store.Context) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 30 with StoreProperties

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());
}
Also used : HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

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