Example #1
0
  @Test
  public void testAddGroups() throws Exception {
    String name = "addGroups" + r.nextInt();

    UserWrapper user = UserHelper.addUser(name, null, true);

    Assert.assertEquals(0, user.getGroupCollection(false).size());

    GroupWrapper group1 = GroupHelper.addGroup(name + "_1", true);
    GroupWrapper group2 = GroupHelper.addGroup(name + "_2", true);

    user.addToGroupCollection(Arrays.asList(group1, group2));
    user.persist();

    user.reload();
    group1.reload();
    group2.reload();
    Assert.assertEquals(2, user.getGroupCollection(false).size());
    Assert.assertEquals(1, group1.getUserCollection(false).size());
    Assert.assertEquals(1, group2.getUserCollection(false).size());
  }
Example #2
0
  @Test
  public void testDeleteWhenHasGroupRelation() throws Exception {
    String name = "deleteWhenHasGroupRelation" + r.nextInt();
    UserWrapper user1 = UserHelper.addUser(name + "_1", null, false);
    UserWrapper user2 = UserHelper.addUser(name + "_2", null, true);

    GroupWrapper group = GroupHelper.addGroup(name, true);
    group.addToUserCollection(Arrays.asList(user1, user2));
    group.persist();
    user1.reload();
    user2.reload();

    Assert.assertEquals(2, group.getUserCollection(false).size());

    // deletedependencies should remove the relation in the correlation
    // table
    user1.delete();

    group.reload();
    Assert.assertEquals(1, group.getUserCollection(false).size());
  }