Skip to content

Commit

Permalink
Merge branch 'develop' into gh-1422-swagger-ui-configurable-title
Browse files Browse the repository at this point in the history
  • Loading branch information
m55624 committed Nov 3, 2017
2 parents 1ac5398 + 1768207 commit d695335
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 46 deletions.
10 changes: 0 additions & 10 deletions core/data/src/main/java/uk/gov/gchq/gaffer/data/element/Edge.java
Expand Up @@ -161,16 +161,6 @@ public MatchedVertex getMatchedVertex() {
return matchedVertex;
}

@JsonIgnore
public Object getMatchedVertexValue() {
return MatchedVertex.DESTINATION == matchedVertex ? getDestination() : getSource();
}

@JsonIgnore
public Object getAdjacentMatchedVertexValue() {
return MatchedVertex.DESTINATION == matchedVertex ? getSource() : getDestination();
}

@Override
public Object getIdentifier(final IdentifierType identifierType) {
switch (identifierType) {
Expand Down
Expand Up @@ -160,4 +160,15 @@ default Matches isRelated(final EntityId that) {
}
return Matches.NONE;
}

@JsonIgnore
default Object getMatchedVertexValue() {
return MatchedVertex.DESTINATION == getMatchedVertex() ? getDestination() : getSource();
}

@JsonIgnore
default Object getAdjacentMatchedVertexValue() {
return MatchedVertex.DESTINATION == getMatchedVertex() ? getSource() : getDestination();
}

}
Expand Up @@ -32,11 +32,12 @@

