Search in sources :

Example 21 with NamedOperationDetail

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));
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 22 with NamedOperationDetail

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();
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 23 with NamedOperationDetail

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());
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 24 with NamedOperationDetail

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());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) CustomUserPredicate(uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Example 25 with NamedOperationDetail

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));
}
Also used : NoAccessPredicate(uk.gov.gchq.gaffer.access.predicate.NoAccessPredicate) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException) Test(org.junit.jupiter.api.Test)

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