private FileItem generateTestContent(String name, String owner) throws Exception { FileItem content = new HibFileItem(); content.setName(name); content.setDisplayName(name); content.setContent(helper.getBytes("testdata1.txt")); content.setContentLanguage("en"); content.setContentEncoding("UTF8"); content.setContentType("text/text"); content.setOwner(getUser(userDao, owner)); content.addAttribute( new HibStringAttribute(new HibQName("customattribute"), "customattributevalue")); return content; }
public void testContentDaoUpdateContent() throws Exception { User user = getUser(userDao, "testuser"); CollectionItem root = (CollectionItem) contentDao.getRootItem(user); FileItem item = generateTestContent(); ContentItem newItem = contentDao.createContent(root, item); Date newItemModifyDate = newItem.getModifiedDate(); clearSession(); FileItem queryItem = (FileItem) contentDao.findContentByUid(newItem.getUid()); helper.verifyItem(newItem, queryItem); Assert.assertEquals(0, queryItem.getVersion().intValue()); queryItem.setName("test2"); queryItem.setDisplayName("this is a test item2"); queryItem.removeAttribute("customattribute"); queryItem.setContentLanguage("es"); queryItem.setContent(helper.getBytes("testdata2.txt")); // Make sure modified date changes Thread.sleep(1000); queryItem = (FileItem) contentDao.updateContent(queryItem); clearSession(); ContentItem queryItem2 = contentDao.findContentByUid(newItem.getUid()); Assert.assertTrue(queryItem2.getVersion().intValue() > 0); helper.verifyItem(queryItem, queryItem2); Assert.assertTrue(newItemModifyDate.before(queryItem2.getModifiedDate())); }