Search in sources :

Example 66 with StoreProperties

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

the class ScoreOperationChainHandlerTest method shouldExecuteScoreChainOperation.

@Test
public void shouldExecuteScoreChainOperation() throws OperationException {
    // Given
    final ScoreOperationChainHandler operationHandler = new ScoreOperationChainHandler();
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    final ScoreOperationChain scoreOperationChain = mock(ScoreOperationChain.class);
    StoreProperties storeProperties = new StoreProperties();
    final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
    final GetElements op2 = mock(GetElements.class);
    final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2));
    final Integer expectedResult = 2;
    given(context.getUser()).willReturn(user);
    Set<String> opAuths = new HashSet<>();
    opAuths.add("TEST_USER");
    given(user.getOpAuths()).willReturn(opAuths);
    given(scoreOperationChain.getOperationChain()).willReturn(opChain);
    given(store.getProperties()).willReturn(storeProperties);
    // When
    final Object result = operationHandler.doOperation(new ScoreOperationChain.Builder().operationChain(opChain).build(), context, store);
    // Then
    assertSame(expectedResult, result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ScoreOperationChain(uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ScoreOperationChain(uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 67 with StoreProperties

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

the class ScoreOperationChainHandlerTest method shouldExecuteScoreChainOperationForNestedOperationChain.

@Test
public void shouldExecuteScoreChainOperationForNestedOperationChain() throws OperationException {
    // Given
    final ScoreOperationChainHandler operationHandler = new ScoreOperationChainHandler();
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    final ScoreOperationChain scoreOperationChain = mock(ScoreOperationChain.class);
    StoreProperties storeProperties = new StoreProperties();
    final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
    final GetElements op2 = mock(GetElements.class);
    final Limit op3 = mock(Limit.class);
    final OperationChain opChain1 = new OperationChain(Arrays.asList(op1, op2));
    final OperationChain opChain = new OperationChain(Arrays.asList(opChain1, op3));
    final Integer expectedResult = 3;
    given(context.getUser()).willReturn(user);
    Set<String> opAuths = new HashSet<>();
    opAuths.add("TEST_USER");
    given(user.getOpAuths()).willReturn(opAuths);
    given(scoreOperationChain.getOperationChain()).willReturn(opChain);
    given(store.getProperties()).willReturn(storeProperties);
    // When
    final Object result = operationHandler.doOperation(new ScoreOperationChain.Builder().operationChain(opChain).build(), context, store);
    // Then
    assertSame(expectedResult, result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ScoreOperationChain(uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ScoreOperationChain(uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 68 with StoreProperties

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

the class AddSchemaToLibraryHandlerTest method shouldNotSupportAddToGraphLibraryII.

@Test
public void shouldNotSupportAddToGraphLibraryII() throws Exception {
    // given
    store.setGraphLibrary(new NoGraphLibrary());
    // when
    store.initialise(TEST_STORE_ID, new Schema(), new StoreProperties());
    // then
    assertFalse(store.isSupported(AddSchemaToLibrary.class));
}
Also used : NoGraphLibrary(uk.gov.gchq.gaffer.store.library.NoGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AddSchemaToLibrary(uk.gov.gchq.gaffer.store.operation.add.AddSchemaToLibrary) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 69 with StoreProperties

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

the class AddSchemaToLibraryHandlerTest method shouldAddSchemaWithGraphLibrary.

@Test
public void shouldAddSchemaWithGraphLibrary() throws Exception {
    // given
    HashMapGraphLibrary library = new HashMapGraphLibrary();
    store.setGraphLibrary(library);
    store.initialise(TEST_STORE_ID, new Schema(), new StoreProperties());
    // when
    store.execute(new Builder().schema(schema).id(TEST_SCHEMA_ID).build(), new Context(StoreUser.blankUser()));
    // then
    Schema actualSchema = library.getSchema(TEST_SCHEMA_ID);
    assertEquals(schema, actualSchema);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Builder(uk.gov.gchq.gaffer.store.operation.add.AddSchemaToLibrary.Builder) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 70 with StoreProperties

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

the class AddSchemaToLibraryHandlerTest method shouldThrowWithNoGraphLibrary.

@Test
public void shouldThrowWithNoGraphLibrary() throws Exception {
    // given
    store.initialise(TEST_STORE_ID, new Schema(), new StoreProperties());
    try {
        // when
        store.execute(new Builder().schema(schema).id(TEST_SCHEMA_ID).build(), new Context(StoreUser.blankUser()));
        fail("Exception expected");
    } catch (final Exception e) {
        // then
        assertEquals(String.format("Operation class %s is not supported by the %s.", AddSchemaToLibrary.class.getName(), TestAddToGraphLibraryImpl.class.getSimpleName()), e.getMessage());
    }
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Builder(uk.gov.gchq.gaffer.store.operation.add.AddSchemaToLibrary.Builder) AddSchemaToLibrary(uk.gov.gchq.gaffer.store.operation.add.AddSchemaToLibrary) 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