Search in sources :

Example 1 with ToMap

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();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) ToMap(uk.gov.gchq.gaffer.operation.impl.output.ToMap) Test(org.junit.jupiter.api.Test)

Example 2 with ToMap

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);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) ToMap(uk.gov.gchq.gaffer.operation.impl.output.ToMap) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) ToMap(uk.gov.gchq.gaffer.operation.impl.output.ToMap) LinkedHashMap(java.util.LinkedHashMap) Map(uk.gov.gchq.gaffer.operation.impl.Map) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 3 with ToMap

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) HashMap(java.util.HashMap) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) ToMap(uk.gov.gchq.gaffer.operation.impl.output.ToMap) MapGenerator(uk.gov.gchq.gaffer.data.generator.MapGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 ToMap (uk.gov.gchq.gaffer.operation.impl.output.ToMap)3 Context (uk.gov.gchq.gaffer.store.Context)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)1 Entity (uk.gov.gchq.gaffer.data.element.Entity)1 MapGenerator (uk.gov.gchq.gaffer.data.generator.MapGenerator)1 Operation (uk.gov.gchq.gaffer.operation.Operation)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 If (uk.gov.gchq.gaffer.operation.impl.If)1 Map (uk.gov.gchq.gaffer.operation.impl.Map)1 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)1 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)1 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)1 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)1