Search in sources :

Example 1 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds 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);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) 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 2 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds 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 GetAdjacentIds

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

the class DefaultScoreResolverTest method shouldGetScoreForNestedOperations.

@Test
public void shouldGetScoreForNestedOperations() {
    // Given
    final GetElements getElements = mock(GetElements.class);
    final GetWalks getWalks = mock(GetWalks.class);
    final GetAdjacentIds getAdjacentIds = mock(GetAdjacentIds.class);
    given(getWalks.getOperations()).willReturn(Collections.singletonList(new OperationChain<>(getAdjacentIds, getAdjacentIds)));
    final Limit limit = mock(Limit.class);
    final List<Operation> opList = Arrays.asList(getElements, getWalks, limit);
    final OperationChain opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(opList);
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(GetElements.class, 2);
    opScores.put(GetAdjacentIds.class, 2);
    opScores.put(Limit.class, 1);
    final DefaultScoreResolver resolver = new DefaultScoreResolver(opScores);
    // When
    final int score = resolver.getScore(opChain);
    // Then
    assertEquals(7, score);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 4 with GetAdjacentIds

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

the class GetAdjacentIdsHandlerTest method shouldDoNothingIfNoSeedsProvided.

@Test
public void shouldDoNothingIfNoSeedsProvided() throws OperationException {
    // Given
    final GetAdjacentIdsHandler handler = new GetAdjacentIdsHandler();
    final GetAdjacentIds getAdjacentIds = new GetAdjacentIds();
    final Context context = mock(Context.class);
    final HBaseStore store = mock(HBaseStore.class);
    // When
    final CloseableIterable<? extends EntityId> result = handler.doOperation(getAdjacentIds, context, store);
    // Then
    assertEquals(0, Iterables.size(result));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) Test(org.junit.jupiter.api.Test)

Example 5 with GetAdjacentIds

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

the class OperationChainTest method shouldBuildOperationChain_AdjEntitySeedsThenElements.

@Test
public void shouldBuildOperationChain_AdjEntitySeedsThenElements() {
    // Given
    final GetAdjacentIds getAdjacentIds = mock(GetAdjacentIds.class);
    final GetElements getEdges = mock(GetElements.class);
    // When
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getEdges).build();
    // Then
    assertEquals(2, opChain.getOperations().size());
    assertSame(getAdjacentIds, opChain.getOperations().get(0));
    assertSame(getEdges, opChain.getOperations().get(1));
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.jupiter.api.Test)

Aggregations

GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)57 Test (org.junit.jupiter.api.Test)53 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)32 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)32 User (uk.gov.gchq.gaffer.user.User)32 Context (uk.gov.gchq.gaffer.store.Context)25 Operation (uk.gov.gchq.gaffer.operation.Operation)20 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)19 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)13 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)12 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)12 HashSet (java.util.HashSet)11 LinkedHashMap (java.util.LinkedHashMap)11 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)11 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)9 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)9 Graph (uk.gov.gchq.gaffer.graph.Graph)8 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)8 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)7 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)6