String id;
@Test
public void testDynaRoles() throws Exception {
IRoleService roleService = getRoleService();
IDynamicRoleMetaInfo dynaMeta = roleService.getDynamicRoleImpl("com.jresearchsoft.flexess.examples.orders"); //$NON-NLS-1$
dynaMeta.setName("superadm"); //$NON-NLS-1$
dynaMeta = roleService.saveDynamicRole(dynaMeta);
id = dynaMeta.getId();
IPermissionService permService = getPermissionService();
List<IPermissionMetaInfo> perms = permService.getPermissions("com.jresearchsoft.flexess.examples.orders"); //$NON-NLS-1$
for (IPermissionMetaInfo info : perms) {
roleService.addPermission(dynaMeta.getId(), info.getId());
}
dynaMeta = roleService.getDynamicRole(id);
dynaMeta.setName("superAdmmm"); //$NON-NLS-1$
// roleService.saveDynamicRole(dynaMeta);
List<IDynamicRoleMetaInfo> roles = roleService.getDynamicRoles("com.jresearchsoft.flexess.examples.orders"); //$NON-NLS-1$
assertEquals(1, roles.size());
dynaMeta = roles.get(0);
// assertEquals(dynaMeta.getName(), "superAdmmm"); //$NON-NLS-1$
assertEquals(dynaMeta.getName(), "superadm"); //$NON-NLS-1$
List<IRoleMetaInfo> roles2 = roleService.getAllRoles("com.jresearchsoft.flexess.examples.orders"); //$NON-NLS-1$
assertEquals(4, roles2.size());
IRoleInstanceService roleInstService = getRoleInstService();
assertNotNull(roleInstService);
IPermissionInstanceService permissionService = getPermissionInstanceService();
assertNotNull(permissionService);
IRoleInstanceMetaInfo rm = roleInstService.getRoleInstanceImpl("com.jresearchsoft.flexess.examples.orders"); //$NON-NLS-1$
rm.setName("super administrator"); //$NON-NLS-1$
rm.setRoleId(dynaMeta.getId());
List<IPermissionInstanceMetaInfo> permInstances = permissionService.getPermissionInstances();
for (IPermissionInstanceMetaInfo info : permInstances) {
rm.addPermissionInstance(info);
}
rm = roleInstService.saveRoleInstance(rm);
// getUserRoleService().addUserRole("cathy", rm);
roleService.deleteRole("com.jresearchsoft.flexess.examples.orders", dynaMeta.getId()); //$NON-NLS-1$
}