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