use of uk.gov.gchq.gaffer.operation.impl.output.ToMap in project Gaffer by gchq.
the class ToMapHandlerTest method shouldHandleNullInput.
@Test
public void shouldHandleNullInput() throws OperationException {
// Given
final ToMapHandler handler = new ToMapHandler();
final ToMap operation = mock(ToMap.class);
given(operation.getInput()).willReturn(null);
// When
final Iterable<? extends Map<String, Object>> results = handler.doOperation(operation, new Context(), null);
// Then
assertThat(results).isNull();
}
use of uk.gov.gchq.gaffer.operation.impl.output.ToMap 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.output.ToMap in project Gaffer by gchq.
the class ToMapHandlerTest method shouldConvertElementToMap.
@Test
public void shouldConvertElementToMap() throws OperationException {
// Given
final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).vertex(1).build();
final Map<String, Object> originalMap = new HashMap<>(1);
originalMap.put("group", TestGroups.ENTITY);
originalMap.put("vertex", 1);
final MapGenerator generator = new MapGenerator.Builder().group("group").vertex("vertex").source("source").destination("destination").build();
final Iterable originalResults = new WrappedCloseableIterable<>(Collections.singleton(entity));
final ToMapHandler handler = new ToMapHandler();
final ToMap operation = mock(ToMap.class);
given(operation.getInput()).willReturn(originalResults);
given(operation.getElementGenerator()).willReturn(generator);
// When
final Iterable<? extends Map<String, Object>> results = handler.doOperation(operation, new Context(), null);
// Then
assertThat(results).containsExactly(originalMap);
}
Aggregations