Search in sources :

Example 1 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class OperationChainLimiterTest method shouldRejectOperationChainWhenUserHasAuthScoreLessThanChainScore.

@Test
public void shouldRejectOperationChainWhenUserHasAuthScoreLessThanChainScore() {
    // Given
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds()).then(new GetAdjacentEntitySeeds()).then(new GetAdjacentEntitySeeds()).then(new GetAdjacentEntitySeeds()).then(new GenerateObjects()).build();
    final User user = new User.Builder().opAuths("User").build();
    try {
        OPERATION_CHAIN_LIMITER.preExecute(opChain, user);
        fail("Exception expected");
    } catch (final UnauthorisedException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) GetAdjacentEntitySeeds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.Test)

Example 2 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class OperationChainLimiterTest method shouldAcceptOperationChainWhenUserHasAuthScoreGreaterThanChainScore.

@Test
public void shouldAcceptOperationChainWhenUserHasAuthScoreGreaterThanChainScore() {
    // Given
    final OperationChain opChain = new OperationChain.Builder().first(new GetEntities()).build();
    final User user = new User.Builder().opAuths("User").build();
    // When
    OPERATION_CHAIN_LIMITER.preExecute(opChain, user);
// Then - no exceptions
}
Also used : User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test)

Example 3 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class OperationChainLimiterTest method shouldRejectOperationChainWhenUserHasMaxAuthScoreLessThanChainScore.

@Test
public void shouldRejectOperationChainWhenUserHasMaxAuthScoreLessThanChainScore() {
    // Given
    final OperationChain opChain = new OperationChain.Builder().first(new GetAllEdges()).then(new GenerateObjects()).build();
    final User user = new User.Builder().opAuths("SuperUser", "User").build();
    // When/Then
    try {
        OPERATION_CHAIN_LIMITER.preExecute(opChain, user);
        fail("Exception expected");
    } catch (final UnauthorisedException e) {
        assertNotNull(e.getMessage());
    }
}
Also used : GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) User(uk.gov.gchq.gaffer.user.User) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.Test)

Example 4 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain 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 JSONSerialiser jsonSerialiser = mock(JSONSerialiser.class);
    final Long timeToLive = 10000L;
    final String visibility = "visibility value";
    final ExportToGafferResultCacheHandler handler = new ExportToGafferResultCacheHandler();
    handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
    handler.setJsonSerialiser(jsonSerialiser);
    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.eq(context.getUser()));
    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) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Test(org.junit.Test)

Example 5 with OperationChain

use of uk.gov.gchq.gaffer.operation.OperationChain in project Gaffer by gchq.

the class GafferResultCacheExporterTest method shouldGetEmptyResults.

@Test
public void shouldGetEmptyResults() throws OperationException, SerialisationException {
    // Given
    final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
    given(store.execute(opChain.capture(), Mockito.eq(user))).willReturn(null);
    final GafferResultCacheExporter exporter = new GafferResultCacheExporter(user, jobId, resultCache, SERIALISER, visibility, requiredOpAuths);
    // When
    final CloseableIterable<?> cachedResults = exporter.get(key);
    // Then
    assertEquals(Collections.emptyList(), Lists.newArrayList(cachedResults));
}
Also used : GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Aggregations

OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)65 Test (org.junit.Test)52 User (uk.gov.gchq.gaffer.user.User)38 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 Store (uk.gov.gchq.gaffer.store.Store)13 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)12 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)11 GenerateObjects (uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects)11 Schema (uk.gov.gchq.gaffer.store.schema.Schema)10 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)9 GetAdjacentEntitySeeds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentEntitySeeds)8 Edge (uk.gov.gchq.gaffer.data.element.Edge)7 Element (uk.gov.gchq.gaffer.data.element.Element)7 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)7 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)7 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)7 InOrder (org.mockito.InOrder)6 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)6 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)6