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