use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ElementPreAggregationFilterTest method shouldAcceptElementWhenViewValidatorAcceptsElement.
@Test
public void shouldAcceptElementWhenViewValidatorAcceptsElement() throws Exception {
// Given
final AbstractElementFilter filter = new ElementPreAggregationFilter();
final Map<String, String> options = new HashMap<>();
options.put(AccumuloStoreConstants.SCHEMA, getSchemaJson());
options.put(AccumuloStoreConstants.VIEW, getViewJson());
options.put(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS, ByteEntityAccumuloElementConverter.class.getName());
filter.validateOptions(options);
final ByteEntityAccumuloElementConverter converter = new ByteEntityAccumuloElementConverter(getSchema());
final Element element = new Edge(TestGroups.EDGE, "source", "dest", true);
final Pair<Key> key = converter.getKeysFromElement(element);
final Value value = converter.getValueFromElement(element);
// When
final boolean accept = filter.accept(key.getFirst(), value);
// Then
assertTrue(accept);
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ValidatorFilterTest method shouldAcceptElementWhenSchemaValidatorAcceptsElement.
@Test
public void shouldAcceptElementWhenSchemaValidatorAcceptsElement() throws Exception {
// Given
final ValidatorFilter filter = new ValidatorFilter();
final Map<String, String> options = new HashMap<>();
options.put(AccumuloStoreConstants.SCHEMA, getSchemaJson());
options.put(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS, ByteEntityAccumuloElementConverter.class.getName());
filter.validateOptions(options);
final ByteEntityAccumuloElementConverter converter = new ByteEntityAccumuloElementConverter(getSchema());
final Element element = new Edge(TestGroups.EDGE, "source", "dest", true);
final Pair<Key> key = converter.getKeysFromElement(element);
final Value value = converter.getValueFromElement(element);
// When
final boolean accept = filter.accept(key.getFirst(), value);
// Then
assertTrue(accept);
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ByteEntityRangeElementPropertyFilterIteratorTest method shouldOnlyAcceptDeduplicatedEdges.
@Test
public void shouldOnlyAcceptDeduplicatedEdges() throws OperationException, AccumuloElementConversionException {
// Given
final ByteEntityRangeElementPropertyFilterIterator filter = new ByteEntityRangeElementPropertyFilterIterator();
final Map<String, String> options = new HashMap<String, String>() {
{
put(AccumuloStoreConstants.OUTGOING_EDGE_ONLY, "true");
put(AccumuloStoreConstants.DEDUPLICATE_UNDIRECTED_EDGES, "true");
}
};
filter.validateOptions(options);
// value should not be used
final Value value = null;
// When / Then
for (final Element element : ELEMENTS) {
final Pair<Key> keys = converter.getKeysFromElement(element);
// First key is deduplicated, but only edges should be excepted
assertEquals("Failed for element: " + element.toString(), element instanceof Edge, filter.accept(keys.getFirst(), value));
if (null != keys.getSecond()) {
// self elements are not added the other way round
assertEquals("Failed for element: " + element.toString(), false, filter.accept(keys.getSecond(), value));
}
}
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class OneToOneElementGeneratorTest method getElementShouldReturnGeneratedElement.
@Test
public void getElementShouldReturnGeneratedElement() {
// Given
final OneToOneElementGenerator<String> generator = new OneToOneElementGeneratorImpl();
// When
final Element result = generator.getElement(obj1);
// Then
assertSame(elm1, result);
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ElementFilterTest method shouldWrapElementInElementTupleAndCallSuper.
@Test
public void shouldWrapElementInElementTupleAndCallSuper() {
// Given
final String reference = "reference1";
final String value = "value";
final ElementFilter filter = new ElementFilter();
final ConsumerFunctionContext<String, FilterFunction> functionContext1 = mock(ConsumerFunctionContext.class);
final FilterFunction function = mock(FilterFunction.class);
given(functionContext1.getFunction()).willReturn(function);
filter.addFunction(functionContext1);
final Element element = mock(Element.class);
given(element.getProperty(reference)).willReturn(value);
final ArgumentCaptor<ElementTuple> elementTupleCaptor = ArgumentCaptor.forClass(ElementTuple.class);
given(functionContext1.select(elementTupleCaptor.capture())).willReturn(new Object[] { value });
// When
filter.filter(element);
// Then
assertSame(element, elementTupleCaptor.getValue().getElement());
verify(functionContext1).getFunction();
final ArgumentCaptor<Object[]> argumentCaptor = ArgumentCaptor.forClass(Object[].class);
verify(function).isValid(argumentCaptor.capture());
assertEquals(value, argumentCaptor.getValue()[0]);
}
Aggregations