Search in sources :

Example 6 with ToArray

use of uk.gov.gchq.gaffer.operation.impl.output.ToArray in project Gaffer by gchq.

the class ToArrayHandlerTest method shouldConvertIterableOfElementsToArray.

@Test
public void shouldConvertIterableOfElementsToArray() throws OperationException {
    // Given
    final Element[] originalArray = new Element[] { new Entity.Builder().group("entity").build(), new Edge.Builder().group("edge").build() };
    final Iterable<Element> originalResults = new WrappedCloseableIterable<>(Arrays.asList(originalArray));
    final ToArrayHandler<Element> handler = new ToArrayHandler<>();
    final ToArray operation = mock(ToArray.class);
    given(operation.getInput()).willReturn(originalResults);
    // When
    final Element[] results = handler.doOperation(operation, new Context(), null);
    // Then
    assertArrayEquals(originalArray, results);
}
Also used : ToArray(uk.gov.gchq.gaffer.operation.impl.output.ToArray) Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) Test(org.junit.jupiter.api.Test)

Example 7 with ToArray

use of uk.gov.gchq.gaffer.operation.impl.output.ToArray in project Gaffer by gchq.

the class ToArrayHandlerTest method shouldConvertIterableToArray.

@Test
public void shouldConvertIterableToArray() throws OperationException {
    // Given
    final Integer[] originalArray = new Integer[] { 1, 2, 3 };
    final Iterable<Integer> originalResults = new WrappedCloseableIterable<>(Arrays.asList(originalArray));
    final ToArrayHandler<Integer> handler = new ToArrayHandler<>();
    final ToArray operation = mock(ToArray.class);
    given(operation.getInput()).willReturn(originalResults);
    // When
    final Integer[] results = handler.doOperation(operation, new Context(), null);
    // Then
    assertArrayEquals(originalArray, results);
}
Also used : ToArray(uk.gov.gchq.gaffer.operation.impl.output.ToArray) Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Test(org.junit.jupiter.api.Test)

Example 8 with ToArray

use of uk.gov.gchq.gaffer.operation.impl.output.ToArray in project Gaffer by gchq.

the class ToArrayHandlerTest method shouldConvertEmptyIterableOfObjectsToNullArray.

@Test
public void shouldConvertEmptyIterableOfObjectsToNullArray() throws OperationException {
    // Given
    final Object[] originalArray = new Object[0];
    final Iterable<Object> originalResults = new WrappedCloseableIterable<>(Arrays.asList(originalArray));
    final ToArrayHandler<Object> handler = new ToArrayHandler<>();
    final ToArray operation = mock(ToArray.class);
    given(operation.getInput()).willReturn(originalResults);
    // When
    final Object[] results = handler.doOperation(operation, new Context(), null);
    // Then
    assertNull(results);
}
Also used : ToArray(uk.gov.gchq.gaffer.operation.impl.output.ToArray) Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 ToArray (uk.gov.gchq.gaffer.operation.impl.output.ToArray)8 Context (uk.gov.gchq.gaffer.store.Context)8 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)7 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)3 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)3 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)2 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 Entity (uk.gov.gchq.gaffer.data.element.Entity)1