public void testFindUsersByQuery() throws Exception
{
createUser("tolik");
uHandler.authenticate("tolik", "pwdADDSomeSaltToBeCompliantWithSomeIS00");
Query query = new Query();
query.setEmail("email@test");
// try to find user by email
assertSizeEquals(1, uHandler.findUsersByQuery(query), UserStatus.ENABLED);
assertSizeEquals(1, uHandler.findUsersByQuery(query, UserStatus.ENABLED), UserStatus.ENABLED);
assertSizeEquals(1, uHandler.findUsersByQuery(query, UserStatus.ANY), UserStatus.ANY);
// try to find user by name with mask
query = new Query();
query.setUserName("*tolik*");
assertSizeEquals(1, uHandler.findUsersByQuery(query));
// try to find user by name with mask
query = new Query();
query.setUserName("tol*");
assertSizeEquals(1, uHandler.findUsersByQuery(query));
// try to find user by name with mask
query = new Query();
query.setUserName("*lik");
assertSizeEquals(1, uHandler.findUsersByQuery(query));
// try to find user by name explicitly
query = new Query();
query.setUserName("tolik");
assertSizeEquals(1, uHandler.findUsersByQuery(query));
// try to find user by part of name without mask
query = new Query();
query.setUserName("tol");
assertSizeEquals(1, uHandler.findUsersByQuery(query));
// try to find user by fist and last names
query = new Query();
query.setFirstName("first");
query.setLastName("last");
assertSizeEquals(1, uHandler.findUsersByQuery(query));
String skipCISearchTests = System.getProperty("orgservice.test.configuration.skipCISearchTests");
if (!"true".equals(skipCISearchTests))
{
// try to find user by name explicitly, case insensitive search
query = new Query();
query.setUserName("Tolik");
assertSizeEquals(1, uHandler.findUsersByQuery(query));
// try to find user by fist and last names, case insensitive search
query = new Query();
query.setFirstName("fiRst");
query.setLastName("lasT");
assertSizeEquals(1, uHandler.findUsersByQuery(query));
}
String skipDateTests = System.getProperty("orgservice.test.configuration.skipDateTests");
if (!"true".equals(skipDateTests))
{
// try to find user by login date
Calendar calc = Calendar.getInstance();
calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) - 1);
query = new Query();
query.setFromLoginDate(calc.getTime());
query.setUserName("tolik");
assertSizeEquals(1, uHandler.findUsersByQuery(query));
calc = Calendar.getInstance();
calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) + 1);
query = new Query();
query.setFromLoginDate(calc.getTime());
assertSizeEquals(0, uHandler.findUsersByQuery(query));
calc = Calendar.getInstance();
calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) - 1);
query = new Query();
query.setToLoginDate(calc.getTime());
assertSizeEquals(0, uHandler.findUsersByQuery(query));
calc = Calendar.getInstance();
calc.set(Calendar.YEAR, calc.get(Calendar.YEAR) + 1);
query = new Query();
query.setToLoginDate(calc.getTime());
query.setUserName("tolik");
assertSizeEquals(1, uHandler.findUsersByQuery(query));
}
createUser("rolik");
createUser("bolik");
createUser("volik");
query = new Query();
query.setUserName("olik");
ListAccess<User> users = uHandler.findUsersByQuery(query);
assertSizeEquals(4, users, UserStatus.ENABLED);
assertSizeEquals(4, uHandler.findUsersByQuery(query, UserStatus.ENABLED), UserStatus.ENABLED);