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());
}
}
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
}
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);
}
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));
}
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"));
}
}
}
Aggregations