use of org.apereo.portal.persondir.LocalAccountQuery in project uPortal by Jasig.
the class JpaLocalAccountDaoImplTest method testAccountSearch.
@Test
public void testAccountSearch() throws Exception {
//Create users
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
final ILocalAccountPerson user1 = localAccountDao.createPerson("user1");
user1.setAttribute("attr1", "value1", "ValUe2", "blue");
user1.setAttribute("attr2", "foobar");
localAccountDao.updateAccount(user1);
final ILocalAccountPerson user2 = localAccountDao.createPerson("user2");
user2.setAttribute("attr1", "blue");
user2.setAttribute("attr2", "barrun");
localAccountDao.updateAccount(user2);
return null;
}
});
//Direct Access
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
final ILocalAccountPerson user1 = localAccountDao.getPerson("user1");
assertNotNull(user1);
assertEquals("user1", user1.getName());
final Map<String, List<Object>> attributes = user1.getAttributes();
assertNotNull(attributes);
assertEquals(2, attributes.size());
return null;
}
});
//Query 0
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
final LocalAccountQuery query = new LocalAccountQuery();
query.setAttribute("attr1", Arrays.asList("black"));
final List<ILocalAccountPerson> people = localAccountDao.getPeople(query);
assertNotNull(people);
assertEquals(0, people.size());
return null;
}
});
//Query 1
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
final LocalAccountQuery query = new LocalAccountQuery();
query.setAttribute("attr1", Arrays.asList("value"));
query.setAttribute("attr2", Arrays.asList("bar"));
final List<ILocalAccountPerson> people = localAccountDao.getPeople(query);
assertNotNull(people);
assertEquals(2, people.size());
return null;
}
});
//Query 2
this.execute(new Callable<Object>() {
@Override
public Object call() throws Exception {
final LocalAccountQuery query = new LocalAccountQuery();
query.setAttribute("attr1", Arrays.asList("black"));
query.setAttribute("attr2", Arrays.asList("foo", "run"));
final List<ILocalAccountPerson> people = localAccountDao.getPeople(query);
assertNotNull(people);
assertEquals(2, people.size());
return null;
}
});
}
Aggregations