use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class GetAllNamedOperationsHandlerTest method shouldReturnNamedOperationWithInputType.
@Test
public void shouldReturnNamedOperationWithInputType() throws Exception {
// Given
AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().name(expectedOperationDetailWithInputType.getOperationName()).description(expectedOperationDetailWithInputType.getDescription()).operationChain(expectedOperationDetailWithInputType.getOperationChainWithDefaultParams()).build();
addNamedOperationHandler.doOperation(addNamedOperation, context, store);
// When
CloseableIterable<NamedOperationDetail> allNamedOperationsList = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store);
// Then
assertEquals(1, Iterables.size(allNamedOperationsList));
assertTrue(Iterables.contains(allNamedOperationsList, expectedOperationDetailWithInputType));
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class GetAllNamedOperationsHandlerTest method shouldReturnNullLabelWhenLabelIsNullFromAddNamedOperationRequest.
@Test
public void shouldReturnNullLabelWhenLabelIsNullFromAddNamedOperationRequest() throws Exception {
final AddNamedOperation addNamedOperationWithNullLabel = new AddNamedOperation.Builder().name("My Operation With Label").labels(null).operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}").build();
addNamedOperationHandler.doOperation(addNamedOperationWithNullLabel, context, store);
final CloseableIterable<NamedOperationDetail> allNamedOperations = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store);
assertThat(allNamedOperations.iterator().next().getLabels()).isNull();
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class GetAllNamedOperationsHandlerTest method shouldReturnLabelWhenNamedOperationHasLabel.
@Test
public void shouldReturnLabelWhenNamedOperationHasLabel() throws Exception {
final AddNamedOperation addNamedOperationWithLabel = new AddNamedOperation.Builder().name("My Operation With Label").labels(Arrays.asList("test label")).operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}").build();
addNamedOperationHandler.doOperation(addNamedOperationWithLabel, context, store);
final CloseableIterable<NamedOperationDetail> allNamedOperations = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store);
assertEquals(Arrays.asList("test label"), allNamedOperations.iterator().next().getLabels());
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldAddCustomAccessPredicateFieldsToNamedOperationDetailCorrectly.
@Test
public void shouldAddCustomAccessPredicateFieldsToNamedOperationDetailCorrectly() throws OperationException, CacheOperationFailedException {
final AccessPredicate readAccessPredicate = new AccessPredicate(new CustomUserPredicate());
final AccessPredicate writeAccessPredicate = new AccessPredicate(new CustomUserPredicate());
OperationChain opChain = new OperationChain.Builder().first(new AddElements()).build();
addNamedOperation.setOperationChain(opChain);
addNamedOperation.setScore(2);
addNamedOperation.setOperationName("testOp");
addNamedOperation.setLabels(asList("test label"));
addNamedOperation.setReadAccessRoles(null);
addNamedOperation.setReadAccessPredicate(readAccessPredicate);
addNamedOperation.setWriteAccessRoles(null);
addNamedOperation.setWriteAccessPredicate(writeAccessPredicate);
handler.doOperation(addNamedOperation, context, store);
final NamedOperationDetail result = mockCache.getNamedOperation("testOp", new User(), EMPTY_ADMIN_AUTH);
assert cacheContains("testOp");
assertTrue(result.getScore() == 2);
assertEquals(asList("test label"), result.getLabels());
assertEquals(readAccessPredicate, result.getReadAccessPredicate());
assertEquals(writeAccessPredicate, result.getWriteAccessPredicate());
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheTest method shouldThrowExceptionTryingToDeleteOperationConfiguredWithWriteNoAccessPredicate.
@Test
public void shouldThrowExceptionTryingToDeleteOperationConfiguredWithWriteNoAccessPredicate() throws CacheOperationFailedException {
final NamedOperationDetail noWriteAccess = new NamedOperationDetail.Builder().creatorId(standardUser.getUserId()).description("an operation that does no allow read access").operationName("test").readers(readers).operationChain(standardOpChain).writeAccessPredicate(new NoAccessPredicate()).build();
cache.addNamedOperation(noWriteAccess, false, standardUser);
assertThatExceptionOfType(CacheOperationFailedException.class).isThrownBy(() -> cache.deleteNamedOperation("test", standardUser));
}
Aggregations