/** Test changing group. */
  @Test
  public void testModifyGroup() throws Exception {
    System.out.println(">>> Modifying group");
    UserTransaction tx = getUserTransaction();
    try {
      AdminEJBLocal instance = (AdminEJBLocal) getEJBInstance(AdminEJB.class.getSimpleName());
      tx.begin();
      // Get group
      Group group = instance.getGroup(GROUP_ID);
      if (group != null) {
        group.getGroupRoles();
      }
      tx.commit();

      assertNotNull("Failed to get group", group);
      assertNotNull("Group name is null", group.getName());
      assertNotNull("Group description is null", group.getDescription());
      assertNotNull("Group roles is null", group.getGroupRoles());
      int rolesSize = group.getGroupRoles().size();

      group.setEntityAction(EntityAction.UPDATE);

      if (rolesSize > 1) {
        group.getGroupRoles().get(0).setEntityAction(EntityAction.DELETE);
        rolesSize -= 1;
      }

      group.setName("Updated Test group");
      group.setDescription("Updated description for group");

      tx.begin();
      Group updatedGroup = instance.saveGroup(group);
      tx.commit();

      // Re-read group
      tx.begin();
      updatedGroup = instance.getGroup(GROUP_ID);
      if (updatedGroup != null) {
        updatedGroup.getGroupRoles();
      }
      tx.commit();

      assertNotNull("Failed to get modified group", updatedGroup);
      assertEquals("Group name wasn't modified", updatedGroup.getName(), group.getName());
      assertEquals(
          "Group description wasn't modified",
          updatedGroup.getDescription(),
          group.getDescription());
      assertNotNull("Modified group roles is null", group.getGroupRoles());
      assertEquals("Group roles wasn't modified", updatedGroup.getGroupRoles().size(), rolesSize);

      System.out.println(">>> Group has been modified!");

    } catch (Exception e) {
      tx.rollback();
      fail(e.getMessage());
    }
  }