Search in sources :

Example 21 with StoreProperties

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

the class GraphTest method shouldNotAddDefaultSecurityHooksIfAlreadyAdded.

@Test
public void shouldNotAddDefaultSecurityHooksIfAlreadyAdded() {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStore.class.getName());
    TestStore.mockStore = mock(Store.class);
    given(TestStore.mockStore.isSupported(NamedOperation.class)).willReturn(true);
    // When
    final GraphConfig config = new GraphConfig.Builder().graphId("test").addHook(new FunctionAuthoriser(Lists.newArrayList(Identity.class))).build();
    final Graph graph = new Graph.Builder().addSchemas(StreamUtil.schemas(getClass())).storeProperties(storeProperties).config(config).build();
    // Then
    assertEquals(Arrays.asList(NamedOperationResolver.class, NamedViewResolver.class, FunctionAuthoriser.class), graph.getGraphHooks());
    assertEquals(Identity.class, ((FunctionAuthoriser) graph.getConfig().getHooks().get(2)).getUnauthorisedFunctions().get(0));
}
Also used : NamedOperationResolver(uk.gov.gchq.gaffer.graph.hook.NamedOperationResolver) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Identity(uk.gov.gchq.koryphe.impl.function.Identity) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) Test(org.junit.jupiter.api.Test)

Example 22 with StoreProperties

use of uk.gov.gchq.gaffer.store.StoreProperties 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 23 with StoreProperties

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

the class GraphTest method shouldDelegateIsSupportedToStore.

@Test
public void shouldDelegateIsSupportedToStore() {
    // 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();
    given(store.isSupported(GetElements.class)).willReturn(true);
    given(store.isSupported(GetAllElements.class)).willReturn(false);
    // When / Then
    assertTrue(graph.isSupported(GetElements.class));
    assertFalse(graph.isSupported(GetAllElements.class));
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 24 with StoreProperties

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

the class GraphTest method shouldAddHooksVarArgsAndGetGraphHooks.

@Test
public void shouldAddHooksVarArgsAndGetGraphHooks() throws Exception {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStoreImpl.class.getName());
    final GraphHook graphHook1 = mock(GraphHook.class);
    final Log4jLogger graphHook2 = mock(Log4jLogger.class);
    // When
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId("graphId").addHooks(graphHook1, graphHook2).build()).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).build();
    // Then
    assertEquals(Arrays.asList(NamedViewResolver.class, graphHook1.getClass(), graphHook2.getClass(), FunctionAuthoriser.class), graph.getGraphHooks());
}
Also used : GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) Log4jLogger(uk.gov.gchq.gaffer.graph.hook.Log4jLogger) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) Test(org.junit.jupiter.api.Test)

Example 25 with StoreProperties

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

the class GraphTest method shouldBuildGraphFromConfigAndMergeConfigWithExistingConfig.

@Test
public void shouldBuildGraphFromConfigAndMergeConfigWithExistingConfig() throws Exception {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStoreImpl.class.getName());
    final String graphId1 = "graphId1";
    final String graphId2 = "graphId2";
    final GraphLibrary library1 = mock(GraphLibrary.class);
    final GraphLibrary library2 = mock(GraphLibrary.class);
    final View view1 = new View.Builder().entity(TestGroups.ENTITY).build();
    final View view2 = new View.Builder().edge(TestGroups.EDGE).build();
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final GraphHook hook3 = mock(GraphHook.class);
    // When
    final GraphConfig config = new GraphConfig.Builder().graphId(graphId2).library(library2).addHook(hook2).view(view2).build();
    final Graph graph = new Graph.Builder().graphId(graphId1).library(library1).view(view1).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).addHook(hook1).config(config).addHook(hook3).build();
    // Then
    assertEquals(graphId2, graph.getGraphId());
    assertEquals(view2, graph.getView());
    assertEquals(library2, graph.getGraphLibrary());
    assertEquals(Arrays.asList(NamedViewResolver.class, hook1.getClass(), hook2.getClass(), hook3.getClass(), FunctionAuthoriser.class), graph.getGraphHooks());
}
Also used : GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) 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