use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsWhenNoEdgeIdsProvided.
@Test
public void testGetElementsWhenNoEdgeIdsProvided() 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 EmptyClosableIterable<>()).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 testGetElementsByEntityId.
@Test
public void testGetElementsByEntityId() 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 EntitySeed("A")).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");
} else {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") || edge.getDestination().equals("A");
}
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
// Repeat to ensure iterator can be consumed twice
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsByEntityIdWithViewRestrictedByGroupAndAPostAggregationFilter.
@Test
public void testGetElementsByEntityIdWithViewRestrictedByGroupAndAPostAggregationFilter() 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 EntitySeed("A")).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1, new ViewElementDefinition.Builder().postAggregationFilter(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");
} else {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") || edge.getDestination().equals("A");
}
}).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 testGetElementsByEdgeIdWithViewRestrictedByGroupAndAPostAggregationFilter.
@Test
public void testGetElementsByEdgeIdWithViewRestrictedByGroupAndAPostAggregationFilter() 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().postAggregationFilter(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 AddElementsHandlerTest method shouldAddWithNoGroupByProperties.
@Test
public void shouldAddWithNoGroupByProperties() throws OperationException, StoreException {
// Given
final AddElements addElements = mock(AddElements.class);
given(addElements.getInput()).willReturn((Iterable) Arrays.asList(new Edge("group1")));
final Context context = mock(Context.class);
final MapStore store = new SingleUseMapStore();
store.initialise("graphId1", new Schema(), new MapStoreProperties());
final AddElementsHandler handler = new AddElementsHandler();
// When / Then - should not throw NPE
handler.doOperation(addElements, context, store);
}
Aggregations