// we need a second user for this test
UserData user = TestUtils.setupUser("foofoo");
TestUtils.endSession(true);
UserManager mgr = RollerFactory.getRoller().getUserManager();
PermissionsData perm = null;
List perms = null;
// get all permissions for a user
perms = mgr.getAllPermissions(user);
assertEquals(0, perms.size());
perms = mgr.getAllPermissions(testUser);
assertEquals(1, perms.size());
// get all permissions for a weblog
perms = mgr.getAllPermissions(testWeblog);
assertEquals(1, perms.size());
perm = new PermissionsData();
perm.setUser(user);
perm.setWebsite(testWeblog);
perm.setPending(true);
perm.setPermissionMask(PermissionsData.AUTHOR);
mgr.savePermissions(perm);
// get pending permissions for a user
perms = mgr.getPendingPermissions(testUser);
assertEquals(0, perms.size());
perms = mgr.getPendingPermissions(user);
assertEquals(1, perms.size());
// get pending permissions for a weblog
perms = mgr.getPendingPermissions(testWeblog);
assertEquals(1, perms.size());
// get permissions by id
String id = perm.getId();
perm = null;
perm = mgr.getPermissions(id);
assertNotNull(perm);
assertEquals(id, perm.getId());
// get permissions for a specific user/weblog
perm = null;
perm = mgr.getPermissions(testWeblog, testUser);
assertNotNull(perm);
assertEquals(PermissionsData.ADMIN, perm.getPermissionMask());
perm = null;
perm = mgr.getPermissions(testWeblog, user);
assertNotNull(perm);
assertEquals(PermissionsData.AUTHOR, perm.getPermissionMask());
assertEquals(true, perm.isPending());
// cleanup the extra test user
TestUtils.teardownUser(user.getId());
TestUtils.endSession(true);
}