@Test
public void testCreateDelete()
throws Exception
{
final Product p = new Product();
p.setTitle("test");
new FacesRequest() {
protected void invokeApplication()
{
EntityManager em = (EntityManager) getValue("#{entityManager}");
em.persist(p);
}
}.run();
new FacesRequest() {
protected void invokeApplication()
{
EntityManager em = (EntityManager) getValue("#{entityManager}");
Product found = em.find(Product.class ,p.getProductId());
assertNotNull("find by id", found);
assertEquals("id", p.getProductId(), found.getProductId());
assertEquals("title", "test", found.getTitle());
em.remove(found);
}
}.run();
new FacesRequest() {
protected void invokeApplication()
{
EntityManager em = (EntityManager) getValue("#{entityManager}");
Product found = em.find(Product.class ,p.getProductId());
assertNull("deleted product", found);
}
}.run();