use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsByEdgeIdWithViewRestrictedByGroupAndAPreAggregationFilter.
@Test
public void testGetElementsByEdgeIdWithViewRestrictedByGroupAndAPreAggregationFilter() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetElements getElements = new GetElements.Builder().input(new EdgeSeed("A", "B0", true)).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new IsMoreThan(5)).build()).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
return ((Entity) element).getVertex().equals("A") || ((Entity) element).getVertex().equals("B0");
} else {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") && edge.getDestination().equals("B0");
}
}).filter(e -> e.getGroup().equals(GetAllElementsHandlerTest.BASIC_EDGE1) && ((int) e.getProperty(GetAllElementsHandlerTest.COUNT)) > 5).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsByEdgeSeedWithViewRestrictedByGroupAndAPostTransformFilter.
@Test
public void testGetElementsByEdgeSeedWithViewRestrictedByGroupAndAPostTransformFilter() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetElements getElements = new GetElements.Builder().input(new EdgeSeed("A", "B0", true)).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1, new ViewElementDefinition.Builder().transformer(new ElementTransformer.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new ExampleTransform()).project(GetAllElementsHandlerTest.COUNT).build()).postTransformFilter(new ElementFilter.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new IsMoreThan(50)).build()).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(e -> e.getGroup().equals(GetAllElementsHandlerTest.BASIC_EDGE1)).filter(element -> {
if (element instanceof Entity) {
return ((Entity) element).getVertex().equals("A") || ((Entity) element).getVertex().equals("B0");
} else {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") && edge.getDestination().equals("B0");
}
}).map(element -> {
element.putProperty(GetAllElementsHandlerTest.COUNT, ((Integer) element.getProperty(GetAllElementsHandlerTest.COUNT)) + ExampleTransform.INCREMENT_BY);
return element;
}).filter(element -> ((Integer) element.getProperty(GetAllElementsHandlerTest.COUNT)) > 50).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsByNonExistentEdgeId.
@Test
public void testGetElementsByNonExistentEdgeId() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetElements getElements = new GetElements.Builder().input(new EdgeSeed("NOT_PRESENT", "ALSO_NOT_PRESENT", true)).build();
final CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
assertEquals(Collections.emptySet(), resultsSet);
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsSeedMatchingTypeOption.
@Test
public void testGetElementsSeedMatchingTypeOption() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When seedMatching is EQUAL
GetElements getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).seedMatching(SeedMatchingType.EQUAL).build();
CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(element -> element instanceof Entity).filter(element -> {
final Entity entity = (Entity) element;
return entity.getVertex().equals("A") || entity.getVertex().equals("X");
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// When seedMatching is RELATED
getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).seedMatching(SeedMatchingType.RELATED).build();
results = graph.execute(getElements, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
final Entity entity = (Entity) element;
return entity.getVertex().equals("A") || entity.getVertex().equals("X");
} else {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("X") || edge.getDestination().equals("X");
}
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// Repeat with seedMatching set to EQUAL for an EdgeId
final GetElements getElementsFromEdgeId = new GetElements.Builder().input(new EdgeSeed("A", "B0", true)).seedMatching(SeedMatchingType.EQUAL).build();
results = graph.execute(getElementsFromEdgeId, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> element instanceof Edge).filter(element -> {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") && edge.getDestination().equals("B0") && edge.isDirected();
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsDirectedTypeOption.
@Test
public void testGetElementsDirectedTypeOption() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When directedType is EITHER
GetElements getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).directedType(DirectedType.EITHER).build();
CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
final Entity entity = (Entity) element;
return entity.getVertex().equals("A") || entity.getVertex().equals("X");
} else {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("X") || edge.getDestination().equals("X");
}
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// When view has no edges
getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
results = graph.execute(getElements, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
final Entity entity = (Entity) element;
return entity.getVertex().equals("A") || entity.getVertex().equals("X");
} else {
return false;
}
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// When directedType is DIRECTED
getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).directedType(DirectedType.DIRECTED).build();
results = graph.execute(getElements, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
final Entity entity = (Entity) element;
return entity.getVertex().equals("A") || entity.getVertex().equals("X");
} else {
final Edge edge = (Edge) element;
return (edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("X") || edge.getDestination().equals("X")) && edge.isDirected();
}
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// When directedType is UNDIRECTED
getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).directedType(DirectedType.UNDIRECTED).build();
results = graph.execute(getElements, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
final Entity entity = (Entity) element;
return entity.getVertex().equals("A") || entity.getVertex().equals("X");
} else {
final Edge edge = (Edge) element;
return (edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("X") || edge.getDestination().equals("X")) && !edge.isDirected();
}
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
Aggregations