JetspeedUser user = null;
try
{
// test updating and retrieving some fields
user = JetspeedUserManagement.getUser(new UserNamePrincipal("turbine"));
String lastName = user.getLastName();
user.setLastName(TEMP_LAST_NAME);
user.setDisabled(true);
JetspeedUserManagement.saveUser(user);
JetspeedUser user2 = JetspeedUserManagement.getUser(new UserNamePrincipal("turbine"));
assertTrue(user2.getLastName().equals(TEMP_LAST_NAME));
assertTrue(user2.getDisabled() == true);
user2.setLastName(lastName);
user2.setDisabled(false);
JetspeedUserManagement.saveUser(user2);
JetspeedUser user3 = JetspeedUserManagement.getUser(new UserNamePrincipal("turbine"));
assertTrue(user3.getLastName().equals(lastName));
assertTrue(user3.getDisabled() == false);
// test set/get Perm
user3.setPerm("unittest", "test");
JetspeedUserManagement.saveUser(user3);
JetspeedUser user4 = JetspeedUserManagement.getUser(new UserNamePrincipal("turbine"));
String unitTestValue = (String)user4.getPerm("unittest");
assertTrue(unitTestValue.equals("test"));
user4.setPerm("unittest", null);
JetspeedUserManagement.saveUser(user4);
// try saving to an non-existing user
try
{
JetspeedUser user5 = JetspeedUserFactory.getInstance();
user5.setLastName("junk");
JetspeedUserManagement.saveUser(user5);
}
catch (Exception e)
{
assertTrue(e instanceof UnknownUserException);
}
// test dup on unique username key
JetspeedUser user6 = JetspeedUserManagement.getUser(new UserNamePrincipal("turbine"));
user6.setUserName("admin");
try
{
JetspeedUserManagement.saveUser(user6);
}