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();
}
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();
}
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();
}
Aggregations