/** * TODO - Remove this sample unit test Test method for {@link * org.sakaiproject.crudplus.dao.impl.GenericHibernateDao#save(java.lang.Object)}. */ public void testSave() { CrudPlusItem item1 = new CrudPlusItem("New item1", ITEM_OWNER, ITEM_SITE, ITEM_HIDDEN, new Date()); dao.save(item1); Long itemId = item1.getId(); Assert.assertNotNull(itemId); Assert.assertEquals(dao.countAll(CrudPlusItem.class), 3); }
// run this before each test starts and as part of the transaction protected void onSetUpInTransaction() { // load the spring created dao class bean from the Spring Application Context dao = (CrudPlusDao) applicationContext.getBean("org.sakaiproject.crudplus.dao.CrudPlusDao"); if (dao == null) { log.error("onSetUpInTransaction: DAO could not be retrieved from spring context"); } // init the class if needed // check the preloaded data Assert.assertTrue("Error preloading data", dao.countAll(CrudPlusItem.class) > 0); // preload data if desired dao.save(item); }
/** * TODO - Remove this sample unit test Test method for {@link * org.sakaiproject.crudplus.dao.impl.GenericHibernateDao#delete(java.lang.Object)}. */ public void testDelete() { Assert.assertEquals(dao.countAll(CrudPlusItem.class), 2); dao.delete(item); Assert.assertEquals(dao.countAll(CrudPlusItem.class), 1); }