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);
}
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);
}
Aggregations