コード例 #1
0
  private Role createRole(String namespaceCode, String name, String kimTypeId) {
    Role.Builder bldr = Role.Builder.create();
    bldr.setNamespaceCode(namespaceCode);
    bldr.setName(name);
    bldr.setKimTypeId(kimTypeId);
    bldr.setActive(true);

    Role fromCreate = this.roleService.createRole(bldr.build());
    assertEquals(namespaceCode, fromCreate.getNamespaceCode());
    assertEquals(name, fromCreate.getName());
    assertEquals(kimTypeId, fromCreate.getKimTypeId());
    assertNotNull(fromCreate.getId());
    assertNotNull(fromCreate.getVersionNumber());
    assertTrue(fromCreate.isActive());
    assertNull(fromCreate.getDescription());

    bldr = Role.Builder.create(fromCreate);
    bldr.setDescription(namespaceCode + " " + name);
    Role fromUpdate = this.roleService.updateRole(bldr.build());
    assertEquals(fromCreate.getNamespaceCode(), fromUpdate.getNamespaceCode());
    assertEquals(fromCreate.getName(), fromUpdate.getName());
    assertEquals(fromCreate.getId(), fromUpdate.getId());
    assertNotSame(fromCreate.getVersionNumber(), fromUpdate.getVersionNumber());
    assertEquals(fromCreate.isActive(), fromUpdate.isActive());
    assertEquals(bldr.getDescription(), fromUpdate.getDescription());

    Role fromGet = this.roleService.getRole(fromUpdate.getId());
    assertEquals(fromUpdate.getNamespaceCode(), fromGet.getNamespaceCode());
    assertEquals(fromUpdate.getName(), fromGet.getName());
    assertEquals(fromUpdate.getKimTypeId(), fromGet.getKimTypeId());
    assertEquals(fromUpdate.getId(), fromGet.getId());
    assertEquals(fromUpdate.getVersionNumber(), fromGet.getVersionNumber());
    assertEquals(fromUpdate.isActive(), fromGet.isActive());
    assertEquals(fromUpdate.getDescription(), fromGet.getDescription());

    Role fromFind = this.roleService.getRoleByNamespaceCodeAndName(namespaceCode, name);
    assertEquals(fromUpdate.getNamespaceCode(), fromFind.getNamespaceCode());
    assertEquals(fromUpdate.getName(), fromFind.getName());
    assertEquals(fromUpdate.getKimTypeId(), fromFind.getKimTypeId());
    assertEquals(fromUpdate.getId(), fromFind.getId());
    assertEquals(fromUpdate.getVersionNumber(), fromFind.getVersionNumber());
    assertEquals(fromUpdate.isActive(), fromFind.isActive());
    assertEquals(fromUpdate.getDescription(), fromFind.getDescription());

    // TODO: test update

    return fromFind;
  }
コード例 #2
0
 private RoleMember assignPrincipal2Role(String principalId, Role role, String subjArea) {
   Map<String, String> qualifiers = new LinkedHashMap<String, String>();
   if (subjArea != null) {
     qualifiers.put(KimPermissionConstants.SUBJECT_AREA_ATTR_DEFINITION, subjArea);
   }
   RoleMember roleMember =
       this.roleService.assignPrincipalToRole(
           principalId, role.getNamespaceCode(), role.getName(), qualifiers);
   assertEquals(principalId, roleMember.getMemberId());
   assertEquals(role.getId(), roleMember.getRoleId());
   assertEquals(KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, roleMember.getType());
   assertEquals(qualifiers, roleMember.getAttributes());
   List<String> roleIds =
       this.roleService.getMemberParentRoleIds(
           KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode(), principalId);
   //        assertEquals(1, roleIds.size());
   assertTrue(roleIds.contains(role.getId()));
   return roleMember;
 }