/**
* A {@code ToVerticesHandler} handles for {@link ToVertices} operations.
*
* <p>
* For {@link uk.gov.gchq.gaffer.data.element.Entity} objects, the vertex object
* is used. For {@link uk.gov.gchq.gaffer.data.element.Edge}s the correct object
* is selected based on the values of the {@link EdgeVertices} and {@link UseMatchedVertex}
* values.
* </p>
*/
public class ToVerticesHandler implements OutputOperationHandler<ToVertices, Iterable<? extends Object>> {

Expand All @@ -55,10 +56,16 @@ private Function<ElementId, Stream<Object>> elementIdsToVertices(final ToVertice

if (e instanceof EdgeId) {
final EdgeId edgeId = (EdgeId) e;
if (operation.getEdgeVertices() == EdgeVertices.NONE) {
if (EdgeVertices.NONE == operation.getEdgeVertices()) {
vertices = Stream.empty();
} else if (null != edgeId.getMatchedVertex()) {
vertices = getMatchedEdgeVertices(operation, edgeId);
} else if (null != operation.getEdgeVertices()) {
vertices = getEdgeVertices(operation.getEdgeVertices(), edgeId);
} else if (UseMatchedVertex.EQUAL == operation.getUseMatchedVertex()) {
vertices = getEdgeVertices(EdgeVertices.SOURCE, edgeId);
} else if (UseMatchedVertex.OPPOSITE == operation.getUseMatchedVertex()) {
vertices = getEdgeVertices(EdgeVertices.DESTINATION, edgeId);
} else {
vertices = getEdgeVertices(operation.getEdgeVertices(), edgeId);
}
Expand Down
Expand Up @@ -17,6 +17,7 @@
package uk.gov.gchq.gaffer.store.operation.handler.output;

import com.google.common.collect.Sets;
import org.junit.Before;
import org.junit.Test;

import uk.gov.gchq.gaffer.data.element.id.EdgeId;
Expand All @@ -34,6 +35,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
Expand All @@ -42,12 +44,25 @@

public class ToVerticesHandlerTest {

private Object vertex1, vertex2, vertex3,
vertex4, vertex5, vertex6,
vertex7, vertex8;

@Before
public void setup() {
vertex1 = "vertex1";
vertex2 = "vertex2";
vertex3 = "vertex3";
vertex4 = "vertex4";
vertex5 = "vertex5";
vertex6 = "vertex6";
vertex7 = "vertex7";
vertex8 = "vertex8";
}

@Test
public void shouldConvertElementSeedsToVertices() throws OperationException {
// Given
final Object vertex1 = "vertex1";
final Object vertex2 = "vertex2";

final List elementIds = Arrays.asList(new EntitySeed(vertex1), new EntitySeed(vertex2));

final ToVerticesHandler handler = new ToVerticesHandler();
Expand All @@ -66,9 +81,6 @@ public void shouldConvertElementSeedsToVertices() throws OperationException {
@Test
public void shouldBeAbleToIterableOverTheResultsMultipleTimes() throws OperationException {
// Given
final Object vertex1 = "vertex1";
final Object vertex2 = "vertex2";

final List elementIds = Arrays.asList(new EntitySeed(vertex1), new EntitySeed(vertex2));

final ToVerticesHandler handler = new ToVerticesHandler();
Expand All @@ -90,15 +102,6 @@ public void shouldBeAbleToIterableOverTheResultsMultipleTimes() throws Operation
@Test
public void shouldConvertEdgeSeedsToVertices_matchedVertexEqual() throws OperationException {
// Given
final Object vertex1 = "vertex1";
final Object vertex2 = "vertex2";
final Object vertex3 = "vertex3";
final Object vertex4 = "vertex4";
final Object vertex5 = "vertex5";
final Object vertex6 = "vertex6";
final Object vertex7 = "vertex7";
final Object vertex8 = "vertex8";

final List elementIds = Arrays.asList(
new EdgeSeed(vertex1, vertex2, false, EdgeId.MatchedVertex.SOURCE),
new EdgeSeed(vertex3, vertex4, false, EdgeId.MatchedVertex.DESTINATION),
Expand All @@ -123,15 +126,6 @@ public void shouldConvertEdgeSeedsToVertices_matchedVertexEqual() throws Operati
@Test
public void shouldConvertEdgeSeedsToVertices_matchedVertexOpposite() throws OperationException {
// Given
final Object vertex1 = "vertex1";
final Object vertex2 = "vertex2";
final Object vertex3 = "vertex3";
final Object vertex4 = "vertex4";
final Object vertex5 = "vertex5";
final Object vertex6 = "vertex6";
final Object vertex7 = "vertex7";
final Object vertex8 = "vertex8";

final List elementIds = Arrays.asList(
new EdgeSeed(vertex1, vertex2, false, EdgeId.MatchedVertex.SOURCE),
new EdgeSeed(vertex3, vertex4, false, EdgeId.MatchedVertex.DESTINATION),
Expand All @@ -156,10 +150,6 @@ public void shouldConvertEdgeSeedsToVertices_matchedVertexOpposite() throws Oper
@Test
public void shouldConvertEdgeSeedsToVertices_sourceAndDestination() throws OperationException {
// Given
final Object vertex1 = "vertex1";
final Object vertex2 = "vertex2";
final Object vertex3 = "vertex3";

final List elementIds = Arrays.asList(new EdgeSeed(vertex1, vertex2, false), new EdgeSeed(vertex1, vertex3, false));

final ToVerticesHandler handler = new ToVerticesHandler();
Expand All @@ -178,9 +168,6 @@ public void shouldConvertEdgeSeedsToVertices_sourceAndDestination() throws Opera
@Test
public void shouldConvertEdgeSeedsToVertices_sourceOnly() throws OperationException {
// Given
final Object vertex1 = "vertex1";
final Object vertex2 = "vertex2";

final List elementIds = Collections.singletonList(new EdgeSeed(vertex1, vertex2, false));
final ToVerticesHandler handler = new ToVerticesHandler();
final ToVertices operation = mock(ToVertices.class);
Expand All @@ -198,9 +185,6 @@ public void shouldConvertEdgeSeedsToVertices_sourceOnly() throws OperationExcept
@Test
public void shouldConvertEdgeSeedsToVertices_destinationOnly() throws OperationException {
// Given
final Object vertex1 = "vertex1";
final Object vertex2 = "vertex2";

final List elementIds = Collections.singletonList(new EdgeSeed(vertex1, vertex2, false));

final ToVerticesHandler handler = new ToVerticesHandler();
Expand All @@ -216,6 +200,72 @@ public void shouldConvertEdgeSeedsToVertices_destinationOnly() throws OperationE
assertThat(Sets.newHashSet(results), containsInAnyOrder(vertex2));
}

@Test
public void shouldCorrectlyConvertEdgeSeedsWithEqualUseMatchedVertex() 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.EQUAL);

// When
final Iterable<Object> results = handler.doOperation(operation, new Context(), null);

// Then
assertThat(Sets.newHashSet(results), containsInAnyOrder(vertex1, vertex3, vertex5, vertex7));
}

@Test
public void shouldCorrectlyConvertEdgeSeedsWithOppositeUseMatchedVertex() 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.OPPOSITE);

// When
final Iterable<Object> results = handler.doOperation(operation, new Context(), null);

// Then
assertThat(Sets.newHashSet(results), containsInAnyOrder(vertex2, vertex4, vertex6, vertex8));
}

@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), is(empty()));
}

@Test
public void shouldHandleNullInput() throws OperationException {
// Given
Expand Down

0 comments on commit d695335

Please sign in to comment.