Search in sources :

Example 1 with ForEach

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

the class ForEachHandlerTest method shouldThrowExceptionWithNullOperation.

@Test
public void shouldThrowExceptionWithNullOperation() {
    // Given
    final Store store = mock(Store.class);
    final Context context = new Context(new User());
    final ForEach op = new ForEach.Builder<>().operation(null).input(Arrays.asList("1", "2")).build();
    final ForEachHandler handler = new ForEachHandler();
    // When / Then
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(op, context, store)).withMessage("Operation cannot be null");
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) Test(org.junit.jupiter.api.Test)

Example 2 with ForEach

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

the class ForEachHandlerTest method shouldThrowExceptionWithNullInput.

@Test
public void shouldThrowExceptionWithNullInput() {
    // Given
    final Store store = mock(Store.class);
    final Context context = new Context(new User());
    final ForEach op = new ForEach.Builder<>().operation(new GetElements()).build();
    final ForEachHandler handler = new ForEachHandler();
    // When / Then
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(op, context, store)).withMessage("Inputs cannot be null");
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) Test(org.junit.jupiter.api.Test)

Example 3 with ForEach

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

the class ForEachHandlerTest method shouldExecuteAndReturnExpected.

@Test
public void shouldExecuteAndReturnExpected() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    final Context context = new Context(new User());
    final InputOutput op = mock(InputOutput.class);
    final InputOutput opClone = mock(InputOutput.class);
    given(op.shallowClone()).willReturn(opClone);
    final Object input = mock(Object.class);
    final Object output = mock(Object.class);
    final ForEach forEach = new ForEach.Builder<>().input(input).operation(op).build();
    final ForEachHandler handler = new ForEachHandler();
    given(store.execute(opClone, context)).willReturn(output);
    // When
    final List<Object> result = (List<Object>) handler.doOperation(forEach, context, store);
    // Then
    verify(opClone).setInput(input);
    assertThat(result).hasSize(1);
    assertSame(output, result.get(0));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) InputOutput(uk.gov.gchq.gaffer.operation.io.InputOutput) Store(uk.gov.gchq.gaffer.store.Store) List(java.util.List) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) Test(org.junit.jupiter.api.Test)

Example 4 with ForEach

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

the class GetWalksIT method shouldGetPathsWithEntities.

@Test
public void shouldGetPathsWithEntities() throws Exception {
    // Given
    final GetElements getEntities = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
    final GetElements getElements = new GetElements.Builder().directedType(DirectedType.DIRECTED).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build()).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(getElements, getElements, getEntities).build();
    // When
    final List<Walk> results = Lists.newArrayList(graph.execute(op, getUser()));
    // Then
    assertThat(getPaths(results)).isEqualTo("AED,ABC");
    results.forEach(r -> r.getEntities().forEach(l -> {
        assertThat(l).isNotEmpty();
    }));
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Edge(uk.gov.gchq.gaffer.data.element.Edge) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) Predicate(java.util.function.Predicate) TestPropertyNames(uk.gov.gchq.gaffer.commonutil.TestPropertyNames) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) AgeOff(uk.gov.gchq.koryphe.impl.predicate.AgeOff) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) HashMap(java.util.HashMap) HashSet(java.util.HashSet) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Lists(com.google.common.collect.Lists) While(uk.gov.gchq.gaffer.operation.impl.While) Map(uk.gov.gchq.gaffer.operation.impl.Map) Max(uk.gov.gchq.koryphe.impl.binaryoperator.Max) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Sum(uk.gov.gchq.koryphe.impl.binaryoperator.Sum) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) Walk(uk.gov.gchq.gaffer.data.graph.Walk) AddOperationsToChain(uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) CollectionContains(uk.gov.gchq.koryphe.impl.predicate.CollectionContains) Test(org.junit.Test) Entity(uk.gov.gchq.gaffer.data.element.Entity) KorypheFunction(uk.gov.gchq.koryphe.function.KorypheFunction) IterableConcat(uk.gov.gchq.koryphe.impl.function.IterableConcat) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) ExtractWalkEntities(uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntities) AbstractStoreIT(uk.gov.gchq.gaffer.integration.AbstractStoreIT) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement) Operation(uk.gov.gchq.gaffer.operation.Operation) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) TestTypes(uk.gov.gchq.gaffer.store.TestTypes) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) SeededGraphFilters(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 5 with ForEach

use of uk.gov.gchq.gaffer.operation.impl.ForEach 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);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) Test(org.junit.Test)

Aggregations

ForEach (uk.gov.gchq.gaffer.operation.impl.ForEach)8 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)5 Test (org.junit.Test)4 List (java.util.List)3 Test (org.junit.jupiter.api.Test)3 Element (uk.gov.gchq.gaffer.data.element.Element)3 Context (uk.gov.gchq.gaffer.store.Context)3 Store (uk.gov.gchq.gaffer.store.Store)3 User (uk.gov.gchq.gaffer.user.User)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)2 CsvGenerator (uk.gov.gchq.gaffer.data.generator.CsvGenerator)2 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)2 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)2 ToCsv (uk.gov.gchq.gaffer.operation.impl.output.ToCsv)2 ToEntitySeeds (uk.gov.gchq.gaffer.operation.impl.output.ToEntitySeeds)2 ToSingletonList (uk.gov.gchq.gaffer.operation.impl.output.ToSingletonList)2 Lists (com.google.common.collect.Lists)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1