use of uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable in project Gaffer by gchq.
the class DeduplicateHandlerTest method shouldDeduplicateResultsAndMaintainOrder.
@Test
public void shouldDeduplicateResultsAndMaintainOrder() throws OperationException {
// Given
final CloseableIterable<Integer> originalResults = new WrappedCloseableIterable<>(Arrays.asList(10, 9, 8, 10, 7, 8, 7, 6, 6, 5, 6, 9, 4, 5, 3, 4, 2, 2, 2, 1, 1));
final DeduplicateHandler<Integer> handler = new DeduplicateHandler<>();
final Deduplicate<Integer> operation = mock(Deduplicate.class);
given(operation.getInput()).willReturn(originalResults);
// When
final Iterable<Integer> results = handler.doOperation(operation, new Context(), null);
// Then
assertEquals(Arrays.asList(10, 9, 8, 7, 6, 5, 4, 3, 2, 1), Lists.newArrayList(results));
}
use of uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable 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());
}
Aggregations