949596979899100101102
assertEquals(result.getId(), pm.getId()); } @Test public void testGetInvalidId() { PrivateMessage result = dao.get(-567890L); assertNull(result); }
102103104105106107108109110111112113114115116
} @Test public void testUpdate() { String newBody = "new content"; PrivateMessage pm = getSavedPm(); pm.setBody(newBody); dao.saveOrUpdate(pm); session.flush(); session.evict(pm); PrivateMessage result = (PrivateMessage) session.get(PrivateMessage.class, pm.getId()); assertEquals(result.getBody(), newBody); }
115116117118119120121122123124125126
assertEquals(result.getBody(), newBody); } @Test public void testUpdateNotNullViolation() { PrivateMessage pm = getSavedPm(); pm.setTitle(null); pm.setUserTo(null); pm.setBody(null); dao.saveOrUpdate(pm); }
125126127128129130131132133134135136137
dao.saveOrUpdate(pm); } @Test public void testDelete() { PrivateMessage pm = getSavedPm(); boolean result = dao.delete(pm.getId()); int pmCount = getCount(); assertTrue(result, "Entity is not deleted"); assertEquals(pmCount, 0); }
748749750751752753754755756
/** * Create new PrivateMessage with filled fields and save it. */ private PrivateMessage getSavedPm() throws HibernateException { PrivateMessage pm = PersistedObjectsFactory.getDefaultPrivateMessage(); session.saveOrUpdate(pm); return pm; }