Search in sources :

Example 46 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.

the class OperationChainTest method shouldBuildOperationChainWithTypeUnsafe.

@Test
public void shouldBuildOperationChainWithTypeUnsafe() {
    // When
    final GetAdjacentIds getAdjIds1 = new GetAdjacentIds();
    final ExportToSet<CloseableIterable<? extends EntityId>> exportToSet1 = new ExportToSet<>();
    final DiscardOutput discardOutput1 = new DiscardOutput();
    final GetSetExport getSetExport1 = new GetSetExport();
    final GetAdjacentIds getAdjIds2 = new GetAdjacentIds();
    final ExportToSet<CloseableIterable<? extends EntityId>> exportToSet2 = new ExportToSet<>();
    final DiscardOutput discardOutput2 = new DiscardOutput();
    final GetSetExport getSetExport2 = new GetSetExport();
    final OperationChain<CloseableIterable<? extends EntityId>> opChain = new Builder().first(getAdjIds1).then(exportToSet1).then(discardOutput1).then(getSetExport1).thenTypeUnsafe(// we can use the type unsafe here as we know the output from the set export will be an Iterable of EntityIds
    getAdjIds2).then(exportToSet2).then(discardOutput2).then(getSetExport2).buildTypeUnsafe();
    // Then
    final Operation[] expecteds = { getAdjIds1, exportToSet1, discardOutput1, getSetExport1, getAdjIds2, exportToSet2, discardOutput2, getSetExport2 };
    assertArrayEquals(expecteds, opChain.getOperationArray());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) GetSetExport(uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport) Test(org.junit.jupiter.api.Test)

Example 47 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.

the class OperationChainTest method shouldConvertToOverviewString.

@Test
public void shouldConvertToOverviewString() {
    // Given
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("vertex1")).build()).then(new Limit<>(1)).build();
    // When
    final String overview = opChain.toOverviewString();
    // Then
    assertEquals("OperationChain[GetAdjacentIds->Limit]", overview);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 48 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.

the class OperationChainTest method shouldBuildOperationChain.

@Test
public void shouldBuildOperationChain() {
    // Given
    final AddElements addElements1 = mock(AddElements.class);
    final AddElements addElements2 = mock(AddElements.class);
    final GetAdjacentIds getAdj1 = mock(GetAdjacentIds.class);
    final GetAdjacentIds getAdj2 = mock(GetAdjacentIds.class);
    final GetAdjacentIds getAdj3 = mock(GetAdjacentIds.class);
    final GetElements getElements1 = mock(GetElements.class);
    final GetElements getElements2 = mock(GetElements.class);
    final GetAllElements getAllElements = mock(GetAllElements.class);
    final DiscardOutput discardOutput = mock(DiscardOutput.class);
    final GetJobDetails getJobDetails = mock(GetJobDetails.class);
    final GenerateObjects<EntityId> generateEntitySeeds = mock(GenerateObjects.class);
    final Limit<Element> limit = mock(Limit.class);
    final ToSet<Element> deduplicate = mock(ToSet.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final ExportToSet<GroupCounts> exportToSet = mock(ExportToSet.class);
    final ExportToGafferResultCache<CloseableIterable<? extends Element>> exportToGafferCache = mock(ExportToGafferResultCache.class);
    final If<Iterable<? extends EntityId>, Iterable<? extends EntityId>> ifOp = mock(If.class);
    // When
    final OperationChain<JobDetail> opChain = new Builder().first(addElements1).then(getAdj1).then(getAdj2).then(getElements1).then(generateEntitySeeds).then(getAdj3).then(ifOp).then(getElements2).then(deduplicate).then(limit).then(countGroups).then(exportToSet).then(discardOutput).then(getAllElements).then(exportToGafferCache).then(addElements2).then(getJobDetails).build();
    // Then
    final Operation[] expecteds = { addElements1, getAdj1, getAdj2, getElements1, generateEntitySeeds, getAdj3, ifOp, getElements2, deduplicate, limit, countGroups, exportToSet, discardOutput, getAllElements, exportToGafferCache, addElements2, getJobDetails };
    assertArrayEquals(expecteds, opChain.getOperationArray());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.jupiter.api.Test)

Example 49 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.

the class OperationChainTest method shouldBuildOperationChainWithSingleOperation.

@Test
public void shouldBuildOperationChainWithSingleOperation() {
    // Given
    final GetAdjacentIds getAdjacentIds = mock(GetAdjacentIds.class);
    // When
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).build();
    // Then
    assertEquals(1, opChain.getOperations().size());
    assertSame(getAdjacentIds, opChain.getOperations().get(0));
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) Test(org.junit.jupiter.api.Test)

Example 50 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.

the class GetAdjacentIdsIT method shouldGetEntityIds.

private void shouldGetEntityIds(final List<String> expectedResultSeeds, final IncludeIncomingOutgoingType inOutType, final DirectedType directedType) throws OperationException {
    // Given
    final User user = new User();
    final List<EntityId> seeds = new ArrayList<>();
    for (final String seed : SEEDS) {
        seeds.add(new EntitySeed(seed));
    }
    final GetAdjacentIds operation = new GetAdjacentIds.Builder().input(seeds).directedType(directedType).inOutType(inOutType).build();
    // When
    final CloseableIterable<? extends EntityId> results = graph.execute(operation, user);
    // Then
    List<String> resultSeeds = new ArrayList<>();
    for (final EntityId result : results) {
        resultSeeds.add((String) result.getVertex());
    }
    Collections.sort(resultSeeds);
    Collections.sort(expectedResultSeeds);
    assertThat(resultSeeds.toArray()).as("InOut=" + inOutType + ", directedType=" + directedType + ".\nExpected: \n  " + StringUtils.join(expectedResultSeeds, "\n  ") + " \nbut got: \n  " + StringUtils.join(resultSeeds, "\n  ")).containsExactly(expectedResultSeeds.toArray());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) ArrayList(java.util.ArrayList) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Aggregations

GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)57 Test (org.junit.jupiter.api.Test)53 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)32 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)32 User (uk.gov.gchq.gaffer.user.User)32 Context (uk.gov.gchq.gaffer.store.Context)25 Operation (uk.gov.gchq.gaffer.operation.Operation)20 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)19 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)13 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)12 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)12 HashSet (java.util.HashSet)11 LinkedHashMap (java.util.LinkedHashMap)11 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)11 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)9 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)9 Graph (uk.gov.gchq.gaffer.graph.Graph)8 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)8 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)7 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)6