use of uk.gov.gchq.gaffer.operation.util.Conditional 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));
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class WhileScoreResolverTest method shouldGetScoreWithOperationChainAsOperation.
@Test
public void shouldGetScoreWithOperationChainAsOperation() {
// Given
final Object input = new EntitySeed(3);
final int repeats = 3;
final GetElements getElements = mock(GetElements.class);
final Map map = mock(Map.class);
final ToSet toSet = mock(ToSet.class);
final OperationChain transformChain = mock(OperationChain.class);
final List<Operation> transformOps = new LinkedList<>();
transformOps.add(map);
transformOps.add(toSet);
given(transformChain.getOperations()).willReturn(transformOps);
final Conditional conditional = mock(Conditional.class);
given(conditional.getTransform()).willReturn(transformChain);
final While operation = new While.Builder<>().input(input).maxRepeats(repeats).conditional(conditional).operation(getElements).build();
final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(Operation.class, 1);
opScores.put(Map.class, 3);
opScores.put(ToSet.class, 1);
opScores.put(GetElements.class, 2);
final WhileScoreResolver resolver = new WhileScoreResolver();
final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
// When
final int score = resolver.getScore(operation, defaultResolver);
// Then
assertEquals(18, score);
}
use of uk.gov.gchq.gaffer.operation.util.Conditional 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);
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class If method updateOperations.
@Override
public void updateOperations(final Collection<Operation> operations) {
if (null == operations || 3 != operations.size()) {
throw new IllegalArgumentException("Unable to update operations - exactly 3 operations are required. Received " + (null != operations ? operations.size() : 0) + " operations");
}
final Iterator<Operation> itr = operations.iterator();
final Operation transform = extractNextOp(itr);
if (null == conditional) {
if (null != transform) {
conditional = new Conditional();
conditional.setTransform(transform);
}
} else {
conditional.setTransform(transform);
}
then = extractNextOp(itr);
otherwise = extractNextOp(itr);
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class GetWalksIT method shouldFilterWalksUsingWalkPredicateWithoutTransform.
@Test
public void shouldFilterWalksUsingWalkPredicateWithoutTransform() throws Exception {
final Conditional conditional = new Conditional();
conditional.setPredicate(new WalkPredicate());
final Iterable<Walk> walks = executeGetWalksApplyingConditional(conditional);
assertThat(getPaths(walks)).isEqualTo("AED");
}
Aggregations