UpdateManager implements IUpdateManager { @Override public void deleteMessageUnit(final IMessageUnitEntity messageUnit) throws PersistenceException { EntityManager em = null; EntityTransaction tx = null; try { em = EntityManagerUtil.getEntityManager(); tx = em.getTransaction(); tx.begin(); MessageUnit jpaMsgUnit = em.find(MessageUnit.class, ((MessageUnitEntity) messageUnit).getOID()); em.remove(jpaMsgUnit); tx.commit(); } catch (final Exception e) { if (tx!=null && tx.isActive()) { tx.rollback(); } throw new PersistenceException("An error occurred in the update of the message unit meta-data!", e); }finally { em.close(); } }  @Override V storeMessageUnit(final T messageUnit); @Override boolean setProcessingState(final IMessageUnitEntity msgUnit, final ProcessingState currentProcState,
                                      final ProcessingState newProcState); @Override boolean setProcessingState(final IMessageUnitEntity msgUnit, final ProcessingState currentProcState,
                                      final ProcessingState newProcState, final String description); @Override void deleteMessageUnit(final IMessageUnitEntity messageUnit); @Override void setPModeId(final IMessageUnitEntity msgUnit, final String pmodeId); @Override void setMultiHop(final IMessageUnitEntity msgUnit, final boolean isMultihop); @Override void setPayloadInformation(final IUserMessageEntity userMessage, final Collection<IPayload> payloadInfo); @Override void setAddSOAPFault(final IErrorMessageEntity errorMessage, final boolean addSOAPFault);  }
@Test public void deleteMessageUnit() throws PersistenceException { TestData.createTestSet(); em.getTransaction().begin(); final List<MessageUnitEntity> allMsgUnits = JPAEntityHelper.wrapInEntity(em.createQuery("from MessageUnit", MessageUnit.class) .getResultList()); assertFalse(Utils.isNullOrEmpty(allMsgUnits)); int totalMsgUnits = allMsgUnits.size(); int numberDeleted = 0; for(MessageUnitEntity msgUnit : allMsgUnits) { updManager.deleteMessageUnit(msgUnit); numberDeleted += 1; long currentCount = em.createQuery("select count(*) from MessageUnit", Long.class).getSingleResult(); assertEquals(totalMsgUnits - numberDeleted, currentCount); try { em.refresh((em.find(MessageUnit.class, msgUnit.getOID()))); fail("MessageUnit not removed"); } catch (EntityNotFoundException removed) { } } }