use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheTest method shouldReturnSetOfNamedOperationsThatAUserCanExecute.
@Test
public void shouldReturnSetOfNamedOperationsThatAUserCanExecute() throws CacheOperationFailedException {
cache.addNamedOperation(standard, false, standardUser);
NamedOperationDetail alt = new NamedOperationDetail.Builder().operationName("different operation").description("alt").creatorId(advancedUser.getUserId()).readers(readers).writers(writers).operationChain(alternativeOpChain).build();
cache.addNamedOperation(alt, false, advancedUser);
Set<NamedOperationDetail> actual = Sets.newHashSet(cache.getAllNamedOperations(standardUser));
assert actual.contains(standard);
assert actual.contains(alt);
assert actual.size() == 2;
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationResolver method resolveNamedOperation.
private List<Operation> resolveNamedOperation(final NamedOperation namedOp, final User user) {
final NamedOperationDetail namedOpDetail;
try {
namedOpDetail = cache.getNamedOperation(namedOp.getOperationName(), user);
} catch (final CacheOperationFailedException e) {
// Unable to find named operation - just return the original named operation
return Collections.singletonList(namedOp);
}
final OperationChain<?> namedOperationChain = namedOpDetail.getOperationChain(namedOp.getParameters());
updateOperationInput(namedOperationChain, namedOp.getInput());
// Call resolveNamedOperations again to check there are no nested named operations
resolveNamedOperations(namedOperationChain, user);
return namedOperationChain.getOperations();
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationScoreResolverTest method shouldGetScore.
@Test
public void shouldGetScore() throws CacheOperationFailedException {
// Given
final Integer expectedScore = 5;
final String opName = "otherOp";
final NamedOperation<Element, Iterable<? extends Element>> namedOp = mock(NamedOperation.class);
namedOp.setOperationName(opName);
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(expectedScore);
// When
final Integer result = resolver.getScore(namedOp);
// Then
assertEquals(expectedScore, result);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldBeAbleToDeleteNamedOperationFromCache.
private void shouldBeAbleToDeleteNamedOperationFromCache() throws OperationException {
// given
final Store store = mock(Store.class);
given(store.getProperties()).willReturn(properties);
new AddNamedOperationHandler().doOperation(add, context, store);
DeleteNamedOperation del = new DeleteNamedOperation.Builder().name("op").build();
GetAllNamedOperations get = new GetAllNamedOperations();
// when
deleteNamedOperationHandler.doOperation(del, context, store);
List<NamedOperationDetail> results = Lists.newArrayList(getAllNamedOperationsHandler1.doOperation(get, context, store));
// then
assertThat(results).isEmpty();
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationResolverTest method shouldNotExecuteNamedOperationWithParameterOfWrongType.
@Test
public void shouldNotExecuteNamedOperationWithParameterOfWrongType() throws OperationException, CacheOperationFailedException {
// Given
final String opName = "opName";
final NamedOperationCache cache = mock(NamedOperationCache.class);
final NamedOperationResolver resolver = new NamedOperationResolver(cache);
final User user = mock(User.class);
Map<String, Object> paramMap = Maps.newHashMap();
// A parameter of the wrong type
paramMap.put("param1", new ArrayList());
ParameterDetail param = new ParameterDetail.Builder().defaultValue(1L).description("Limit param").valueClass(Long.class).build();
Map<String, ParameterDetail> paramDetailMap = Maps.newHashMap();
paramDetailMap.put("param1", param);
// Make a real NamedOperationDetail with a parameter
final NamedOperationDetail extendedNamedOperation = new NamedOperationDetail.Builder().operationName(opName).description("standard operation").operationChain("{ \"operations\": [ { \"class\":\"uk.gov.gchq.gaffer.operation.impl.get.GetAllElements\" }, { \"class\":\"uk.gov.gchq.gaffer.operation.impl.Limit\", \"resultLimit\": \"${param1}\" } ] }").parameters(paramDetailMap).build();
given(cache.getNamedOperation(opName, user)).willReturn(extendedNamedOperation);
// When
assertThatIllegalArgumentException().isThrownBy(() -> resolver.preExecute(new OperationChain.Builder().first(new NamedOperation.Builder<>().name(opName).parameters(paramMap).build()).build(), new Context(user)));
}
Aggregations