@Test public void testCreate() { Company cm = new Company(); cm.setName("Windy"); cm.setProductName("Root"); cm.setProductType("Beer"); tx.begin(); em.persist(cm); tx.commit(); assertNotNull(cm.getId()); }
@Test @Ignore public void testDelete() { TypedQuery<Company> cb = em.createQuery("select cb from Company cb where cb.name = ?1", Company.class); cb.setParameter(1, "Pepsico"); Company c = cb.getSingleResult(); assertNotNull(c.getId()); tx.begin(); for (Products d : c.getProducts()) { em.remove(d); } em.remove(c); tx.commit(); Company postRemove = em.find(Company.class, 1L); assertNull(postRemove); }
@Test public void testUpdate() { Company cp = em.createNamedQuery("Company.findByName", Company.class) .setParameter("name", "Windy") .getSingleResult(); assertNotNull(cp.getId()); String originalName = cp.getName(); String newName = "Chicago Beverage"; tx.begin(); cp.setName(newName); tx.commit(); assertNotEquals(originalName, cp.getName()); assertTrue(newName.equals(cp.getName())); tx.begin(); cp.setName(originalName); tx.commit(); }