Search in sources :

Example 71 with Schema

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

the class AggregatorIterator method validateOptions.

@Override
public boolean validateOptions(final Map<String, String> options) {
    if (!super.validateOptions(options)) {
        return false;
    }
    if (!options.containsKey(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS)) {
        throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS);
    }
    if (!options.containsKey(AccumuloStoreConstants.SCHEMA)) {
        throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.SCHEMA);
    }
    try {
        schema = Schema.fromJson(options.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8));
    } catch (final UnsupportedEncodingException e) {
        throw new SchemaException("Unable to deserialise the schema from json", e);
    }
    try {
        final Class<?> elementConverterClass = Class.forName(options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
        elementConverter = (AccumuloElementConverter) elementConverterClass.getConstructor(Schema.class).newInstance(schema);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new AggregationException("Failed to load element converter from class name provided : " + options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS), e);
    }
    return true;
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) AggregationException(uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 72 with Schema

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

the class AbstractAccumuloElementConverterTest method setUp.

@Before
public void setUp() throws SchemaException, IOException {
    final Schema schema = Schema.fromJson(StreamUtil.schemas(getClass()));
    converter = createConverter(schema);
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Before(org.junit.Before)

Example 73 with Schema

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

the class StoreTest method shouldHandleNullOperationSupportRequest.

@Test
public void shouldHandleNullOperationSupportRequest() throws Exception {
    // Given
    final Schema schema = createSchemaMock();
    final StoreProperties properties = mock(StoreProperties.class);
    final Validatable<Integer> validatable = mock(Validatable.class);
    final Map<String, String> options = mock(HashMap.class);
    final StoreImpl store = new StoreImpl();
    given(validatable.isValidate()).willReturn(true);
    given(validatable.getOptions()).willReturn(options);
    store.initialise(schema, properties);
    // When
    final boolean supported = store.isSupported(null);
    // Then
    assertFalse(supported);
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Test(org.junit.Test)

Example 74 with Schema

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

the class StoreTest method shouldThrowExceptionIfOperationViewIsInvalid.

@Test
public void shouldThrowExceptionIfOperationViewIsInvalid() throws OperationException, StoreException {
    // Given
    // Given
    final Schema schema = createSchemaMock();
    final StoreProperties properties = mock(StoreProperties.class);
    final AddElements addElements = new AddElements();
    final View view = mock(View.class);
    final ViewValidator viewValidator = mock(ViewValidator.class);
    final StoreImpl store = new StoreImpl(viewValidator);
    addElements.setView(view);
    given(schema.validate()).willReturn(true);
    given(viewValidator.validate(view, schema, true)).willReturn(false);
    store.initialise(schema, properties);
    // When / Then
    try {
        store.execute(addElements, user);
        fail("Exception expected");
    } catch (final SchemaException e) {
        verify(viewValidator).validate(view, schema, true);
        assertTrue(e.getMessage().contains("View"));
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 75 with Schema

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

the class StoreTest method shouldCallDoUnhandledOperationWhenDoOperationWithUnknownOperationClass.

@Test
public void shouldCallDoUnhandledOperationWhenDoOperationWithUnknownOperationClass() throws Exception {
    // Given
    final Schema schema = createSchemaMock();
    final StoreProperties properties = mock(StoreProperties.class);
    final Operation<String, String> operation = mock(Operation.class);
    final StoreImpl store = new StoreImpl();
    store.initialise(schema, properties);
    // When
    store.execute(operation, user);
    // Then
    assertEquals(1, store.getDoUnhandledOperationCalls().size());
    assertSame(operation, store.getDoUnhandledOperationCalls().get(0));
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Test(org.junit.Test)

Aggregations

Schema (uk.gov.gchq.gaffer.store.schema.Schema)86 Test (org.junit.Test)63 SQLContext (org.apache.spark.sql.SQLContext)14 AccumuloProperties (uk.gov.gchq.gaffer.accumulostore.AccumuloProperties)13 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)13 User (uk.gov.gchq.gaffer.user.User)13 HashSet (java.util.HashSet)12 Filter (org.apache.spark.sql.sources.Filter)12 EqualTo (org.apache.spark.sql.sources.EqualTo)9 MockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore)9 SingleUseMockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore)9 Element (uk.gov.gchq.gaffer.data.element.Element)9 Store (uk.gov.gchq.gaffer.store.Store)9 Before (org.junit.Before)8 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)8 Graph (uk.gov.gchq.gaffer.graph.Graph)8 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)7 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5