use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.
the class GetAllElementsIT method shouldGetAllElementsFilteredOnGroup.
@TraitRequirement({ StoreTrait.PRE_AGGREGATION_FILTERING, StoreTrait.STORE_AGGREGATION })
@Test
public void shouldGetAllElementsFilteredOnGroup() throws Exception {
final GetAllElements<Element> op = new GetAllElements.Builder<>().populateProperties(true).view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
// When
final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
// Then
final List<Element> resultList = Lists.newArrayList(results);
assertEquals(getEntities().size(), resultList.size());
for (final Element element : resultList) {
assertEquals(TestGroups.ENTITY, element.getGroup());
}
}
use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.
the class StoreValidationIT method shouldRemoveInvalidElements.
@Test
@TraitRequirement(StoreTrait.STORE_VALIDATION)
public void shouldRemoveInvalidElements() throws OperationException, InterruptedException {
// Given
final User user = new User();
final Entity entity = new Entity(TestGroups.ENTITY_2, VERTEX);
entity.putProperty(TestPropertyNames.INT, 100);
// add elements but skip the validation
graph.execute(new AddElements.Builder().elements(Collections.<Element>singleton(entity)).validate(false).build(), user);
// When
final CloseableIterable<Entity> results1 = graph.execute(new GetEntities.Builder<>().addSeed(new EntitySeed(VERTEX)).build(), user);
// Then
final List<Entity> results1List = Lists.newArrayList(results1);
assertTrue(results1List.isEmpty());
}
use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.
the class TransformationIT method shouldCreateTransientEdgeProperty.
@Test
@TraitRequirement(StoreTrait.TRANSFORMATION)
public void shouldCreateTransientEdgeProperty() throws OperationException {
// Given
final GetEdges<EdgeSeed> getEdges = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed(SOURCE_1, DEST_1, false)).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.TRANSIENT_1, String.class).transformer(new ElementTransformer.Builder().select(IdentifierType.SOURCE.name(), TestPropertyNames.INT).execute(new Concat()).project(TestPropertyNames.TRANSIENT_1).build()).build()).build()).build();
// When
final List<Edge> results = Lists.newArrayList(graph.execute(getEdges, getUser()));
assertNotNull(results);
for (final Edge result : results) {
assertEquals(SOURCE_1 + "," + result.getProperty(TestPropertyNames.INT), result.getProperty(TestPropertyNames.TRANSIENT_1));
}
}
use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.
the class AggregationIT method shouldGetAllElementsWithFilterSummarisation.
@TraitRequirement({ StoreTrait.PRE_AGGREGATION_FILTERING, StoreTrait.QUERY_AGGREGATION })
@Test
public void shouldGetAllElementsWithFilterSummarisation() throws Exception {
final Edge edge1 = getEdges().get(new EdgeSeed(SOURCE_1, DEST_1, false)).emptyClone();
edge1.putProperty(TestPropertyNames.INT, 100);
edge1.putProperty(TestPropertyNames.COUNT, 1L);
final Edge edge2 = edge1.emptyClone();
edge2.putProperty(TestPropertyNames.INT, 101);
edge2.putProperty(TestPropertyNames.COUNT, 1L);
graph.execute(new AddElements.Builder().elements(Arrays.asList((Element) edge1, edge2)).build(), getUser());
final GetAllElements<Element> op = new GetAllElements.Builder<>().view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsIn(Arrays.asList((Object) 100, 101))).build()).build()).build()).build();
// When
final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
// Then
final List<Element> resultList = Lists.newArrayList(results);
assertEquals(1, resultList.size());
// aggregation is 'Max'
assertEquals(101, resultList.get(0).getProperty(TestPropertyNames.INT));
}
use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.
the class AggregationIT method shouldAggregateIdenticalElements.
@Test
@TraitRequirement(StoreTrait.STORE_AGGREGATION)
public void shouldAggregateIdenticalElements() throws OperationException, UnsupportedEncodingException {
// Given
final GetElements<ElementSeed, Element> getElements = new GetElements.Builder<>().addSeed(new EntitySeed(AGGREGATED_SOURCE)).build();
// When
final List<Element> results = Lists.newArrayList(graph.execute(getElements, getUser()));
// Then
assertNotNull(results);
assertEquals(2, results.size());
final Entity expectedEntity = new Entity(TestGroups.ENTITY, AGGREGATED_SOURCE);
expectedEntity.putProperty(TestPropertyNames.STRING, "3,3");
final Edge expectedEdge = new Edge(TestGroups.EDGE, AGGREGATED_SOURCE, AGGREGATED_DEST, false);
expectedEdge.putProperty(TestPropertyNames.INT, 1);
expectedEdge.putProperty(TestPropertyNames.COUNT, 2L);
assertThat(results, IsCollectionContaining.hasItems(expectedEdge, expectedEntity));
for (final Element result : results) {
if (result instanceof Entity) {
assertEquals(AGGREGATED_ID, result.getProperty(TestPropertyNames.STRING));
} else {
assertEquals(1, result.getProperty(TestPropertyNames.INT));
assertEquals(2L, result.getProperty(TestPropertyNames.COUNT));
}
}
}
Aggregations