use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class AbstractOperationTest method shouldCopyFieldsFromGivenOperationWhenConstructing.
@Test
public void shouldCopyFieldsFromGivenOperationWhenConstructing() {
// Given
final Operation<String, ?> operationToCopy = mock(Operation.class);
final View view = mock(View.class);
final String input = "input value";
given(operationToCopy.getView()).willReturn(view);
given(operationToCopy.getInput()).willReturn(input);
// When
final Operation<String, String> operation = new OperationImpl<>(operationToCopy);
// Then
assertSame(view, operation.getView());
assertSame(input, operation.getInput());
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class Graph method updateOperationChainView.
private <OUTPUT> void updateOperationChainView(final OperationChain<OUTPUT> operationChain) {
for (final Operation operation : operationChain.getOperations()) {
final View opView;
if (null == operation.getView()) {
opView = view;
} else if (!operation.getView().hasGroups()) {
opView = new View.Builder().merge(view).merge(operation.getView()).build();
} else {
opView = operation.getView();
}
opView.expandGlobalDefinitions();
operation.setView(opView);
}
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class GraphTest method shouldExposeGetTraitsMethod.
@Test
public void shouldExposeGetTraitsMethod() throws OperationException {
// Given
final Store store = mock(Store.class);
final View view = mock(View.class);
final Graph graph = new Graph.Builder().store(store).view(view).build();
// When
final Set<StoreTrait> storeTraits = new HashSet<>(Arrays.asList(StoreTrait.STORE_AGGREGATION, StoreTrait.TRANSFORMATION));
given(store.getTraits()).willReturn(storeTraits);
final Collection<StoreTrait> returnedTraits = graph.getStoreTraits();
// Then
assertEquals(returnedTraits, storeTraits);
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class ArrayListStoreTest method shouldAddAndGetEdgesThenEntities.
@Test
public void shouldAddAndGetEdgesThenEntities() throws OperationException {
final Graph graph = createGraph();
addElementsToGraph(graph);
//set up the operation to fetch the entities
final OperationChain<CloseableIterable<SimpleEntityDataObject>> opChain = new OperationChain.Builder().first(new GetEdges.Builder<>().addSeed(new EntitySeed(1)).build()).then(new GenerateObjects.Builder<Edge, EntitySeed>().generator(new EntitySeedExtractor(IdentifierType.DESTINATION)).build()).then(new GetEntities.Builder().view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Entity, SimpleEntityDataObject>().generator(new SimpleEntityGenerator()).build()).build();
//now do the hop
final CloseableIterable<SimpleEntityDataObject> results = graph.execute(opChain, new User());
//check the results by converting our edges back into SimpleDataObjects
if (!results.iterator().hasNext()) {
fail("No results returned");
} else {
for (final SimpleEntityDataObject obj : results) {
LOGGER.info(obj.toString());
}
final List<SimpleEntityDataObject> resultList = Lists.newArrayList(results);
assertEquals(1, resultList.size());
assertEquals(1, resultList.get(0).getId());
assertEquals(1, resultList.get(0).getVisibility());
assertEquals("Red", resultList.get(0).getProperties());
}
results.close();
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class ArrayListStoreTest method shouldAddAndGetEdgesBySeed.
@Test
public void shouldAddAndGetEdgesBySeed() throws OperationException {
final Graph graph = createGraph();
addElementsToGraph(graph);
//set up the operation to fetch the edges
final OperationChain<CloseableIterable<SimpleEdgeDataObject>> opChain = new OperationChain.Builder().first(new GetEdges.Builder().addSeed(new EdgeSeed(2, 1, false)).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Edge, SimpleEdgeDataObject>().generator(new SimpleEdgeGenerator()).build()).build();
//now do the hop
final CloseableIterable<SimpleEdgeDataObject> results = graph.execute(opChain, new User());
//check the results by converting our edges back into SimpleDataObjects
if (!results.iterator().hasNext()) {
fail("No results returned");
} else {
for (final SimpleEdgeDataObject obj : results) {
LOGGER.info(obj.toString());
}
final List<SimpleEdgeDataObject> resultList = Lists.newArrayList(results);
assertEquals(1, resultList.size());
int index = 0;
SimpleEdgeDataObject obj = resultList.get(index);
assertEquals(1, obj.getLeft());
assertEquals(2, obj.getRight());
assertEquals(1, obj.getVisibility());
assertEquals("121", obj.getProperties());
}
results.close();
}
Aggregations