DbSetupUtility.dbupgrade("LATEST");
}
public void testUpgradeToV2_119() throws Exception {
SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
RoleManagerLocal roleManager = LookupUtil.getRoleManager();
Subject overlord = subjectManager.getOverlord();
Role customRole = new Role("role" + UUID.randomUUID());
customRole.addPermission(Permission.MANAGE_REPOSITORIES);
customRole.addPermission(Permission.MANAGE_MEASUREMENTS);
customRole = roleManager.createRole(overlord, customRole);
Set<Permission> customRoleOriginalPermissions = customRole.getPermissions();
assertFalse(customRoleOriginalPermissions.contains(Permission.VIEW_USERS));
Role superuserRole = roleManager.getRole(overlord, 1);
Set<Permission> superuserRoleOriginalPermissions = superuserRole.getPermissions();
assertFalse(superuserRoleOriginalPermissions.contains(Permission.VIEW_USERS));
Role allResourcesRole = roleManager.getRole(overlord, 2);
Set<Permission> allResourcesRoleOriginalPermissions = allResourcesRole.getPermissions();
assertFalse(allResourcesRoleOriginalPermissions.contains(Permission.VIEW_USERS));
// Now upgrade the DB schema to v2.119, which introduces the VIEW_USERS global permission and adds it to any
// existing roles.
DbSetupUtility.dbupgrade("2.119");
customRole = roleManager.getRole(overlord, customRole.getId());
Set<Permission> customRoleNewPermissions = customRole.getPermissions();
customRoleOriginalPermissions.add(Permission.VIEW_USERS);
assertEquals(customRoleOriginalPermissions, customRoleNewPermissions);
superuserRole = roleManager.getRole(overlord, 1);
Set<Permission> superuserRoleNewPermissions = superuserRole.getPermissions();
superuserRoleOriginalPermissions.add(Permission.VIEW_USERS);
assertEquals(superuserRoleOriginalPermissions, superuserRoleNewPermissions);
allResourcesRole = roleManager.getRole(overlord, 2);
Set<Permission> allResourcesRoleNewPermissions = allResourcesRole.getPermissions();
allResourcesRoleOriginalPermissions.add(Permission.VIEW_USERS);
assertEquals(allResourcesRoleOriginalPermissions, allResourcesRoleNewPermissions);
}