Search in sources :

Example 16 with GetWalks

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

the class IfHandlerTest method shouldExecuteOtherwiseOperationWhenConditionNotMet.

@Test
public void shouldExecuteOtherwiseOperationWhenConditionNotMet() throws OperationException {
    // Given
    final Object input = Arrays.asList(new EntitySeed("1"), new EntitySeed("2"));
    final Conditional conditional = mock(Conditional.class);
    final Predicate<Object> predicate = mock(Predicate.class);
    final GetWalks then = mock(GetWalks.class);
    final GetElements otherwise = mock(GetElements.class);
    final If filter = new If.Builder<>().input(input).conditional(conditional).then(then).otherwise(otherwise).build();
    final IfHandler handler = new IfHandler();
    given(conditional.getPredicate()).willReturn(predicate);
    given(predicate.test(input)).willReturn(false);
    // When
    handler.doOperation(filter, context, store);
    // Then
    verify(predicate).test(input);
    verify(store, never()).execute(then, context);
    verify(store).execute(otherwise, context);
}
Also used : GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 17 with GetWalks

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

the class IfHandlerTest method shouldReturnInitialInputForNullOperations.

@Test
public void shouldReturnInitialInputForNullOperations() throws OperationException {
    // Given
    final Object input = Arrays.asList(new EntitySeed("1"), new EntitySeed("2"));
    final Conditional conditional = mock(Conditional.class);
    final Predicate<Object> predicate = mock(Predicate.class);
    final GetWalks then = null;
    final GetElements otherwise = null;
    final If filter = new If.Builder<>().input(input).conditional(conditional).then(then).otherwise(otherwise).build();
    given(conditional.getPredicate()).willReturn(predicate);
    given(predicate.test(input)).willReturn(true);
    final IfHandler handler = new IfHandler();
    // When
    final Object result = handler.doOperation(filter, context, store);
    // Then
    assertEquals(result, input);
    verify(predicate).test(input);
    verify(store, never()).execute(then, context);
    verify(store, never()).execute(otherwise, context);
}
Also used : GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 18 with GetWalks

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

the class AddOperationsToChainTest method shouldAddIfOperation.

@Test
public void shouldAddIfOperation() throws SerialisationException {
    // Given
    final GetWalks getWalks = new GetWalks();
    final uk.gov.gchq.gaffer.operation.impl.Map map = new uk.gov.gchq.gaffer.operation.impl.Map();
    final ToVertices toVertices = new ToVertices();
    final ToSet toSet = new ToSet();
    final Exists exists = new Exists();
    final Limit limit = new Limit();
    final GetAllElements getAllElements = new GetAllElements();
    final GetElements getElements = new GetElements();
    final Conditional conditional = new Conditional();
    conditional.setPredicate(exists);
    final If ifOp = new If.Builder<>().conditional(conditional).then(getElements).otherwise(getAllElements).build();
    final AddOperationsToChain hook = new AddOperationsToChain();
    final Map<String, List<Operation>> after = new HashMap<>();
    final List<Operation> afterOps = new LinkedList<>();
    afterOps.add(ifOp);
    afterOps.add(limit);
    after.put("uk.gov.gchq.gaffer.operation.impl.output.ToSet", afterOps);
    hook.setAfter(after);
    final OperationChain opChain = new OperationChain.Builder().first(getWalks).then(map).then(toVertices).then(toSet).build();
    // When
    hook.preExecute(opChain, new Context());
    // Then
    final OperationChain expectedOpChain = new OperationChain.Builder().first(getWalks).then(map).then(toVertices).then(toSet).then(ifOp).then(limit).build();
    JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
Also used : HashMap(java.util.HashMap) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Operation(uk.gov.gchq.gaffer.operation.Operation) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) LinkedList(java.util.LinkedList) List(java.util.List) Context(uk.gov.gchq.gaffer.store.Context) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) LinkedList(java.util.LinkedList) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) HashMap(java.util.HashMap) Map(java.util.Map) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 19 with GetWalks

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

the class IfScoreResolverTest method shouldGetScoreWithFullyPopulatedOperation.

@Test
public void shouldGetScoreWithFullyPopulatedOperation() {
    // Given
    final Count count = mock(Count.class);
    final GetAllElements getAllElements = mock(GetAllElements.class);
    final GetWalks getWalks = mock(GetWalks.class);
    final Conditional conditional = mock(Conditional.class);
    given(conditional.getTransform()).willReturn(count);
    final If operation = new If.Builder<>().conditional(conditional).then(getWalks).otherwise(getAllElements).build();
    final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Count.class, 1);
    opScores.put(GetAllElements.class, 3);
    opScores.put(GetWalks.class, 4);
    final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
    final IfScoreResolver resolver = new IfScoreResolver();
    // When
    final int score = resolver.getScore(operation, defaultResolver);
    // Then
    assertEquals(4, score);
}
Also used : GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Count(uk.gov.gchq.gaffer.operation.impl.Count) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 20 with GetWalks

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

the class GetWalksIT method shouldGetPathsWithWhileRepeat.

@Test
public void shouldGetPathsWithWhileRepeat() throws Exception {
    // Given
    final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(new While.Builder<>().operation(operation).maxRepeats(2).build()).build();
    // When
    final Iterable<Walk> results = graph.execute(op, getUser());
    // Then
    assertThat(getPaths(results)).isEqualTo("AED,ABC");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) 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) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) While(uk.gov.gchq.gaffer.operation.impl.While) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Aggregations

GetWalks (uk.gov.gchq.gaffer.operation.impl.GetWalks)31 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)27 Test (org.junit.Test)19 Walk (uk.gov.gchq.gaffer.data.graph.Walk)19 Builder (uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder)19 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)17 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)15 Test (org.junit.jupiter.api.Test)11 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)9 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)8 HashMap (java.util.HashMap)5 Operation (uk.gov.gchq.gaffer.operation.Operation)5 If (uk.gov.gchq.gaffer.operation.impl.If)5 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)5 List (java.util.List)4 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)4 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)4 LinkedHashMap (java.util.LinkedHashMap)3 GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)3 AddOperationsToChain (uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain)3