Search in sources :

Example 1 with ToVertices

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

the class ToVerticesHandlerTest method shouldConvertEdgeSeedsToVertices_sourceAndDestination.

@Test
public void shouldConvertEdgeSeedsToVertices_sourceAndDestination() throws OperationException {
    // Given
    final List elementIds = Arrays.asList(new EdgeSeed(vertex1, vertex2, false), new EdgeSeed(vertex1, vertex3, false));
    final ToVerticesHandler handler = new ToVerticesHandler();
    final ToVertices operation = mock(ToVertices.class);
    given(operation.getInput()).willReturn(elementIds);
    given(operation.getEdgeVertices()).willReturn(EdgeVertices.BOTH);
    // When
    final Iterable<Object> results = handler.doOperation(operation, new Context(), null);
    // Then
    assertThat(Sets.newHashSet(results)).containsOnly(vertex1, vertex2, vertex3);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 2 with ToVertices

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

the class ToVerticesHandlerTest method shouldBeAbleToIterableOverTheResultsMultipleTimes.

@Test
public void shouldBeAbleToIterableOverTheResultsMultipleTimes() throws OperationException {
    // Given
    final List elementIds = Arrays.asList(new EntitySeed(vertex1), new EntitySeed(vertex2));
    final ToVerticesHandler handler = new ToVerticesHandler();
    final ToVertices operation = mock(ToVertices.class);
    given(operation.getInput()).willReturn(elementIds);
    given(operation.getEdgeVertices()).willReturn(EdgeVertices.NONE);
    // When
    final Iterable<Object> results = handler.doOperation(operation, new Context(), null);
    // Then
    final Set<Object> set1 = Sets.newHashSet(results);
    final Set<Object> set2 = Sets.newHashSet(results);
    assertEquals(Sets.newHashSet(vertex1, vertex2), set1);
    assertEquals(set1, set2);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 3 with ToVertices

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

the class ToVerticesHandlerTest method shouldConvertEdgeSeedsToVertices_matchedVertexOpposite.

@Test
public void shouldConvertEdgeSeedsToVertices_matchedVertexOpposite() throws OperationException {
    // Given
    final List elementIds = Arrays.asList(new EdgeSeed(vertex1, vertex2, false, EdgeId.MatchedVertex.SOURCE), new EdgeSeed(vertex3, vertex4, false, EdgeId.MatchedVertex.DESTINATION), new EdgeSeed(vertex5, vertex6, false, EdgeId.MatchedVertex.DESTINATION), new EdgeSeed(vertex7, vertex8, false, null));
    final ToVerticesHandler handler = new ToVerticesHandler();
    final ToVertices operation = mock(ToVertices.class);
    given(operation.getInput()).willReturn(elementIds);
    given(operation.getUseMatchedVertex()).willReturn(ToVertices.UseMatchedVertex.OPPOSITE);
    given(operation.getEdgeVertices()).willReturn(EdgeVertices.SOURCE);
    // When
    final Iterable<Object> results = handler.doOperation(operation, new Context(), null);
    // Then
    assertThat(Sets.newHashSet(results)).containsOnly(vertex2, vertex3, vertex5, vertex7);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 4 with ToVertices

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

the class ToVerticesHandlerTest method shouldHandleNullInput.

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

Example 5 with ToVertices

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

the class ToVerticesHandlerTest method shouldCorrectlyConvertEdgeSeedsWithNoneUseMatchedVertex.

@Test
public void shouldCorrectlyConvertEdgeSeedsWithNoneUseMatchedVertex() throws OperationException {
    // Given
    final List elementIds = Arrays.asList(new EdgeSeed(vertex1, vertex2, false, null), new EdgeSeed(vertex3, vertex4, false, null), new EdgeSeed(vertex5, vertex6, false, null), new EdgeSeed(vertex7, vertex8, false, null));
    final ToVerticesHandler handler = new ToVerticesHandler();
    final ToVertices operation = mock(ToVertices.class);
    given(operation.getInput()).willReturn(elementIds);
    given(operation.getUseMatchedVertex()).willReturn(ToVertices.UseMatchedVertex.IGNORE);
    // When
    final Iterable<Object> results = handler.doOperation(operation, new Context(), null);
    // Then
    assertThat(Sets.newHashSet(results)).isEmpty();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)14 ToVertices (uk.gov.gchq.gaffer.operation.impl.output.ToVertices)14 Context (uk.gov.gchq.gaffer.store.Context)12 List (java.util.List)11 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)8 ToSet (uk.gov.gchq.gaffer.operation.impl.output.ToSet)3 Set (java.util.Set)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 Map (uk.gov.gchq.gaffer.operation.impl.Map)2 OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)2 OperationChainOptimiser (uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)2 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)2 FirstItem (uk.gov.gchq.koryphe.impl.function.FirstItem)2 IterableFunction (uk.gov.gchq.koryphe.impl.function.IterableFunction)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 Walk (uk.gov.gchq.gaffer.data.graph.Walk)1 ExtractWalkEdgesFromHop (uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEdgesFromHop)1