use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.
the class UserQueryTest method testFindProperty3.
@Test
public void testFindProperty3() throws RepositoryException {
Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
public <T> void build(QueryBuilder<T> builder) {
builder.setCondition(builder.eq("@numberOfLegs", vf.createValue(8)));
}
});
Iterator<User> expected = Iterators.filter(users.iterator(), new Predicate<User>() {
public boolean apply(User user) {
try {
Value[] numberOfLegs = user.getProperty("numberOfLegs");
return numberOfLegs != null && numberOfLegs.length == 1 && numberOfLegs[0].getLong() == 8;
} catch (RepositoryException e) {
fail(e.getMessage());
}
return false;
}
});
assertTrue(result.hasNext());
assertSameElements(result, expected);
}
use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.
the class UserQueryTest method testFindGroupsInGroup.
@Test
public void testFindGroupsInGroup() throws RepositoryException {
Group[] groups = new Group[] { mammals, vertebrates, apes };
for (final Group g : groups) {
Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
public <T> void build(QueryBuilder<T> builder) {
try {
builder.setSelector(Group.class);
builder.setScope(g.getID(), true);
} catch (RepositoryException e) {
fail(e.getMessage());
}
}
});
Iterator<Authorizable> members = g.getDeclaredMembers();
Iterator<Authorizable> users = Iterators.filter(members, new Predicate<Authorizable>() {
public boolean apply(Authorizable authorizable) {
return authorizable.isGroup();
}
});
assertSameElements(result, users);
}
}
use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.
the class UserQueryTest method testCondition2.
@Test
public void testCondition2() throws RepositoryException {
Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
public <T> void build(QueryBuilder<T> builder) {
builder.setCondition(builder.or(builder.eq("profile/@food", vf.createValue("mice")), builder.eq("profile/@food", vf.createValue("nectar"))));
}
});
Iterator<User> expected = Iterators.filter(users.iterator(), new Predicate<User>() {
public boolean apply(User user) {
try {
Value[] food = user.getProperty("profile/food");
return food != null && food.length == 1 && (food[0].getString().equals("mice") || food[0].getString().equals("nectar"));
} catch (RepositoryException e) {
fail(e.getMessage());
}
return false;
}
});
assertTrue(result.hasNext());
assertSameElements(result, expected);
}
use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.
the class UserQueryTest method testPropertyExistence.
@Test
public void testPropertyExistence() throws RepositoryException {
Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
public <T> void build(QueryBuilder<T> builder) {
builder.setCondition(builder.exists("@poisonous"));
}
});
Iterator<User> expected = Iterators.filter(users.iterator(), new Predicate<User>() {
public boolean apply(User user) {
try {
Value[] poisonous = user.getProperty("poisonous");
return poisonous != null && poisonous.length == 1;
} catch (RepositoryException e) {
fail(e.getMessage());
}
return false;
}
});
assertTrue(result.hasNext());
assertSameElements(result, expected);
}
use of org.apache.jackrabbit.api.security.user.Authorizable in project jackrabbit-oak by apache.
the class UserQueryTest method testDirectScope.
@Test
public void testDirectScope() throws RepositoryException {
Group[] groups = new Group[] { mammals, vertebrates, apes };
for (final Group g : groups) {
Iterator<Authorizable> result = userMgr.findAuthorizables(new Query() {
public <T> void build(QueryBuilder<T> builder) {
try {
builder.setScope(g.getID(), true);
} catch (RepositoryException e) {
fail(e.getMessage());
}
}
});
Iterator<Authorizable> members = g.getDeclaredMembers();
assertSameElements(result, members);
}
}
Aggregations