use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldAllowReadingOfNamedOperationsUsingAdminAuth.
private void shouldAllowReadingOfNamedOperationsUsingAdminAuth() throws OperationException {
// given
Context contextWithAuthorisedUser = new Context(authorisedUser);
Context contextWithAdminUser = new Context(adminAuthUser);
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(add.getOperationName()).operationChain(add.getOperationChainAsString()).description(add.getDescription()).creatorId(authorisedUser.getUserId()).score(0).parameters(null).build();
ArrayList<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
addNamedOperationHandler.doOperation(add, contextWithAuthorisedUser, store);
// when
List<NamedOperationDetail> resultsWithNoAdminRole = Lists.newArrayList(getAllNamedOperationsHandler.doOperation(get, context, store));
// then
assertThat(resultsWithNoAdminRole).isEmpty();
// when
List<NamedOperationDetail> resultsWithAdminRole = Lists.newArrayList(getAllNamedOperationsHandler.doOperation(get, contextWithAdminUser, store));
// then
assertThat(resultsWithAdminRole).hasSize(1).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldBeAbleToAddNamedOperationToCache.
private void shouldBeAbleToAddNamedOperationToCache() throws OperationException {
// given
GetAllNamedOperations get = new GetAllNamedOperations.Builder().build();
final Store store = mock(Store.class);
given(store.getProperties()).willReturn(properties);
// when
addNamedOperationHandler.doOperation(add, context, store);
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(add.getOperationName()).operationChain(add.getOperationChainAsString()).creatorId(user.getUserId()).description(add.getDescription()).score(0).parameters(null).build();
List<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
List<NamedOperationDetail> results = Lists.newArrayList(new GetAllNamedOperationsHandler().doOperation(get, context, store));
// then
assertThat(results).hasSize(1).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldAllowUpdatingOfNamedOperationsWithAllowedUsers.
private void shouldAllowUpdatingOfNamedOperationsWithAllowedUsers() throws OperationException {
// given
final Store store = mock(Store.class);
given(store.getProperties()).willReturn(properties);
new AddNamedOperationHandler().doOperation(add, context, store);
AddNamedOperation update = new AddNamedOperation.Builder().name(add.getOperationName()).description("a different operation").operationChain(add.getOperationChainAsString()).overwrite().score(0).build();
GetAllNamedOperations get = new GetAllNamedOperations();
// when
new AddNamedOperationHandler().doOperation(add, context, store);
List<NamedOperationDetail> results = Lists.newArrayList(getAllNamedOperationsHandler.doOperation(get, context, store));
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(update.getOperationName()).operationChain(update.getOperationChainAsString()).description(update.getDescription()).creatorId(user.getUserId()).score(0).parameters(null).build();
ArrayList<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
// then
assertThat(results).hasSameSizeAs(expected).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldAllowUpdatingOfNamedOperations.
private void shouldAllowUpdatingOfNamedOperations() throws OperationException {
// given
final Store store = mock(Store.class);
final StoreProperties storeProps = mock(StoreProperties.class);
given(store.getProperties()).willReturn(storeProps);
new AddNamedOperationHandler().doOperation(add, context, store);
AddNamedOperation update = new AddNamedOperation.Builder().name(add.getOperationName()).description("a different operation").operationChain(add.getOperationChainAsString()).overwrite().score(0).build();
GetAllNamedOperations get = new GetAllNamedOperations();
// when
new AddNamedOperationHandler().doOperation(add, context, store);
List<NamedOperationDetail> results = Lists.newArrayList(getAllNamedOperationsHandler.doOperation(get, context, store));
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(update.getOperationName()).operationChain(update.getOperationChainAsString()).description(update.getDescription()).creatorId(user.getUserId()).score(0).parameters(null).build();
ArrayList<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
// then
assertThat(results).hasSameSizeAs(expected).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldAllowUpdatingOfNamedOperationsUsingAdminAuth.
private void shouldAllowUpdatingOfNamedOperationsUsingAdminAuth() throws OperationException {
// given
Context contextWithAuthorisedUser = new Context(authorisedUser);
Context contextWithAdminUser = new Context(adminAuthUser);
addNamedOperationHandler.doOperation(add, contextWithAuthorisedUser, store);
AddNamedOperation update = new AddNamedOperation.Builder().name(add.getOperationName()).description("a different operation").operationChain(add.getOperationChainAsString()).overwrite().score(0).build();
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(update.getOperationName()).operationChain(update.getOperationChainAsString()).description(update.getDescription()).creatorId(adminAuthUser.getUserId()).score(0).parameters(null).build();
ArrayList<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
// when / then
assertThatExceptionOfType(OperationException.class).isThrownBy(() -> addNamedOperationHandler.doOperation(update, context, store)).withMessageContaining("User UNKNOWN does not have permission to overwrite");
// when
addNamedOperationHandler.doOperation(update, contextWithAdminUser, store);
List<NamedOperationDetail> results = Lists.newArrayList(getAllNamedOperationsHandler.doOperation(get, contextWithAdminUser, store));
// then
assertThat(results).hasSameSizeAs(expected).isEqualTo(expected);
}
Aggregations