Search in sources :

Example 46 with StoreProperties

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

the class GraphTest method shouldReturnClonedViewFromConfig.

@Test
public void shouldReturnClonedViewFromConfig() throws Exception {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStoreImpl.class.getName());
    final String graphId = "graphId";
    final View view = new View.Builder().entity(TestGroups.ENTITY).build();
    // When
    final GraphConfig config = new GraphConfig.Builder().graphId(graphId).view(view).build();
    final Graph graph = new Graph.Builder().config(config).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).build();
    // Then
    assertEquals(graphId, graph.getGraphId());
    assertEquals(view, graph.getView());
    assertNotSame(view, graph.getView());
}
Also used : StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 47 with StoreProperties

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

the class GraphTest method shouldManipulateViewRemovingBlacklistedEdgeLeavingEmptyViewUsingUpdateViewHook.

@Test
public void shouldManipulateViewRemovingBlacklistedEdgeLeavingEmptyViewUsingUpdateViewHook() throws OperationException {
    // Given
    operation = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).build()).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());
    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().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) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) 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) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 48 with StoreProperties

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

the class GraphTest method shouldDelegateGetSupportedOperationsToStore.

@Test
public void shouldDelegateGetSupportedOperationsToStore() {
    // Given
    final Store store = mock(Store.class);
    given(store.getSchema()).willReturn(new Schema());
    given(store.getProperties()).willReturn(new StoreProperties());
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).store(store).build();
    final Set<Class<? extends Operation>> expectedSupportedOperations = mock(Set.class);
    given(store.getSupportedOperations()).willReturn(expectedSupportedOperations);
    // When
    final Set<Class<? extends Operation>> supportedOperations = graph.getSupportedOperations();
    // Then
    assertSame(expectedSupportedOperations, supportedOperations);
}
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) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 49 with StoreProperties

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

the class GraphTest method shouldAddHookFromPathAndGetGraphHooks.

@Test
public void shouldAddHookFromPathAndGetGraphHooks() throws Exception {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStoreImpl.class.getName());
    final File graphHook1File = tempDir.resolve("opChainLimiter.json").toFile();
    FileUtils.writeLines(graphHook1File, IOUtils.readLines(StreamUtil.openStream(getClass(), "opChainLimiter.json")));
    final File graphHook2File = tempDir.resolve("opAuthoriser.json").toFile();
    FileUtils.writeLines(graphHook2File, IOUtils.readLines(StreamUtil.openStream(getClass(), "opAuthoriser.json")));
    // When
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId("graphId").addHook(Paths.get(graphHook1File.getPath())).addHook(Paths.get(graphHook2File.getPath())).build()).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).build();
    // Then
    assertEquals(Arrays.asList(NamedViewResolver.class, OperationChainLimiter.class, OperationAuthoriser.class, FunctionAuthoriser.class), graph.getGraphHooks());
}
Also used : OperationAuthoriser(uk.gov.gchq.gaffer.graph.hook.OperationAuthoriser) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) File(java.io.File) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) OperationChainLimiter(uk.gov.gchq.gaffer.graph.hook.OperationChainLimiter) Test(org.junit.jupiter.api.Test)

Example 50 with StoreProperties

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

the class GraphTest method shouldBuildGraphFromConfigAndSetIdsToGraphsWhenIdentical.

@Test
public void shouldBuildGraphFromConfigAndSetIdsToGraphsWhenIdentical() {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStoreImpl.class.getName());
    String storePropertiesId1 = "storePropertiesId1";
    final Schema schema = new Schema.Builder().build();
    final String graphId1 = "graphId1";
    final HashMapGraphLibrary library = new HashMapGraphLibrary();
    library.addSchema(SCHEMA_ID_1, schema);
    library.addProperties(storePropertiesId1, storeProperties);
    // 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(storeProperties).addParentSchemaIds(SCHEMA_ID_1).addSchemas(schema).build();
    // Then
    assertEquals(graphId1, graph1.getGraphId());
    JsonAssert.assertEquals(library.getSchema(SCHEMA_ID_1).toJson(false), schema.toJson(false));
    // Check that the schemaId = schemaId1 as both the parent and supplied schema have same id's
    // Check that the storePropsId = storePropertiesId1 as both parent and supplied storeProps have same id's
    assertThat(graphId1).isEqualTo(library.getIds(graphId1).getFirst()).isEqualTo(library.getIds(graphId1).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