Search in sources :

Example 6 with TraitRequirement

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());
    }
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 7 with TraitRequirement

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());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 8 with TraitRequirement

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));
    }
}
Also used : Concat(uk.gov.gchq.gaffer.function.transform.Concat) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 9 with TraitRequirement

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));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Element(uk.gov.gchq.gaffer.data.element.Element) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) IsIn(uk.gov.gchq.gaffer.function.filter.IsIn) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 10 with TraitRequirement

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));
        }
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Aggregations

Test (org.junit.Test)18 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)18 Element (uk.gov.gchq.gaffer.data.element.Element)14 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)14 Entity (uk.gov.gchq.gaffer.data.element.Entity)12 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)10 HashSet (java.util.HashSet)7 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)5 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)5 Edge (uk.gov.gchq.gaffer.data.element.Edge)4 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4 GetEntities (uk.gov.gchq.gaffer.operation.impl.get.GetEntities)4 User (uk.gov.gchq.gaffer.user.User)4 Concat (uk.gov.gchq.gaffer.function.transform.Concat)3 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)3 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 IsEqual (uk.gov.gchq.gaffer.function.filter.IsEqual)2 IsIn (uk.gov.gchq.gaffer.function.filter.IsIn)2 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)2