Search in sources :

Example 1 with ToArray

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

the class ToArrayHandlerTest method shouldConvertIterableOfElementIdsToArray.

@Test
public void shouldConvertIterableOfElementIdsToArray() throws OperationException {
    // Given
    final ElementId[] originalArray = new ElementId[] { new EntitySeed("vertex"), new EdgeSeed("src", "dest", true) };
    final Iterable<ElementId> originalResults = new WrappedCloseableIterable<>(Arrays.asList(originalArray));
    final ToArrayHandler<ElementId> handler = new ToArrayHandler<>();
    final ToArray operation = mock(ToArray.class);
    given(operation.getInput()).willReturn(originalResults);
    // When
    final ElementId[] 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) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.jupiter.api.Test)

Example 2 with ToArray

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

the class ToArrayHandlerTest method shouldConvertIterableOfElementsAndElementIdsToArray.

@Test
public void shouldConvertIterableOfElementsAndElementIdsToArray() throws OperationException {
    // Given
    final ElementId[] originalArray = new ElementId[] { new Entity.Builder().group("entity").build(), new Edge.Builder().group("edge").build(), new EntitySeed("vertex"), new EdgeSeed("src", "dest", true) };
    final Iterable<ElementId> originalResults = new WrappedCloseableIterable<>(Arrays.asList(originalArray));
    final ToArrayHandler<ElementId> handler = new ToArrayHandler<>();
    final ToArray operation = mock(ToArray.class);
    given(operation.getInput()).willReturn(originalResults);
    // When
    final ElementId[] 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) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.jupiter.api.Test)

Example 3 with ToArray

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

the class ToArrayHandlerTest method shouldHandleZeroLengthInput.

@Test
public void shouldHandleZeroLengthInput() throws OperationException {
    // Given
    final Integer[] originalArray = new Integer[] {};
    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
    assertThat(results).isNull();
}
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 4 with ToArray

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

the class ToArrayHandlerTest method shouldHandleNullInput.

@Test
public void shouldHandleNullInput() throws OperationException {
    // Given
    final ToArrayHandler<Integer> handler = new ToArrayHandler<>();
    final ToArray operation = mock(ToArray.class);
    given(operation.getInput()).willReturn(null);
    // When
    final Integer[] results = handler.doOperation(operation, new Context(), null);
    // Then
    assertThat(results).isNull();
}
Also used : ToArray(uk.gov.gchq.gaffer.operation.impl.output.ToArray) Context(uk.gov.gchq.gaffer.store.Context) Test(org.junit.jupiter.api.Test)

Example 5 with ToArray

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

the class ToArrayHandlerTest method shouldConvertIterableOfObjectsToArray.

@Test
public void shouldConvertIterableOfObjectsToArray() throws OperationException {
    // Given
    final Object[] originalArray = new Object[] { new Entity("entity"), new Edge.Builder().group("edge"), new EntitySeed("vertex"), new EdgeSeed("src", "dest", true), 1, 2, 1.5 };
    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
    assertArrayEquals(originalArray, results);
}
Also used : ToArray(uk.gov.gchq.gaffer.operation.impl.output.ToArray) Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) 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