Search in sources :

Example 16 with SchemaEdgeDefinition

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

the class GraphTest method shouldCorrectlyAddExtraGroupsFromSchemaViewWithUpdateViewHookWhenNotInBlacklist.

@Test
public void shouldCorrectlyAddExtraGroupsFromSchemaViewWithUpdateViewHookWhenNotInBlacklist() throws OperationException {
    // Given
    operation = new GetElements.Builder().build();
    final UpdateViewHook updateViewHook = new UpdateViewHook.Builder().addExtraGroups(true).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_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).edge(TestGroups.EDGE_4).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) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) 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 17 with SchemaEdgeDefinition

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

the class GraphTest method shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeLeavingEmptyViewUsingUpdateViewHook.

@Test
public void shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeLeavingEmptyViewUsingUpdateViewHook() 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_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) 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 18 with SchemaEdgeDefinition

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

the class GroupedPropertiesSerialiserTest method setUp.

@BeforeAll
public static void setUp() {
    final SchemaEdgeDefinition edgeDef = new SchemaEdgeDefinition.Builder().build();
    schema = new Schema.Builder().vertexSerialiser(new StringSerialiser()).edge(TestGroups.EDGE, edgeDef).build();
    serialiser = new GroupedPropertiesSerialiser(schema);
}
Also used : StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 19 with SchemaEdgeDefinition

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

the class ElementSerialiserTest method setUp.

@BeforeAll
public static void setUp() {
    final SchemaEdgeDefinition edgeDef = new SchemaEdgeDefinition.Builder().build();
    final SchemaEntityDefinition entityDef = new SchemaEntityDefinition.Builder().build();
    schema = new Schema.Builder().entity(TestGroups.ENTITY, entityDef).edge(TestGroups.EDGE, edgeDef).vertexSerialiser(new StringSerialiser()).build();
    serialiser = new ElementSerialiser(schema);
}
Also used : StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 20 with SchemaEdgeDefinition

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

the class AbstractGraphLibraryTest method shouldUpdateSchema.

@Test
public void shouldUpdateSchema() {
    // Given
    graphLibrary.addOrUpdateSchema(TEST_SCHEMA_ID, schema);
    Schema tempSchema = new Schema.Builder().edge("testEdge", new SchemaEdgeDefinition()).build();
    // Then
    JsonAssert.assertEquals(schema.toJson(false), graphLibrary.getSchema(TEST_SCHEMA_ID).toJson(false));
    // When
    graphLibrary.addOrUpdateSchema(TEST_SCHEMA_ID, tempSchema);
    // Then
    JsonAssert.assertEquals(tempSchema.toJson(false), graphLibrary.getSchema(TEST_SCHEMA_ID).toJson(false));
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) 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