use of uk.gov.gchq.gaffer.operation.impl.Map in project Gaffer by gchq.
the class IfScoreResolverTest method shouldGetScoreForNestedOperations.
@Test
public void shouldGetScoreForNestedOperations() {
// Given
final Map map = mock(Map.class);
final Conditional conditional = mock(Conditional.class);
given(conditional.getTransform()).willReturn(map);
final GetWalks getWalks = mock(GetWalks.class);
given(getWalks.getOperations()).willReturn(Collections.singletonList(new OperationChain<>(new GetAdjacentIds(), new GetAdjacentIds())));
final GetAllElements getAllElements = new GetAllElements();
final If operation = new If.Builder<>().conditional(conditional).then(getWalks).otherwise(getAllElements).build();
final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(Operation.class, 1);
opScores.put(Map.class, 3);
opScores.put(GetAdjacentIds.class, 2);
opScores.put(GetAllElements.class, 3);
final IfScoreResolver resolver = new IfScoreResolver();
final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
// When
final int score = resolver.getScore(operation, defaultResolver);
// Then
assertEquals(7, score);
}
use of uk.gov.gchq.gaffer.operation.impl.Map in project Gaffer by gchq.
the class IfScoreResolverTest method shouldGetScoreWithOperationChainAsAnOperation.
@Test
public void shouldGetScoreWithOperationChainAsAnOperation() {
// Given
final GetElements getElements = mock(GetElements.class);
final ToMap toMap = mock(ToMap.class);
final Map map = mock(Map.class);
final OperationChain conditionalChain = mock(OperationChain.class);
final List<Operation> conditionalOps = new LinkedList<>();
conditionalOps.add(getElements);
conditionalOps.add(toMap);
conditionalOps.add(map);
given(conditionalChain.getOperations()).willReturn(conditionalOps);
final Conditional conditional = mock(Conditional.class);
given(conditional.getTransform()).willReturn(conditionalChain);
final GetAdjacentIds getAdjacentIds = mock(GetAdjacentIds.class);
final GetAllElements getAllElements = mock(GetAllElements.class);
final If operation = new If.Builder<>().conditional(conditional).then(getAdjacentIds).otherwise(getAllElements).build();
final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(Operation.class, 1);
opScores.put(GetElements.class, 2);
opScores.put(ToMap.class, 2);
opScores.put(Map.class, 3);
opScores.put(GetAdjacentIds.class, 3);
opScores.put(GetAllElements.class, 4);
final IfScoreResolver resolver = new IfScoreResolver();
final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
// When
final int score = resolver.getScore(operation, defaultResolver);
// Then
assertEquals(11, score);
}
use of uk.gov.gchq.gaffer.operation.impl.Map in project Gaffer by gchq.
the class RowToElementGeneratorTest method getElements.
private List<Element> getElements() {
final List<String> names = Lists.newArrayList("Alice", "Bob", "Charlie", "David");
final List<Element> elements = new ArrayList<>();
final List<Entity> entities = names.stream().map(n -> {
return new Entity.Builder().vertex(n.substring(0, 1).toLowerCase()).group(TestGroups.ENTITY).property("fullname", n).build();
}).collect(Collectors.toList());
final Edge edge1 = new Edge.Builder().source("a").dest("b").directed(true).group(TestGroups.EDGE).property("type", "friend").build();
final Edge edge2 = new Edge.Builder().source("b").dest("c").directed(false).group(TestGroups.EDGE).property("type", "follow").build();
final Edge edge3 = new Edge.Builder().source("a").dest("c").directed(true).group(TestGroups.EDGE).property("type", "follow").build();
final Edge edge4 = new Edge.Builder().source("c").dest("a").directed(true).group(TestGroups.EDGE).property("type", "follow").build();
final Edge edge5 = new Edge.Builder().source("d").dest("c").directed(true).group(TestGroups.EDGE).property("type", "follow").build();
final List<Edge> edges = Lists.newArrayList(edge1, edge2, edge3, edge4, edge5);
elements.addAll(entities);
elements.addAll(edges);
return elements;
}
use of uk.gov.gchq.gaffer.operation.impl.Map in project Gaffer by gchq.
the class MapHandlerTest method shouldBuildWithInvalidArgumentsAndFailExecution.
@Test
public void shouldBuildWithInvalidArgumentsAndFailExecution() throws OperationException {
final List<Function> functions = new ArrayList<>();
final Function<Long, Double> func = Double::longBitsToDouble;
final Function<String, Integer> func1 = Integer::valueOf;
functions.add(new ToString());
functions.add(func);
functions.add(func1);
final Map map = new Map();
map.setInput(3);
map.setFunctions(functions);
final MapHandler handler = new MapHandler();
// When / Then
assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(map, context, store)).withMessage("The input/output types of the functions were incompatible");
}
use of uk.gov.gchq.gaffer.operation.impl.Map in project Gaffer by gchq.
the class MapHandlerTest method shouldMapMultipleObjectsAtOnce.
@Test
public void shouldMapMultipleObjectsAtOnce() throws OperationException {
// Given
final MapHandler<Iterable<Integer>, String> handler = new MapHandler<>();
final Map<Iterable<Integer>, String> operation = new Map.Builder<Iterable<Integer>>().input(Arrays.asList(1, 2)).first(Object::toString).build();
// When
final String result = handler.doOperation(operation, context, store);
// Then
assertNotNull(result);
assertEquals("[1, 2]", result);
}
Aggregations