@Test(groups = {"functional"}) public void testBasicCreateUpdateDelete() throws Exception { List<Script> all = dao.findAll(); int originalSize = all.size(); Script entity = DaoTestUtil.createScript(); entity.addStep(DaoTestUtil.createScriptStep()); Script persisted = dao.saveOrUpdate(entity); validate(entity, persisted, false); entity = dao.findById(persisted.getId()); entity = dao.loadScriptSteps(entity); entity.setName("New Workload Name"); persisted = dao.saveOrUpdate(entity); validate(entity, persisted, true); all = dao.findAll(); Assert.assertNotNull(all); Assert.assertEquals(originalSize + 1, all.size()); all = dao.findAll(); Assert.assertNotNull(all); Assert.assertEquals(originalSize + 1, all.size()); // delete it dao.delete(persisted); entity = dao.findById(entity.getId()); Assert.assertNull(entity); all = dao.findAll(); Assert.assertEquals(originalSize, all.size()); }
@Test(groups = {"functional"}) public void testFilter() throws Exception { Calendar calendar = Calendar.getInstance(); Script first = DaoTestUtil.createScript(); first = dao.saveOrUpdate(first); Script third = DaoTestUtil.createScript(); calendar.add(Calendar.DAY_OF_YEAR, -10); // 10 days ago third.setForceCreateDate(calendar.getTime()); third = dao.saveOrUpdate(third); Script second = DaoTestUtil.createScript(); calendar.add(Calendar.DAY_OF_YEAR, 7); // 3 days ago second.setForceCreateDate(calendar.getTime()); second = dao.saveOrUpdate(second); Script fourth = DaoTestUtil.createScript(); calendar.add(Calendar.MONTH, -1); // 1 month and 3 days ago fourth.setForceCreateDate(calendar.getTime()); fourth = dao.saveOrUpdate(fourth); List<Script> list = dao.findAll(); Assert.assertEquals(4, list.size()); Assert.assertEquals(first.getId(), list.get(0).getId()); Assert.assertEquals(second.getId(), list.get(2).getId()); Assert.assertEquals(third.getId(), list.get(1).getId()); Assert.assertEquals(fourth.getId(), list.get(3).getId()); // run our queries list = dao.findFiltered(ViewFilterType.LAST_TWO_WEEKS); Assert.assertEquals(3, list.size()); Assert.assertEquals(first.getId(), list.get(0).getId()); Assert.assertEquals(second.getId(), list.get(1).getId()); list = dao.findFiltered(ViewFilterType.ALL); Assert.assertEquals(4, list.size()); Assert.assertEquals(first.getId(), list.get(0).getId()); Assert.assertEquals(second.getId(), list.get(1).getId()); Assert.assertEquals(third.getId(), list.get(2).getId()); Assert.assertEquals(fourth.getId(), list.get(3).getId()); }