use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class NamedOperationCacheBackwardCompatibilityTest method shouldReturnExpectedNamedOperationDetailUsingCacheDataFromVersion1_12.
@Test
public void shouldReturnExpectedNamedOperationDetailUsingCacheDataFromVersion1_12() throws Exception {
final NamedOperationDetail namedOperationDetail = new NamedOperationDetail.Builder().operationName(OPERATION_NAME).description("standard operation").creatorId(ADDING_USER.getUserId()).readers(asList("readerAuth1", "readerAuth2")).writers(asList("writerAuth1", "writerAuth2")).operationChain(new OperationChain.Builder().first(new AddElements()).build()).build();
final NamedOperationDetail namedOperationDetailFromCacheVersion1_12 = operationCache.getNamedOperation(OPERATION_NAME, ADDING_USER);
assertEquals(namedOperationDetail.getReadAccessPredicate(), namedOperationDetailFromCacheVersion1_12.getReadAccessPredicate());
assertEquals(namedOperationDetail.getWriteAccessPredicate(), namedOperationDetailFromCacheVersion1_12.getWriteAccessPredicate());
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class ExamplesService method addElements.
@Override
public AddElements addElements() {
final AddElements op = new AddElements();
List<Element> elements = new ArrayList<>();
if (hasEntities()) {
elements.add(getEntity(1));
elements.add(getEntity(2));
}
if (hasEdges()) {
elements.add(getEdge(1, 2));
}
op.setInput(elements);
populateOperation(op);
return op;
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class AddElementsHandlerTest method shouldThrowNoExceptionsWhenValidateFlagSetToFalse.
@Test
public void shouldThrowNoExceptionsWhenValidateFlagSetToFalse() throws OperationException, StoreException {
final AddElements addElements = new AddElements.Builder().input(new Edge("Unknown group", "source", "dest", true)).validate(false).build();
final AddElementsHandler handler = new AddElementsHandler();
final Context context = mock(Context.class);
final HBaseStore store = mock(HBaseStore.class);
final Table table = mock(Table.class);
given(store.getTable()).willReturn(table);
final HBaseProperties properties = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
given(store.getProperties()).willReturn(properties);
given(store.getSchema()).willReturn(SCHEMA);
// When / Then - no exceptions
handler.doOperation(addElements, context, store);
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class AddElementsHandlerTest method shouldDoNothingIfNoElementsProvided.
@Test
public void shouldDoNothingIfNoElementsProvided() throws OperationException, StoreException, IOException {
// Given
final AddElementsHandler handler = new AddElementsHandler();
final AddElements addElements = new AddElements();
final Context context = mock(Context.class);
final HBaseStore store = mock(HBaseStore.class);
final Table table = mock(Table.class);
given(store.getTable()).willReturn(table);
final HBaseProperties properties = HBaseProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
given(store.getProperties()).willReturn(properties);
given(store.getSchema()).willReturn(SCHEMA);
// When
handler.doOperation(addElements, context, store);
// Then
verify(table, never()).put(any(Put.class));
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class GetAllElementsHandlerTest method testGetAllElementsWithViewRestrictedByGroupAndAPreAggregationFilter.
@Test
public void testGetAllElementsWithViewRestrictedByGroupAndAPreAggregationFilter() throws OperationException {
// Given
final Graph graph = getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetAllElements getAllElements = new GetAllElements.Builder().view(new View.Builder().edge(BASIC_EDGE1, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(COUNT).execute(new IsMoreThan(5)).build()).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getAllElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(e -> e.getGroup().equals(BASIC_EDGE1) && ((int) e.getProperty(COUNT)) > 5).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
Aggregations