Search in sources :

Example 6 with SchemaEdgeDefinition

use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.

the class GraphTest method shouldThrowExceptionWithInvalidSchema.

@Test
public void shouldThrowExceptionWithInvalidSchema() {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStoreImpl.class.getName());
    // When / Then
    try {
        new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).addSchema(new Schema.Builder().edge("group", new SchemaEdgeDefinition()).entity("group", new SchemaEntityDefinition()).build()).storeProperties(storeProperties).build();
    } catch (final SchemaException e) {
        assertTrue(e.getMessage().contains("Schema is not valid"));
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 7 with SchemaEdgeDefinition

use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.

the class GraphTest method shouldConstructGraphAndCreateViewWithGroups.

@Test
public void shouldConstructGraphAndCreateViewWithGroups() {
    // Given
    final Store store = mock(Store.class);
    given(store.getGraphId()).willReturn(GRAPH_ID);
    given(store.getProperties()).willReturn(new StoreProperties());
    Map<String, SchemaEdgeDefinition> edges = new HashMap<>();
    edges.put("edge1", new SchemaEdgeDefinition());
    edges.put("edge2", new SchemaEdgeDefinition());
    edges.put("edge3", new SchemaEdgeDefinition());
    edges.put("edge4", new SchemaEdgeDefinition());
    Map<String, SchemaEntityDefinition> entities = new HashMap<>();
    entities.put("entity1", new SchemaEntityDefinition());
    entities.put("entity2", new SchemaEntityDefinition());
    entities.put("entity3", new SchemaEntityDefinition());
    entities.put("entity4", new SchemaEntityDefinition());
    Schema schema = new Schema.Builder().edges(edges).entities(entities).build();
    given(store.getSchema()).willReturn(schema);
    // When
    final View resultView = new Graph.Builder().store(store).build().getView();
    // Then
    assertNotSame(schema, resultView);
    assertArrayEquals(entities.keySet().toArray(), resultView.getEntityGroups().toArray());
    assertArrayEquals(edges.keySet().toArray(), resultView.getEdgeGroups().toArray());
    for (final ViewElementDefinition resultElementDef : resultView.getEntities().values()) {
        assertNotNull(resultElementDef);
        assertEquals(0, resultElementDef.getTransientProperties().size());
        assertNull(resultElementDef.getTransformer());
    }
    for (final ViewElementDefinition resultElementDef : resultView.getEdges().values()) {
        assertNotNull(resultElementDef);
        assertEquals(0, resultElementDef.getTransientProperties().size());
        assertNull(resultElementDef.getTransformer());
    }
}
Also used : HashMap(java.util.HashMap) 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) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 8 with SchemaEdgeDefinition

use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition 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 9 with SchemaEdgeDefinition

use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.

the class GraphTest method shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook.

@Test
public void shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook() throws OperationException {
    // Given
    operation = new GetElements.Builder().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.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_5, 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());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) UpdateViewHook(uk.gov.gchq.gaffer.graph.hook.UpdateViewHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 10 with SchemaEdgeDefinition

use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition 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());
}
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) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) UpdateViewHook(uk.gov.gchq.gaffer.graph.hook.UpdateViewHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)25 Test (org.junit.jupiter.api.Test)15 Schema (uk.gov.gchq.gaffer.store.schema.Schema)15 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)11 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)10 Store (uk.gov.gchq.gaffer.store.Store)8 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)7 Context (uk.gov.gchq.gaffer.store.Context)7 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 UpdateViewHook (uk.gov.gchq.gaffer.graph.hook.UpdateViewHook)5 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)5 Operation (uk.gov.gchq.gaffer.operation.Operation)5 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)5 HashMap (java.util.HashMap)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)4 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)4 BeforeAll (org.junit.jupiter.api.BeforeAll)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)3 ByteSequence (org.apache.accumulo.core.data.ByteSequence)2