use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class GetElementsTest method shouldSetSeedMatchingTypeToRelated.
@Test
public void shouldSetSeedMatchingTypeToRelated() {
final ElementId elementId1 = new EntitySeed("identifier");
final ElementId elementId2 = new EdgeSeed("source2", "destination2", true);
// When
final GetElements op = new GetElements.Builder().input(elementId1, elementId2).seedMatching(SeedMatchingType.RELATED).build();
// Then
assertEquals(SeedMatchingType.RELATED, op.getSeedMatching());
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class OperationUtilTest method shouldConvertObjectArrayToElementIds.
@Test
public void shouldConvertObjectArrayToElementIds() {
// Given
final Object[] input = { 1, "2", new EntitySeed("3"), new Entity("group", "4"), new EdgeSeed("5", 6), new Edge("group", 7L, 8, true), null };
// When
final Iterable<? extends ElementId> output = OperationUtil.toElementIds(input);
// Then
final ArrayList<ElementId> expected = Lists.newArrayList(new EntitySeed(1), new EntitySeed("2"), new EntitySeed("3"), new Entity("group", "4"), new EdgeSeed("5", 6), new Edge("group", 7L, 8, true), null);
assertEquals(expected, Lists.newArrayList(output));
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class ForEachIT method shouldReturnEmptyIterableWithOperationThatDoesntImplementOutput.
@Test
public void shouldReturnEmptyIterableWithOperationThatDoesntImplementOutput() throws OperationException {
// Given
final ForEach<ElementSeed, Element> op = new ForEach.Builder<ElementSeed, Element>().operation(new DiscardOutput.Builder().build()).input(Collections.singletonList(new EdgeSeed(SOURCE_DIR_1, DEST_DIR_1, true))).build();
// When
final Iterable<? extends Element> results = graph.execute(op, getUser());
// Then
ElementUtil.assertElementEquals(Sets.newHashSet((ElementId) null), results);
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class GetElementsIT method shouldGetElements.
private void shouldGetElements(final Collection<Element> expectedElements, final SeedMatchingType seedMatching, final DirectedType directedType, final boolean includeEntities, final boolean includeEdges, final IncludeIncomingOutgoingType inOutType, final Iterable<ElementId> seeds) throws IOException, OperationException {
// Given
final User user = new User();
final View.Builder viewBuilder = new View.Builder();
if (includeEntities) {
viewBuilder.entity(TestGroups.ENTITY);
}
if (includeEdges) {
viewBuilder.edge(TestGroups.EDGE);
}
final GetElements opSeed = new GetElements.Builder().input(seeds).directedType(directedType).inOutType(inOutType).view(viewBuilder.build()).seedMatching(seedMatching).build();
Collection<ElementId> seedCollection = StreamSupport.stream(seeds.spliterator(), false).collect(Collectors.toList());
final GetElements opElement = new GetElements.Builder().input(getElements(seedCollection, null)).directedType(directedType).inOutType(inOutType).view(viewBuilder.build()).seedMatching(seedMatching).build();
// When
final CloseableIterable<? extends Element> resultsSeed = graph.execute(opSeed, user);
final CloseableIterable<? extends Element> resultsElement = graph.execute(opElement, user);
// Then
ElementUtil.assertElementEquals(expectedElements, resultsSeed, true);
ElementUtil.assertElementEquals(expectedElements, resultsElement, true);
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class GetElementsIT method getElements.
private static Collection<Element> getElements(final Collection<ElementId> seeds, final Boolean direction) {
final Set<Element> elements = new HashSet<>(seeds.size());
for (final ElementId seed : seeds) {
if (seed instanceof EntityId) {
final Entity entity = new Entity(TestGroups.ENTITY, ((EntityId) seed).getVertex());
entity.putProperty(TestPropertyNames.COUNT, 1L);
entity.putProperty(TestPropertyNames.SET, CollectionUtil.treeSet("3"));
elements.add(entity);
} else {
if (DirectedType.isEither(((EdgeId) seed).getDirectedType())) {
if (BooleanUtils.isNotTrue(direction)) {
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source(((EdgeId) seed).getSource()).dest(((EdgeId) seed).getDestination()).matchedVertex(((EdgeId) seed).getMatchedVertex()).directed(false).property(TestPropertyNames.INT, 1).property(TestPropertyNames.COUNT, 1L).build();
elements.add(edge);
}
if (BooleanUtils.isNotFalse(direction)) {
final Edge edgeDir = new Edge.Builder().group(TestGroups.EDGE).source(((EdgeId) seed).getSource()).dest(((EdgeId) seed).getDestination()).matchedVertex(((EdgeId) seed).getMatchedVertex()).directed(true).property(TestPropertyNames.INT, 1).property(TestPropertyNames.COUNT, 1L).build();
elements.add(edgeDir);
}
} else {
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source(((EdgeId) seed).getSource()).dest(((EdgeId) seed).getDestination()).directed(((EdgeId) seed).isDirected()).matchedVertex(((EdgeId) seed).getMatchedVertex()).property(TestPropertyNames.INT, 1).property(TestPropertyNames.COUNT, 1L).build();
elements.add(edge);
}
}
}
return elements;
}
Aggregations