### Question:
JPAWorkItemHandler extends AbstractLogOrThrowWorkItemHandler implements Cacheable { public void close() { emf.close(); } JPAWorkItemHandler(String persistenceUnit);  JPAWorkItemHandler(String persistenceUnit,
                              ClassLoader classloader); void executeWorkItem(WorkItem wi,
                                WorkItemManager wim); void close(); void abortWorkItem(WorkItem wi,
                              WorkItemManager wim); static final String P_RESULT; static final String P_TYPE; static final String P_ID; static final String P_ENTITY; static final String P_ACTION; static final String P_QUERY; static final String P_QUERY_PARAMS; static final String P_QUERY_RESULTS; static final String CREATE_ACTION; static final String UPDATE_ACTION; static final String GET_ACTION; static final String DELETE_ACTION; static final String QUERY_ACTION; }### Answer:
@Test public void createOnProcessTest() throws Exception { String DESC = "Table"; Product p = new Product(DESC, 10f); startJPAWIHProcess(JPAWorkItemHandler.CREATE_ACTION, p); UserTransaction ut = getUserTransaction(); ut.begin(); EntityManager em = emf.createEntityManager(); TypedQuery<Product> products = em.createQuery("select p from Product p where p.description = :desc", Product.class); products.setParameter("desc", DESC); List<Product> resultList = products.getResultList(); Product result = resultList.iterator().next(); assertEquals(DESC, result.getDescription()); em.remove(result); em.flush(); em.close(); ut.commit(); }
@Test public void removeOnProcessTest() throws Exception { Product p = new Product("A Product", 10f); ut.begin(); EntityManager em = emf.createEntityManager(); em.persist(p); long id = p.getId(); em.close(); ut.commit(); startJPAWIHProcess(JPAWorkItemHandler.DELETE_ACTION, p); ut.begin(); em = emf.createEntityManager(); p = em.find(Product.class, id); assertNull(p); ut.commit(); }
@Test public void updateOnProcessTest() throws Exception { String DESC = "Table"; String NEW_DESC = "Red Table"; Product p = new Product(DESC, 10f); ut.begin(); EntityManager em = emf.createEntityManager(); em.persist(p); long id = p.getId(); em.close(); ut.commit(); p.setDescription(NEW_DESC); startJPAWIHProcess(JPAWorkItemHandler.UPDATE_ACTION, p); ut.begin(); em = emf.createEntityManager(); p = em.find(Product.class, id); assertEquals(p.getDescription(), NEW_DESC); ut.commit(); removeProduct(p); }