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