Search in sources :

Example 16 with StoreProperties

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

the class FederatedOperationOutputHandlerTest method shouldReturnEmptyIterableWhenNoResults.

@Test
public void shouldReturnEmptyIterableWhenNoResults() throws Exception {
    // Given
    final OP op = getExampleOperation();
    op.addOption(KEY_OPERATION_OPTIONS_GRAPH_IDS, TEST_GRAPH_ID);
    Schema unusedSchema = new Schema.Builder().build();
    StoreProperties storeProperties = new StoreProperties();
    Store mockStoreInner = Mockito.mock(Store.class);
    given(mockStoreInner.getSchema()).willReturn(unusedSchema);
    given(mockStoreInner.getProperties()).willReturn(storeProperties);
    given(mockStoreInner.execute(any(OperationChain.class), eq(context))).willReturn(null);
    FederatedStore mockStore = Mockito.mock(FederatedStore.class);
    HashSet<Graph> filteredGraphs = Sets.newHashSet(getGraphWithMockStore(mockStoreInner));
    Mockito.when(mockStore.getGraphs(user, TEST_GRAPH_ID, op)).thenReturn(filteredGraphs);
    // When
    final O results = getFederatedHandler().doOperation(op, context, mockStore);
    assertEquals(0, Iterables.size((Iterable) results));
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Store(uk.gov.gchq.gaffer.store.Store) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Test(org.junit.jupiter.api.Test)

Example 17 with StoreProperties

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

the class FederatedOperationOutputHandlerTest method shouldNotThrowException.

@Test
public void shouldNotThrowException() throws Exception {
    // Given
    // Given
    final OP op = getExampleOperation();
    op.addOption(KEY_OPERATION_OPTIONS_GRAPH_IDS, "1,3");
    op.addOption(KEY_SKIP_FAILED_FEDERATED_STORE_EXECUTE, String.valueOf(true));
    Schema unusedSchema = new Schema.Builder().build();
    StoreProperties storeProperties = new StoreProperties();
    Store mockStore1 = getMockStore(unusedSchema, storeProperties, o1);
    Store mockStore2 = getMockStore(unusedSchema, storeProperties, o2);
    Store mockStore3 = Mockito.mock(Store.class);
    given(mockStore3.getSchema()).willReturn(unusedSchema);
    given(mockStore3.getProperties()).willReturn(storeProperties);
    given(mockStore3.execute(any(OperationChain.class), eq(context))).willThrow(new RuntimeException("Test Exception"));
    Store mockStore4 = getMockStore(unusedSchema, storeProperties, o4);
    FederatedStore mockStore = Mockito.mock(FederatedStore.class);
    LinkedHashSet<Graph> filteredGraphs = Sets.newLinkedHashSet();
    filteredGraphs.add(getGraphWithMockStore(mockStore1));
    filteredGraphs.add(getGraphWithMockStore(mockStore3));
    Mockito.when(mockStore.getGraphs(user, "1,3", op)).thenReturn(filteredGraphs);
    // When
    O theMergedResultsOfOperation = null;
    try {
        theMergedResultsOfOperation = getFederatedHandler().doOperation(op, context, mockStore);
    } catch (Exception e) {
        fail("Exception should not have been thrown: " + e.getMessage());
    }
    // Then
    validateMergeResultsFromFieldObjects(theMergedResultsOfOperation, o1);
    ArgumentCaptor<Context> context1Captor = ArgumentCaptor.forClass(Context.class);
    verify(mockStore1).execute(any(OperationChain.class), context1Captor.capture());
    assertNotEquals(context.getJobId(), context1Captor.getValue().getJobId());
    assertEquals(context.getUser(), context1Captor.getValue().getUser());
    verify(mockStore2, never()).execute(any(OperationChain.class), any(Context.class));
    ArgumentCaptor<Context> context3Captor = ArgumentCaptor.forClass(Context.class);
    verify(mockStore3).execute(any(OperationChain.class), context3Captor.capture());
    assertNotEquals(context.getJobId(), context3Captor.getValue().getJobId());
    assertEquals(context.getUser(), context3Captor.getValue().getUser());
    verify(mockStore4, never()).execute(any(OperationChain.class), any(Context.class));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Store(uk.gov.gchq.gaffer.store.Store) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Test(org.junit.jupiter.api.Test)

Example 18 with StoreProperties

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

the class AddGraphWithHooksTest method builderShouldCreatePopulatedOperation.

@Test
@Override
public void builderShouldCreatePopulatedOperation() {
    Schema expectedSchema = new Schema.Builder().build();
    StoreProperties storeProperties = new AccumuloProperties();
    Log4jLogger log4jLogger = new Log4jLogger();
    AddGraphWithHooks op = new Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(storeProperties).hooks(log4jLogger).readAccessPredicate(READ_ACCESS_PREDICATE).writeAccessPredicate(WRITE_ACCESS_PREDICATE).build();
    assertEquals(EXPECTED_GRAPH_ID, op.getGraphId());
    assertEquals(expectedSchema, op.getSchema());
    assertNotNull(op.getStoreProperties().getStorePropertiesClassName());
    assertEquals(AccumuloProperties.class, op.getStoreProperties().getStorePropertiesClass());
    assertThat(op.getHooks()).hasSize(1);
    assertEquals(log4jLogger, op.getHooks()[0]);
    assertEquals(READ_ACCESS_PREDICATE, op.getReadAccessPredicate());
    assertEquals(WRITE_ACCESS_PREDICATE, op.getWriteAccessPredicate());
}
Also used : AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Builder(uk.gov.gchq.gaffer.federatedstore.operation.AddGraphWithHooks.Builder) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Log4jLogger(uk.gov.gchq.gaffer.graph.hook.Log4jLogger) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 19 with StoreProperties

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

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

the class GraphTest method shouldManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook.

@Test
public void shouldManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook() throws OperationException {
    // Given
    operation = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE_5).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().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) 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) 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)

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