@Test
public void deleteMessageUnit() throws PersistenceException {

    // First create some records
    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;
        // Count number of message units left
        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) {
            // Okay
        }
    }
}