use of uk.gov.gchq.gaffer.store.operation.resolver.DefaultScoreResolver in project Gaffer by gchq.
the class NamedOperationScoreResolverTest method shouldGetScoreFromOperationsInParameters.
@Test
public void shouldGetScoreFromOperationsInParameters() throws CacheOperationFailedException {
// Given
final Integer expectedScore = 8;
final String opName = "otherOp";
final NamedOperation<Element, Iterable<? extends Element>> namedOp = mock(NamedOperation.class);
namedOp.setOperationName(opName);
Operation operation = new GetAllElements();
Map<String, Object> paramMap = Maps.newHashMap();
paramMap.put("test param", operation);
namedOp.setParameters(paramMap);
final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(GetAllElements.class, 3);
final ScoreResolver scoreResolver = new DefaultScoreResolver(opScores);
final NamedOperationDetail namedOpDetail = mock(NamedOperationDetail.class);
final NamedOperationCache cache = mock(NamedOperationCache.class);
final NamedOperationScoreResolver resolver = new NamedOperationScoreResolver(cache);
given(cache.getFromCache(namedOpDetail.getOperationName())).willReturn(namedOpDetail);
given(namedOpDetail.getOperationName()).willReturn(opName);
given(namedOpDetail.getScore()).willReturn(5);
final List<Operation> operations = new ArrayList<>();
operations.add(operation);
given(namedOp.getOperations()).willReturn(operations);
// When
final Integer result = resolver.getScore(namedOp, scoreResolver);
// Then
assertEquals(expectedScore, result);
}
use of uk.gov.gchq.gaffer.store.operation.resolver.DefaultScoreResolver in project Gaffer by gchq.
the class NamedOperationScoreResolverTest method shouldDefaultScoreFromOpChainIfNamedOpScoreEmpty.
@Test
public void shouldDefaultScoreFromOpChainIfNamedOpScoreEmpty() throws CacheOperationFailedException {
// Given
final String namedOpName = "namedOp";
final Map parametersMap = new HashMap<>();
final Integer expectedScore = 7;
final NamedOperation<Element, Iterable<? extends Element>> namedOp = mock(NamedOperation.class);
final NamedOperationCache cache = mock(NamedOperationCache.class);
final ScoreResolver defaultScoreResolver = mock(DefaultScoreResolver.class);
final NamedOperationDetail namedOpDetail = mock(NamedOperationDetail.class);
final NamedOperationScoreResolver resolver = new NamedOperationScoreResolver(cache);
final OperationChain opChain = new OperationChain();
namedOp.setOperationName(namedOpName);
namedOp.setParameters(parametersMap);
given(namedOpDetail.getOperationChain(parametersMap)).willReturn(opChain);
given(namedOpDetail.getScore()).willReturn(null);
given(cache.getFromCache(namedOpDetail.getOperationName())).willReturn(namedOpDetail);
given(defaultScoreResolver.getScore(opChain)).willReturn(7);
// When
final Integer result = resolver.getScore(namedOp, defaultScoreResolver);
// Then
assertEquals(expectedScore, result);
}
use of uk.gov.gchq.gaffer.store.operation.resolver.DefaultScoreResolver in project Gaffer by gchq.
the class ScoreOperationChainHandlerTest method shouldReAddDefaultScoreResolversWhenCallingSetMethod.
@Test
public void shouldReAddDefaultScoreResolversWhenCallingSetMethod() {
// Given
final ScoreOperationChainHandler handler = new ScoreOperationChainHandler();
final Map<Class<? extends Operation>, ScoreResolver> defaultResolvers = ScoreOperationChainHandler.getDefaultScoreResolvers();
final Map<Class<? extends Operation>, ScoreResolver> expectedMap = new HashMap<>();
expectedMap.putAll(defaultResolvers);
final Map<Class<? extends Operation>, ScoreResolver> inputMap = new HashMap<>();
inputMap.put(GetElements.class, new DefaultScoreResolver(null));
inputMap.put(GetAllElements.class, new DefaultScoreResolver(null));
expectedMap.putAll(inputMap);
// When
handler.setScoreResolvers(inputMap);
final Map<Class<? extends Operation>, ScoreResolver> results = handler.getScoreResolvers();
// Then
assertEquals(expectedMap.keySet(), results.keySet());
assertTrue(results.get(NamedOperation.class) instanceof NamedOperationScoreResolver);
assertTrue(results.get(If.class) instanceof IfScoreResolver);
assertEquals(expectedMap.size(), results.size());
}
Aggregations