use of uk.gov.gchq.gaffer.operation.OperationChain 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.operation.OperationChain in project Gaffer by gchq.
the class CoreOperationChainOptimiserTest method shouldNotAddValidateOperationWhenValidatableHasValidateSetToFalse.
@Test
public void shouldNotAddValidateOperationWhenValidatableHasValidateSetToFalse() throws Exception {
// Given
final Store store = mock(Store.class);
final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
final Validatable<Integer> validatable1 = mock(Validatable.class);
final boolean skipInvalidElements = true;
final CloseableIterable<Element> elements = mock(CloseableIterable.class);
final OperationChain<Integer> opChain = new OperationChain<>(validatable1);
given(validatable1.isSkipInvalidElements()).willReturn(skipInvalidElements);
given(validatable1.isValidate()).willReturn(false);
given(validatable1.getElements()).willReturn(elements);
// When
final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
// Then
assertEquals(1, optimisedOpChain.getOperations().size());
assertSame(validatable1, optimisedOpChain.getOperations().get(0));
verify(validatable1, never()).setElements(null);
}
use of uk.gov.gchq.gaffer.operation.OperationChain 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);
}
}
use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.
the class CoreOperationChainOptimiserTest method shouldAddValidateOperationForValidatableOperation.
@Test
public void shouldAddValidateOperationForValidatableOperation() throws Exception {
// Given
final Store store = mock(Store.class);
final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
final Validatable<Integer> validatable1 = mock(Validatable.class);
final boolean skipInvalidElements = true;
final CloseableIterable<Element> elements = mock(CloseableIterable.class);
final OperationChain<Integer> opChain = new OperationChain<>(validatable1);
final Map<String, String> options = mock(HashMap.class);
given(validatable1.getOptions()).willReturn(options);
given(validatable1.isSkipInvalidElements()).willReturn(skipInvalidElements);
given(validatable1.isValidate()).willReturn(true);
given(validatable1.getElements()).willReturn(elements);
// When
final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
// Then
assertEquals(2, optimisedOpChain.getOperations().size());
assertSame(elements, ((Validate) optimisedOpChain.getOperations().get(0)).getElements());
assertSame(options, optimisedOpChain.getOperations().get(0).getOptions());
assertSame(validatable1, optimisedOpChain.getOperations().get(1));
verify(validatable1).setElements(null);
}
use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.
the class CoreOperationChainOptimiserTest method shouldNotAddDeduplicateOperationForGetOperationsWithoutFlag.
@Test
public void shouldNotAddDeduplicateOperationForGetOperationsWithoutFlag() throws Exception {
// Given
final Store store = mock(Store.class);
final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
final GetIterableOperation getOperation = mock(GetIterableOperation.class);
final OperationChain<Integer> opChain = new OperationChain<>(getOperation);
given(getOperation.getResultLimit()).willReturn(null);
given(getOperation.isDeduplicate()).willReturn(false);
// When
final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
// Then
assertEquals(1, optimisedOpChain.getOperations().size());
assertSame(getOperation, optimisedOpChain.getOperations().get(0));
}
Aggregations