Search in sources :

Example 1 with NamedOperationDetail

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)

Example 2 with NamedOperationDetail

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);
}
Also used : GetAllNamedOperationsHandler(uk.gov.gchq.gaffer.store.operation.handler.named.GetAllNamedOperationsHandler) GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) Store(uk.gov.gchq.gaffer.store.Store) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)

Example 3 with NamedOperationDetail

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);
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) Store(uk.gov.gchq.gaffer.store.Store) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) AddNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler)

Example 4 with NamedOperationDetail

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);
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) Store(uk.gov.gchq.gaffer.store.Store) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) AddNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties)

Example 5 with NamedOperationDetail

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)

Aggregations

NamedOperationDetail (uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)40 Test (org.junit.jupiter.api.Test)27 User (uk.gov.gchq.gaffer.user.User)11 GetAllNamedOperations (uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations)10 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)10 NamedOperationCache (uk.gov.gchq.gaffer.store.operation.handler.named.cache.NamedOperationCache)10 AddNamedOperation (uk.gov.gchq.gaffer.named.operation.AddNamedOperation)9 Context (uk.gov.gchq.gaffer.store.Context)9 CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException)7 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)7 ParameterDetail (uk.gov.gchq.gaffer.named.operation.ParameterDetail)5 ArrayList (java.util.ArrayList)4 Element (uk.gov.gchq.gaffer.data.element.Element)4 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4 Store (uk.gov.gchq.gaffer.store.Store)4 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)3 AddNamedOperationHandler (uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2