Search in sources :

Example 16 with TraitRequirement

use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.

the class VisibilityIT method shouldAccessMultipleVisibilityGroups_and.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessMultipleVisibilityGroups_and() throws OperationException {
    final Set<Element> elements = new HashSet<>();
    final Entity entity1 = new Entity(TestGroups.ENTITY, "B");
    entity1.putProperty(TestTypes.VISIBILITY, "vis1&vis2");
    elements.add(entity1);
    final AddElements addElements = new AddElements.Builder().elements(elements).build();
    graph.execute(addElements, new User());
    final GetElements<EntitySeed, Element> get = new GetElements.Builder<EntitySeed, Element>().addSeed(new EntitySeed("B")).build();
    final CloseableIterable<Element> iterable = graph.execute(get, new User(User.UNKNOWN_USER_ID, Sets.newHashSet("vis1", "vis2")));
    final List<Element> results = Lists.newArrayList(iterable);
    assertThat("Results do not contain all expected Elements.", results, hasSize(1));
    for (final Element e : iterable) {
        assertTrue(e.getProperties().containsKey(TestTypes.VISIBILITY));
    }
    iterable.close();
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) 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) HashSet(java.util.HashSet) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 17 with TraitRequirement

use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.

the class VisibilityIT method shouldAccessSingleVisibilityGroup.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessSingleVisibilityGroup() throws OperationException {
    final Set<Element> elements = new HashSet<>();
    final Entity entity1 = new Entity(TestGroups.ENTITY, "A");
    entity1.putProperty(TestTypes.VISIBILITY, "vis1");
    final Entity entity2 = new Entity(TestGroups.ENTITY, "B");
    entity2.putProperty(TestTypes.VISIBILITY, "vis1");
    elements.add(entity1);
    elements.add(entity2);
    final AddElements addElements = new AddElements.Builder().elements(elements).build();
    graph.execute(addElements, USER_VIS_1);
    final GetElements<EntitySeed, Element> get = new GetElements.Builder<EntitySeed, Element>().addSeed(new EntitySeed("A")).addSeed(new EntitySeed("B")).build();
    final CloseableIterable<Element> userVis1Iterable = graph.execute(get, USER_VIS_1);
    final CloseableIterable<Element> userVis2Iterable = graph.execute(get, USER_VIS_2);
    final List<Element> userVis1Results = Lists.newArrayList(userVis1Iterable);
    final List<Element> userVis2Results = Lists.newArrayList(userVis2Iterable);
    assertThat(userVis1Results, hasSize(2));
    assertThat(userVis2Results, is(empty()));
    for (final Element e : userVis1Results) {
        // Check that all visible entities contain the visibility property
        assertTrue("Missing visibility property.", e.getProperties().containsKey(TestTypes.VISIBILITY));
        // Check that the visibility key contai
        // ns the correct value
        assertEquals("Visibility property should be \"vis1\"", e.getProperties().get(TestTypes.VISIBILITY).toString(), "vis1");
    }
    userVis1Iterable.close();
    userVis2Iterable.close();
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashSet(java.util.HashSet) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 18 with TraitRequirement

use of uk.gov.gchq.gaffer.integration.TraitRequirement in project Gaffer by gchq.

the class VisibilityIT method shouldAccessEmptyVisibilityGroups.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessEmptyVisibilityGroups() throws OperationException, JsonProcessingException {
    final Set<Element> elements = new HashSet<>();
    final Entity entity1 = new Entity(TestGroups.ENTITY, "A");
    entity1.putProperty(TestTypes.VISIBILITY, "");
    elements.add(entity1);
    final AddElements addElements = new AddElements.Builder().elements(elements).build();
    graph.execute(addElements, USER_DEFAULT);
    final GetElements<EntitySeed, Element> get = new GetElements.Builder<EntitySeed, Element>().addSeed(new EntitySeed("A")).build();
    final CloseableIterable<Element> iterable = graph.execute(get, USER_DEFAULT);
    final List<Element> results = Lists.newArrayList(iterable);
    // Check for all entities which should be visible
    assertThat("Results do not contain all expected entities.", results, hasSize(1));
    for (final Element e : results) {
        // Check that all visible entities contain the visibility property
        assertTrue("Visibility property should be visible.", e.getProperties().containsKey(TestTypes.VISIBILITY));
        assertThat("Visibility property should contain an empty String.", e.getProperties().get(TestTypes.VISIBILITY).toString(), isEmptyString());
    }
    iterable.close();
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) HashSet(java.util.HashSet) 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