Search in sources :

Example 51 with OperationChain

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

the class OperationChainLimiterTest method shouldRejectOperationChainWhenUserHasNoAuthWithAConfiguredScore.

@Test
public void shouldRejectOperationChainWhenUserHasNoAuthWithAConfiguredScore() {
    // Given
    final OperationChain opChain = new OperationChain.Builder().first(new GenerateObjects()).build();
    final User user = new User.Builder().opAuths("NoScore").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) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.Test)

Example 52 with OperationChain

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

the class OperationChainLimiterTest method shouldAcceptOperationChainWhenUserHasAuthScoreEqualToChainScore.

@Test
public void shouldAcceptOperationChainWhenUserHasAuthScoreEqualToChainScore() {
    // Given
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentEntitySeeds()).then(new GenerateObjects()).build();
    final User user = new User.Builder().opAuths("User").build();
    // When
    OPERATION_CHAIN_LIMITER.preExecute(opChain, user);
// Then - no exceptions
}
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) Test(org.junit.Test)

Example 53 with OperationChain

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

the class OperationChainLimiterTest method shouldReturnResultWithoutModification.

@Test
public void shouldReturnResultWithoutModification() {
    // Given
    final Object result = mock(Object.class);
    final OperationChain opChain = new OperationChain.Builder().first(new GenerateObjects<>()).build();
    final User user = new User.Builder().opAuths("NoScore").build();
    // When
    final Object returnedResult = OPERATION_CHAIN_LIMITER.postExecute(result, opChain, user);
    // Then
    assertSame(result, returnedResult);
}
Also used : GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Example 54 with OperationChain

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

the class GafferResultCacheExporterTest method shouldGetResults.

@Test
public void shouldGetResults() throws OperationException, SerialisationException {
    // Given
    final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
    long timestamp = System.currentTimeMillis();
    final List<Element> cachedEdges = createCachedEdges(timestamp, serialisedResults);
    given(store.execute(opChain.capture(), Mockito.eq(user))).willReturn(new WrappedCloseableIterable<>(cachedEdges));
    final GafferResultCacheExporter exporter = new GafferResultCacheExporter(user, jobId, resultCache, SERIALISER, visibility, requiredOpAuths);
    // When
    final CloseableIterable<?> cachedResults = exporter.get(key);
    // Then
    assertEquals(results, Lists.newArrayList(cachedResults));
}
Also used : GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Element(uk.gov.gchq.gaffer.data.element.Element) Test(org.junit.Test)

Example 55 with OperationChain

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

the class GafferResultCacheExporterTest method shouldAddResults.

@Test
public void shouldAddResults() throws OperationException, SerialisationException {
    // Given
    final GafferResultCacheExporter exporter = new GafferResultCacheExporter(user, jobId, resultCache, SERIALISER, visibility, requiredOpAuths);
    // When
    exporter.add(key, results);
    // Then
    final ArgumentCaptor<OperationChain> opChain = ArgumentCaptor.forClass(OperationChain.class);
    verify(store).execute(opChain.capture(), Mockito.eq(user));
    assertEquals(1, opChain.getValue().getOperations().size());
    final AddElements addElements = (AddElements) opChain.getValue().getOperations().get(0);
    final List<Element> elements = Lists.newArrayList(addElements.getElements());
    final Object timestamp = elements.get(0).getProperty("timestamp");
    final List<Element> expectedElements = createCachedEdges(timestamp, elements.get(0).getProperty("result"), elements.get(1).getProperty("result"), null);
    assertEquals(expectedElements, elements);
    for (int i = 0; i < elements.size(); i++) {
        if (null == results.get(i)) {
            assertNull(elements.get(i).getProperty("result"));
        } else {
            assertArrayEquals(SERIALISER.serialise(results.get(i)), (byte[]) elements.get(i).getProperty("result"));
        }
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Element(uk.gov.gchq.gaffer.data.element.Element) 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