Beispiel #1
0
  @Test
  public void testAddMembershipsWithPermission() throws Exception {
    String name = "testAddMembershipsWithPermission" + r.nextInt();
    UserWrapper user = UserHelper.addUser(name, null, true);

    MembershipWrapper ms = MembershipHelper.newMembership(user, null, null);
    ms.addToPermissionCollection(Arrays.asList(PermissionEnum.CLINIC_CREATE));
    user.persist();

    user.reload();
    Assert.assertEquals(1, user.getMembershipCollection(false).size());
    ms = user.getMembershipCollection(false).get(0);
    Assert.assertEquals(1, ms.getPermissionCollection().size());
  }
Beispiel #2
0
  @Test
  public void testAddMembershipsWithRole() throws Exception {
    String name = "addMembershipsWithRole" + r.nextInt();
    UserWrapper user = UserHelper.addUser(name, null, true);

    RoleWrapper role = RoleHelper.addRole(name, true);

    MembershipWrapper ms = MembershipHelper.newMembership(user, null, null);
    ms.addToRoleCollection(Arrays.asList(role));
    user.persist();

    user.reload();
    Assert.assertEquals(1, user.getMembershipCollection(false).size());
    ms = user.getMembershipCollection(false).get(0);
    Assert.assertEquals(1, ms.getRoleCollection(false).size());
  }
Beispiel #3
0
  @Test
  public void testRemoveMembershipWithRole() throws Exception {
    String name = "removeMembershipWithRole" + r.nextInt();
    UserWrapper user = UserHelper.addUser(name, null, true);

    RoleWrapper role = RoleHelper.addRole(name, true);
    MembershipWrapper mwr = MembershipHelper.newMembership(user, null, null);
    mwr.addToRoleCollection(Arrays.asList(role));
    user.persist();

    user.reload();
    Assert.assertEquals(1, user.getMembershipCollection(false).size());

    mwr = user.getMembershipCollection(false).get(0);
    Integer mwrId = mwr.getId();
    user.removeFromMembershipCollection(Arrays.asList(mwr));
    user.persist();
    user.reload();
    Assert.assertEquals(0, user.getMembershipCollection(false).size());

    Membership msDB = ModelUtils.getObjectWithId(appService, Membership.class, mwrId);
    Assert.assertNull(msDB);
  }