Search in sources :

Example 1 with LocalAccountQuery

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;
        }
    });
}
Also used : List(java.util.List) ILocalAccountPerson(org.apereo.portal.persondir.ILocalAccountPerson) Map(java.util.Map) LocalAccountQuery(org.apereo.portal.persondir.LocalAccountQuery) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 ILocalAccountPerson (org.apereo.portal.persondir.ILocalAccountPerson)1 LocalAccountQuery (org.apereo.portal.persondir.LocalAccountQuery)1 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)1 Test (org.junit.Test)1