use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class AddElementsFromHdfsIT method createGraph.
private Graph createGraph(final Class<? extends AccumuloKeyPackage> keyPackageClass) throws StoreException {
final Schema schema = Schema.fromJson(StreamUtil.schemas(getClass()));
final AccumuloProperties properties = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
properties.setKeyPackageClass(keyPackageClass.getName());
properties.setInstance("instance_" + keyPackageClass.getName());
final AccumuloStore store = new MockAccumuloStore();
store.initialise(schema, properties);
store.updateConfiguration(createLocalConf(), new View(), new User());
return new Graph.Builder().store(store).build();
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class GetElementsBetweenSetsHandlerTest method shouldReturnSummarisedElements.
private void shouldReturnSummarisedElements(final AccumuloStore store) throws OperationException {
final View opView = new View.Builder(defaultView).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy().build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build();
final GetElementsBetweenSets<Element> op = new GetElementsBetweenSets<>(seedsA, seedsB, opView);
final GetElementsBetweenSetsHandler handler = new GetElementsBetweenSetsHandler();
final CloseableIterable<Element> elements = handler.doOperation(op, user, store);
//With query compaction the result size should be 2
assertEquals(2, Iterables.size(elements));
assertThat(elements, IsCollectionContaining.hasItems(expectedSummarisedEdge, expectedEntity1));
elements.close();
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class ViewIT method shouldDeserialiseJsonView.
@Test
public void shouldDeserialiseJsonView() throws IOException {
// Given
// When
View view = loadView();
// Then
final ViewElementDefinition edge = view.getEdge(TestGroups.EDGE);
final ElementTransformer transformer = edge.getTransformer();
assertNotNull(transformer);
final List<ConsumerProducerFunctionContext<String, TransformFunction>> contexts = transformer.getFunctions();
assertEquals(1, contexts.size());
final List<String> selection = contexts.get(0).getSelection();
assertEquals(2, selection.size());
assertEquals(TestPropertyNames.PROP_1, selection.get(0));
assertEquals(IdentifierType.SOURCE.name(), selection.get(1));
final List<String> projection = contexts.get(0).getProjection();
assertEquals(1, projection.size());
assertEquals(TestPropertyNames.TRANSIENT_1, projection.get(0));
assertTrue(contexts.get(0).getFunction() instanceof ExampleTransformFunction);
final ElementFilter postFilter = edge.getPostTransformFilter();
assertNotNull(postFilter);
final List<ConsumerFunctionContext<String, FilterFunction>> filterContexts = postFilter.getFunctions();
assertEquals(1, contexts.size());
final List<String> postFilterSelection = filterContexts.get(0).getSelection();
assertEquals(1, postFilterSelection.size());
assertEquals(TestPropertyNames.TRANSIENT_1, postFilterSelection.get(0));
assertTrue(filterContexts.get(0).getFunction() instanceof ExampleFilterFunction);
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class GraphTest method shouldSetGraphViewOnOperationAndDelegateDoOperationToStore.
@Test
public void shouldSetGraphViewOnOperationAndDelegateDoOperationToStore() 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();
final User user = new User();
final int expectedResult = 5;
final Operation<?, Integer> operation = mock(Operation.class);
given(operation.getView()).willReturn(null);
final OperationChain<Integer> opChain = mock(OperationChain.class);
given(opChain.getOperations()).willReturn(Collections.<Operation>singletonList(operation));
given(store.execute(opChain, user)).willReturn(expectedResult);
// When
int result = graph.execute(opChain, user);
// Then
assertEquals(expectedResult, result);
verify(store).execute(opChain, user);
verify(operation).setView(view);
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.
the class GraphTest method shouldConstructGraphAndCreateViewWithGroups.
@Test
public void shouldConstructGraphAndCreateViewWithGroups() {
// Given
final Store store = mock(Store.class);
final Schema schema = mock(Schema.class);
given(store.getSchema()).willReturn(schema);
final Set<String> edgeGroups = new HashSet<>();
edgeGroups.add("edge1");
edgeGroups.add("edge2");
edgeGroups.add("edge3");
edgeGroups.add("edge4");
given(schema.getEdgeGroups()).willReturn(edgeGroups);
final Set<String> entityGroups = new HashSet<>();
entityGroups.add("entity1");
entityGroups.add("entity2");
entityGroups.add("entity3");
entityGroups.add("entity4");
given(schema.getEntityGroups()).willReturn(entityGroups);
// When
final View resultView = new Graph.Builder().store(store).build().getView();
// Then
assertNotSame(schema, resultView);
assertArrayEquals(entityGroups.toArray(), resultView.getEntityGroups().toArray());
assertArrayEquals(edgeGroups.toArray(), resultView.getEdgeGroups().toArray());
for (final ViewElementDefinition resultElementDef : resultView.getEntities().values()) {
assertNotNull(resultElementDef);
assertEquals(0, resultElementDef.getTransientProperties().size());
assertNull(resultElementDef.getTransformer());
}
for (final ViewElementDefinition resultElementDef : resultView.getEdges().values()) {
assertNotNull(resultElementDef);
assertEquals(0, resultElementDef.getTransientProperties().size());
assertNull(resultElementDef.getTransformer());
}
}
Aggregations