use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class ExamplesService method getAdjacentIds.
@Override
public GetAdjacentIds getAdjacentIds() {
final GetAdjacentIds op = new GetAdjacentIds();
final List<EntityId> seeds = new ArrayList<>();
if (hasEntities()) {
seeds.add(getEntityId(1));
} else if (hasEdges()) {
seeds.add(new EntitySeed(getEdgeId(1, 2).getSource()));
}
op.setInput(seeds);
populateOperation(op);
return op;
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class AbstractExamplesFactoryTest method shouldUseSchemaToCreateGetAdjacentIdsInput.
@Test
public void shouldUseSchemaToCreateGetAdjacentIdsInput() throws InstantiationException, IllegalAccessException {
// Given
TestExamplesFactory examplesFactory = new TestExamplesFactory(SCHEMA);
// When
GetAdjacentIds operation = (GetAdjacentIds) examplesFactory.generateExample(GetAdjacentIds.class);
// Then
int size = 0;
for (ElementId e : operation.getInput()) {
size++;
if (e instanceof EntityId) {
assertEquals(String.class, ((EntityId) e).getVertex().getClass());
} else {
throw new RuntimeException("Expected operation only to contain entity ids");
}
}
assertEquals(1, size);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class FederatedOperationTest method shouldReturnFalseWhenOpChainDoesNotHaveFederatedOps.
@Test
public void shouldReturnFalseWhenOpChainDoesNotHaveFederatedOps() {
// Given
final OperationChain<?> opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetElements()).build();
// When
final boolean result = FederatedOperation.hasFederatedOperations(opChain);
// Then
assertFalse(result);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class AbstractExamplesFactory method getAdjacentIds.
public GetAdjacentIds getAdjacentIds() {
final GetAdjacentIds op = new GetAdjacentIds();
final List<EntityId> seeds = new ArrayList<>();
if (hasEntities()) {
seeds.add(getEntityId(1));
} else if (hasEdges()) {
seeds.add(new EntitySeed(getEdgeId(1, 2).getSource()));
}
op.setInput(seeds);
populateOperation(op);
return op;
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class GetAdjacentIdsTest method shouldGetAdjacentEntityId.
@Test
public void shouldGetAdjacentEntityId() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(GetAllElementsHandlerTest.getElements()).build();
graph.execute(addElements, new User());
// When - query for A
GetAdjacentIds getAdjacentIds = new GetAdjacentIds.Builder().input(new EntitySeed("A")).build();
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 -> {
final Edge edge = (Edge) element;
if (edge.getSource().equals("A") || edge.getDestination().equals("A")) {
return true;
}
return false;
}).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"));
assertEquals(expectedResults, resultsSet);
// Repeat to ensure iterator can be consumed twice
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
assertEquals(expectedResults, resultsSet);
// When - query for A and Y2
getAdjacentIds = new GetAdjacentIds.Builder().input(new EntitySeed("A"), new EntitySeed("Y2")).build();
results = graph.execute(getAdjacentIds, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
GetAllElementsHandlerTest.getElements().stream().filter(element -> element instanceof Edge).filter(element -> {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("Y2") || edge.getDestination().equals("Y2");
}).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);
}
Aggregations