use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class GetAdjacentIdsTest method shouldPassValidationOnEntitiesWithoutFilters.
@Test
public void shouldPassValidationOnEntitiesWithoutFilters() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(GetAllElementsHandlerTest.getElements()).build();
graph.execute(addElements, new User());
// When
final GetAdjacentIds getAdjacentIds = new GetAdjacentIds.Builder().input(new EntitySeed("A"), new EntitySeed("Y2")).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new IsMoreThan(5)).build()).build()).entity(GetAllElementsHandlerTest.BASIC_ENTITY, new ViewElementDefinition()).build()).build();
final CloseableIterable<? extends EntityId> results = graph.execute(getAdjacentIds, new User());
// Then
final Set<EntityId> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<EntityId> expectedResults = new HashSet<>();
GetAllElementsHandlerTest.getElements().stream().filter(element -> element instanceof Edge).filter(element -> element.getGroup().equals(GetAllElementsHandlerTest.BASIC_EDGE1)).filter(element -> {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("Y2") || edge.getDestination().equals("Y2");
}).filter(element -> ((Integer) element.getProperty(GetAllElementsHandlerTest.COUNT)) > 5).map(element -> {
final Edge edge = (Edge) element;
final Set<EntityId> nodes = new HashSet<>();
nodes.add(new EntitySeed(edge.getSource()));
nodes.add(new EntitySeed(edge.getDestination()));
return nodes;
}).flatMap(nodes -> nodes.stream()).forEach(expectedResults::add);
expectedResults.remove(new EntitySeed("A"));
expectedResults.remove(new EntitySeed("Y2"));
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class GetAdjacentIdsHandlerTest method shouldReturnHBaseRetriever.
@Test
public void shouldReturnHBaseRetriever() throws OperationException, StoreException {
// Given
final Iterable<EntityId> ids = mock(Iterable.class);
final Context context = mock(Context.class);
final User user = mock(User.class);
final HBaseStore store = mock(HBaseStore.class);
final HBaseRetriever<GetElements> hbaseRetriever = mock(HBaseRetriever.class);
final GetAdjacentIdsHandler handler = new GetAdjacentIdsHandler();
final GetAdjacentIds getAdjacentIds = new GetAdjacentIds.Builder().inputIds(ids).option("option1", "optionValue").inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.INCOMING).directedType(DirectedType.DIRECTED).view(new View()).build();
given(context.getUser()).willReturn(user);
final ArgumentCaptor<GetElements> getElementsCaptor = ArgumentCaptor.forClass(GetElements.class);
given(store.createRetriever(getElementsCaptor.capture(), eq(user), eq(ids), eq(true))).willReturn(hbaseRetriever);
// When
final GetAdjacentIdsHandler.ExtractDestinationEntityId result = (GetAdjacentIdsHandler.ExtractDestinationEntityId) handler.doOperation(getAdjacentIds, context, store);
// Then
assertSame(hbaseRetriever, result.getInput());
final GetElements getElements = getElementsCaptor.getValue();
assertSame(ids, getElements.getInput());
assertTrue(getElements.getView().getEntities().isEmpty());
assertEquals(getAdjacentIds.getDirectedType(), getElements.getDirectedType());
assertEquals(getAdjacentIds.getIncludeIncomingOutGoing(), getElements.getIncludeIncomingOutGoing());
assertEquals("optionValue", getElements.getOption("option1"));
}
Aggregations