Search in sources :

Example 31 with GetAdjacentIds

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

the class DefaultScoreResolverTest method shouldGetScoreForOperationChainContainingNamedOperation.

@Test
public void shouldGetScoreForOperationChainContainingNamedOperation() throws OperationException {
    // Given
    final ScoreResolver mockResolver = mock(NamedOperationScoreResolver.class);
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(GetAdjacentIds.class, 2);
    opScores.put(GetElements.class, 3);
    opScores.put(Limit.class, 4);
    final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
    final String opName = "basicOp";
    final NamedOperation<Object, Object> namedOp = new Builder<>().name(opName).build();
    resolvers.put(NamedOperation.class, mockResolver);
    given(mockResolver.getScore(eq(namedOp), any())).willReturn(5);
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetElements()).then(new Limit()).then(new GetWalks.Builder().addOperations(namedOp, new GetElements()).build()).build();
    final DefaultScoreResolver scoreResolver = new DefaultScoreResolver(opScores, resolvers);
    // When
    final Object result = scoreResolver.getScore(opChain);
    // Then
    assertEquals(17, result);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Builder(uk.gov.gchq.gaffer.named.operation.NamedOperation.Builder) 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) NamedOperationScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 32 with GetAdjacentIds

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

the class DefaultScoreResolverTest method shouldGetDefaultScoreWhenNoOperationScores.

@Test
public void shouldGetDefaultScoreWhenNoOperationScores() throws OperationException {
    // Given
    final DefaultScoreResolver resolver = new DefaultScoreResolver(new LinkedHashMap<>());
    final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
    // When
    final int score = resolver.getScore(op1);
    // Then
    assertEquals(1, score);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Test(org.junit.jupiter.api.Test)

Example 33 with GetAdjacentIds

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

the class DefaultScoreResolverTest method shouldPreventInfiniteRecusion.

@Test
public void shouldPreventInfiniteRecusion() throws OperationException {
    // Given
    final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
    resolvers.put(GetElements.class, new ScoreResolver() {

        @Override
        public Integer getScore(final Operation operation) {
            throw new IllegalArgumentException("defaultResolver is required");
        }

        @Override
        public Integer getScore(final Operation operation, final ScoreResolver defaultScoreResolver) {
            // infinite loop
            return defaultScoreResolver.getScore(operation);
        }
    });
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetElements()).build();
    final DefaultScoreResolver scoreResolver = new DefaultScoreResolver(null, resolvers);
    // When
    final Object result = scoreResolver.getScore(opChain);
    // Then
    assertEquals(2, result);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) NamedOperationScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.jupiter.api.Test)

Example 34 with GetAdjacentIds

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

the class DefaultScoreResolverTest method shouldGetScoreForOperationChainWhenNamedOperationScoreIsNull.

@Test
public void shouldGetScoreForOperationChainWhenNamedOperationScoreIsNull() throws OperationException {
    // Given
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(GetAdjacentIds.class, 2);
    opScores.put(GetElements.class, 1);
    opScores.put(Limit.class, 1);
    final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
    final String opName = "basicOp";
    final NamedOperation<Object, Object> namedOp = new Builder<>().name(opName).build();
    final ScoreResolver mockResolver = mock(NamedOperationScoreResolver.class);
    resolvers.put(NamedOperation.class, mockResolver);
    given(mockResolver.getScore(eq(namedOp), any())).willReturn(null);
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetElements()).then(new Limit()).then(namedOp).build();
    final DefaultScoreResolver scoreResolver = new DefaultScoreResolver(opScores, resolvers);
    // When
    final Object result = scoreResolver.getScore(opChain);
    // Then
    assertEquals(5, result);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Builder(uk.gov.gchq.gaffer.named.operation.NamedOperation.Builder) 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) NamedOperationScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 35 with GetAdjacentIds

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

the class DefaultScoreResolverTest method shouldGetScore.

@Test
public void shouldGetScore() {
    // Given
    final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(GetAdjacentIds.class, 2);
    opScores.put(GetElements.class, 1);
    opScores.put(Limit.class, 1);
    final DefaultScoreResolver resolver = new DefaultScoreResolver(opScores);
    // When
    final int score = resolver.getScore(op1);
    // Then
    assertEquals(2, score);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) 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