Search in sources :

Example 1 with Builder

use of uk.gov.gchq.gaffer.named.operation.NamedOperation.Builder 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 2 with Builder

use of uk.gov.gchq.gaffer.named.operation.NamedOperation.Builder 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)

Aggregations

HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Test (org.junit.jupiter.api.Test)2 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)2 Builder (uk.gov.gchq.gaffer.named.operation.NamedOperation.Builder)2 Operation (uk.gov.gchq.gaffer.operation.Operation)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)2 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)2 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)2 NamedOperationScoreResolver (uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver)2