Search in sources :

Example 36 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class ExportToGafferResultCacheHandlerTest method shouldHandleOperationByDelegatingToAnNewExporter.

@Test
public void shouldHandleOperationByDelegatingToAnNewExporter() throws OperationException {
    // Given
    final List<?> results = Arrays.asList(1, 2, 3);
    final ExportToGafferResultCache export = new ExportToGafferResultCache.Builder<>().key("key").input(results).build();
    final Context context = new Context();
    final Store store = mock(Store.class);
    final Long timeToLive = 10000L;
    final String visibility = "visibility value";
    final ExportToGafferResultCacheHandler handler = new ExportToGafferResultCacheHandler();
    handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
    handler.setTimeToLive(timeToLive);
    handler.setVisibility(visibility);
    final Store cacheStore = mock(Store.class);
    TestStore.mockStore = cacheStore;
    // When
    final Object handlerResult = handler.doOperation(export, context, store);
    // Then
    assertSame(handlerResult, results);
    final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
    verify(cacheStore).execute(opChain.capture(), Mockito.any(Context.class));
    assertEquals(1, opChain.getValue().getOperations().size());
    assertTrue(opChain.getValue().getOperations().get(0) instanceof AddElements);
    final GafferResultCacheExporter exporter = context.getExporter(GafferResultCacheExporter.class);
    assertNotNull(exporter);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Test(org.junit.jupiter.api.Test)

Example 37 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class AddNamedOperationHandlerTest method shouldNotAllowForNonRecursiveNamedOperationsToBeNested.

@Test
public void shouldNotAllowForNonRecursiveNamedOperationsToBeNested() throws OperationException {
    OperationChain child = new OperationChain.Builder().first(new AddElements()).build();
    addNamedOperation.setOperationChain(child);
    addNamedOperation.setOperationName("child");
    handler.doOperation(addNamedOperation, context, store);
    OperationChain parent = new OperationChain.Builder().first(new NamedOperation.Builder().name("child").build()).then(new GetElements()).build();
    addNamedOperation.setOperationChain(parent);
    addNamedOperation.setOperationName("parent");
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(addNamedOperation, context, store));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Test(org.junit.jupiter.api.Test)

Example 38 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class AddNamedOperationHandlerTest method shouldAddNamedOperationFieldsToNamedOperationDetailCorrectly.

@Test
public void shouldAddNamedOperationFieldsToNamedOperationDetailCorrectly() throws OperationException, CacheOperationFailedException {
    final List<String> readAuths = asList("readAuth1", "readAuth2");
    final List<String> writeAuths = asList("writeAuth1", "writeAuth2");
    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(readAuths);
    addNamedOperation.setWriteAccessRoles(writeAuths);
    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());
    final AccessPredicate expectedReadAccessPredicate = new AccessPredicate(context.getUser(), readAuths);
    assertEquals(expectedReadAccessPredicate, result.getOrDefaultReadAccessPredicate());
    final AccessPredicate expectedWriteAccessPredicate = new AccessPredicate(context.getUser(), writeAuths);
    assertEquals(expectedWriteAccessPredicate, result.getOrDefaultWriteAccessPredicate());
}
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) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) Test(org.junit.jupiter.api.Test)

Example 39 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class DefaultScoreResolverTest method shouldGetScoreForNestedOperationWithNullOperationList.

@Test
public void shouldGetScoreForNestedOperationWithNullOperationList() throws OperationException {
    // Given
    final GetElements op1 = mock(GetElements.class);
    final AddElements op2 = mock(AddElements.class);
    final DefaultScoreResolver scoreResolver = new DefaultScoreResolver();
    final OperationChain opChain = new OperationChain.Builder().first(op1).then(op2).then(new OperationChain((List) null)).build();
    // When
    final Object result = scoreResolver.getScore(opChain);
    // Then
    assertEquals(2, result);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Builder(uk.gov.gchq.gaffer.named.operation.NamedOperation.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.jupiter.api.Test)

Example 40 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class DefaultScoreResolverTest method shouldGetScoreForOperationChainWithMultipleScoreResolvers.

@Test
public void shouldGetScoreForOperationChainWithMultipleScoreResolvers() throws OperationException {
    // Given
    final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
    final ScoreResolver mockResolver = mock(NamedOperationScoreResolver.class);
    final ScoreResolver mockResolver1 = mock(DefaultScoreResolver.class);
    final GetElements op1 = new GetElements();
    final AddElements op2 = new AddElements();
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(GetElements.class, 2);
    final String opName = "namedOp";
    final NamedOperation<Iterable<? extends Element>, Iterable<? extends Element>> namedOp = mock(NamedOperation.class);
    namedOp.setOperationName(opName);
    resolvers.put(namedOp.getClass(), mockResolver);
    resolvers.put(op2.getClass(), mockResolver1);
    given(mockResolver.getScore(eq(namedOp), any())).willReturn(3);
    given(mockResolver1.getScore(eq(op2), any())).willReturn(5);
    final DefaultScoreResolver scoreResolver = new DefaultScoreResolver(opScores, resolvers);
    final OperationChain opChain = new OperationChain.Builder().first(op1).then(op2).then(namedOp).build();
    // When
    final Object result = scoreResolver.getScore(opChain);
    // Then
    assertEquals(10, result);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Element(uk.gov.gchq.gaffer.data.element.Element) Builder(uk.gov.gchq.gaffer.named.operation.NamedOperation.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) NamedOperationScoreResolver(uk.gov.gchq.gaffer.store.operation.resolver.named.NamedOperationScoreResolver) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.jupiter.api.Test)

Aggregations

AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)157 Graph (uk.gov.gchq.gaffer.graph.Graph)99 User (uk.gov.gchq.gaffer.user.User)98 Element (uk.gov.gchq.gaffer.data.element.Element)88 Test (org.junit.jupiter.api.Test)74 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)72 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)63 Edge (uk.gov.gchq.gaffer.data.element.Edge)62 Entity (uk.gov.gchq.gaffer.data.element.Entity)51 ArrayList (java.util.ArrayList)49 HashSet (java.util.HashSet)47 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)47 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)47 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)39 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)37 OperationException (uk.gov.gchq.gaffer.operation.OperationException)36 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)35 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)35 Test (org.junit.Test)30 Set (java.util.Set)28