private void doTestAdd() throws Exception {
    userGroup = mgr.find(UserGroup.class, userGroup.getKey());
    p = mgr.find(Product.class, p.getKey());

    UserGroupToInvisibleProduct uip = new UserGroupToInvisibleProduct();
    uip.setUserGroup(userGroup);
    uip.setProduct(p);

    mgr.persist(uip);
  }
  private void doTestAddCheck() {
    Product product = mgr.find(Product.class, p.getKey());
    assertNotNull("Product expected", product);

    assertNotNull(product.getUserGroupToInvisibleProducts());
    List<UserGroupToInvisibleProduct> uguList = product.getUserGroupToInvisibleProducts();
    Assert.assertEquals(1, uguList.size());

    UserGroupToInvisibleProduct ugu = uguList.get(0);
    Assert.assertEquals(userGroup, ugu.getUserGroup());
    Assert.assertEquals(p, ugu.getProduct());
  }
  private void doTestDeleteCheckByUserGroup() {
    // UserGroup must be deleted
    UserGroup ug = mgr.find(UserGroup.class, userGroup.getKey());
    Assert.assertNull("UserGroup still available", ug);

    // UserGroupToInvisibleProduct must be deleted
    UserGroupToInvisibleProduct userGroupToInvisibleProduct =
        mgr.find(UserGroupToInvisibleProduct.class, oldUserGroupToInvisibleProduct.getKey());
    Assert.assertNull("UserGroupToInvisibleProduct still available", userGroupToInvisibleProduct);
  }
  private void doTestDeleteCheckByProduct() {
    // Product must be deleted
    Product pu = mgr.find(Product.class, oldproduct.getKey());
    Assert.assertNull("Product still available", pu);

    // UserGroupToInvisibleProduct must be deleted
    UserGroupToInvisibleProduct userGroupToInvisibleProduct =
        mgr.find(UserGroupToInvisibleProduct.class, oldUserGroupToInvisibleProduct.getKey());
    Assert.assertNull("UserGroupToInvisibleProduct still available", userGroupToInvisibleProduct);
  }