use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class StoreTest method shouldHandleMultiStepOperations.
@Test
public void shouldHandleMultiStepOperations() throws Exception {
// Given
final Schema schema = createSchemaMock();
final StoreProperties properties = mock(StoreProperties.class);
final StoreImpl store = new StoreImpl();
final CloseableIterable<Element> getElementsResult = mock(CloseableIterable.class);
final AddElements addElements1 = new AddElements();
final GetElements<ElementSeed, Element> getElements = new GetElements<>();
final OperationChain<CloseableIterable<Element>> opChain = new OperationChain.Builder().first(addElements1).then(getElements).build();
given(addElementsHandler.doOperation(addElements1, context, store)).willReturn(null);
given(getElementsHandler.doOperation(getElements, context, store)).willReturn(getElementsResult);
store.initialise(schema, properties);
// When
final CloseableIterable<Element> result = store.execute(opChain, user);
// Then
assertSame(getElementsResult, result);
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class StoreTest method shouldThrowExceptionWhenPropertyIsNotSerialisable.
@Test
public void shouldThrowExceptionWhenPropertyIsNotSerialisable() throws StoreException {
// Given
final Schema mySchema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, "invalidType").build()).type("invalidType", new TypeDefinition.Builder().clazz(Object.class).serialiser(new StringSerialiser()).build()).build();
final StoreProperties properties = mock(StoreProperties.class);
final StoreImpl store = new StoreImpl();
// When
try {
store.initialise(mySchema, properties);
fail();
} catch (final SchemaException exception) {
assertNotNull(exception.getMessage());
}
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class StoreTest method createSchemaMock.
private Schema createSchemaMock() {
final Schema schema = mock(Schema.class);
given(schema.validate()).willReturn(true);
given(schema.getVertexSerialiser()).willReturn(mock(Serialisation.class));
return schema;
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class StoreIT method shouldCreateStoreAndValidateSchemas.
@Test
public void shouldCreateStoreAndValidateSchemas() throws IOException, SchemaException, StoreException {
// Given
final TestStore testStore = new TestStore();
final Schema schema = Schema.fromJson(StreamUtil.schemas(getClass()));
// When
testStore.initialise(schema, new StoreProperties());
// Then
assertTrue(testStore.getSchema().getEdges().containsKey(TestGroups.EDGE));
assertTrue(testStore.getSchema().getEdges().containsKey(TestGroups.EDGE));
assertTrue(testStore.getSchema().getEntities().containsKey(TestGroups.ENTITY));
assertTrue(testStore.getSchema().getEntities().containsKey(TestGroups.ENTITY));
assertFalse(testStore.getSchema().getEdges().containsKey(TestGroups.EDGE_2));
assertFalse(testStore.getSchema().getEntities().containsKey(TestGroups.ENTITY_2));
assertFalse(testStore.getSchema().getEdges().containsKey(TestGroups.EDGE_2));
assertFalse(testStore.getSchema().getEntities().containsKey(TestGroups.ENTITY_2));
assertTrue(testStore.getSchema().validate());
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class CoreOperationChainOptimiserTest method shouldThrowExceptionIfValidatableHasValidateSetToFalseAndStoreRequiresValidation.
@Test
public void shouldThrowExceptionIfValidatableHasValidateSetToFalseAndStoreRequiresValidation() throws Exception {
// Given
final Store store = mock(Store.class);
final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
final Schema schema = mock(Schema.class);
final Validatable<Integer> validatable1 = mock(Validatable.class);
final OperationChain<Integer> opChain = new OperationChain<>(validatable1);
given(schema.validate()).willReturn(true);
given(store.isValidationRequired()).willReturn(true);
given(validatable1.isValidate()).willReturn(false);
// When / then
try {
optimiser.optimise(opChain);
} catch (UnsupportedOperationException e) {
assertNotNull(e);
}
}
Aggregations