use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getFullElement.
@Override
public Element getFullElement(final Key key, final Value value, final Map<String, String> options) throws AccumuloElementConversionException {
final Element element = getElementFromKey(key, options);
element.copyProperties(getPropertiesFromValue(element.getGroup(), value));
return element;
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class CoreOperationChainOptimiserTest method shouldAddValidateOperationsForAllValidatableOperations.
@Test
public void shouldAddValidateOperationsForAllValidatableOperations() throws Exception {
// Given
final Store store = mock(Store.class);
final CoreOperationChainOptimiser optimiser = new CoreOperationChainOptimiser(store);
final CloseableIterable<Element> elements = mock(CloseableIterable.class);
final Validatable<Integer> validatable1 = mock(Validatable.class);
final Operation<Iterable<Element>, Iterable<Element>> nonValidatable1 = mock(Operation.class);
final Validatable<Iterable<Element>> validatable2 = mock(Validatable.class);
final Validatable<Iterable<Element>> validatable3 = mock(Validatable.class);
final Operation<Iterable<Element>, Iterable<Element>> nonValidatable2 = mock(Operation.class);
final boolean skipInvalidElements = true;
final OperationChain<Integer> opChain = new OperationChain.Builder().first(nonValidatable2).then(validatable3).then(validatable2).then(nonValidatable1).then(validatable1).build();
given(validatable1.getElements()).willReturn(elements);
given(validatable1.isSkipInvalidElements()).willReturn(skipInvalidElements);
given(validatable2.isSkipInvalidElements()).willReturn(skipInvalidElements);
given(validatable1.isValidate()).willReturn(true);
given(validatable2.isValidate()).willReturn(true);
given(validatable3.isValidate()).willReturn(false);
// When
final OperationChain<Integer> optimisedOpChain = optimiser.optimise(opChain);
// Then
assertEquals(7, optimisedOpChain.getOperations().size());
assertSame(nonValidatable2, optimisedOpChain.getOperations().get(0));
assertSame(validatable3, optimisedOpChain.getOperations().get(1));
assertTrue(optimisedOpChain.getOperations().get(2) instanceof Validate);
assertSame(validatable2, optimisedOpChain.getOperations().get(3));
assertSame(nonValidatable1, optimisedOpChain.getOperations().get(4));
assertTrue(optimisedOpChain.getOperations().get(5) instanceof Validate);
assertSame(elements, ((Validate) optimisedOpChain.getOperations().get(5)).getElements());
assertSame(validatable1, optimisedOpChain.getOperations().get(6));
verify(validatable2).setElements(null);
verify(validatable1).setElements(null);
verify(validatable3, never()).setElements(null);
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ValidatedElementsTest method shouldThrowExceptionIfNextCalledWhenNoNextElement.
@Test
public void shouldThrowExceptionIfNextCalledWhenNoNextElement() {
// Given
final boolean skipInvalidElements = true;
final ValidatedElements validElements = new ValidatedElements(elements, schema, skipInvalidElements);
final Iterator<Element> itr = validElements.iterator();
// When 1
final Element next0 = itr.next();
final Element next1 = itr.next();
// Then 1
assertSame(elements.get(0), next0);
assertSame(elements.get(2), next1);
// When 2 / Then 2
try {
itr.next();
fail("Exception expected");
} catch (NoSuchElementException e) {
assertNotNull(e);
}
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ValidateHandlerTest method shouldValidatedElements.
@Test
public void shouldValidatedElements() throws OperationException {
// Given
final ValidateHandler handler = new ValidateHandler();
final Store store = mock(Store.class);
final Validate validate = mock(Validate.class);
final Element elm1 = mock(Element.class);
final CloseableIterable<Element> elements = new WrappedCloseableIterable<>(Collections.singletonList(elm1));
final Schema schema = mock(Schema.class);
final Context context = new Context();
given(validate.getElements()).willReturn(elements);
given(validate.isSkipInvalidElements()).willReturn(false);
given(store.getSchema()).willReturn(schema);
final String group = "group";
given(elm1.getGroup()).willReturn(group);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter validator = mock(ElementFilter.class);
given(validator.filter(elm1)).willReturn(true);
given(elementDef.getValidator(true)).willReturn(validator);
given(schema.getElement(group)).willReturn(elementDef);
// When
final Iterable<Element> result = handler.doOperation(validate, context, store);
// Then
final Iterator<Element> itr = result.iterator();
final Element elm1Result = itr.next();
assertSame(elm1, elm1Result);
assertFalse(itr.hasNext());
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ValidateHandlerTest method shouldReturnNullIfElementsAreNull.
@Test
public void shouldReturnNullIfElementsAreNull() throws OperationException {
// Given
final ValidateHandler handler = new ValidateHandler();
final Store store = mock(Store.class);
final Validate validate = mock(Validate.class);
given(validate.getElements()).willReturn(null);
final Context context = new Context();
// When
final Iterable<Element> result = handler.doOperation(validate, context, store);
// Then
assertNull(result);
}
Aggregations