public class TestContentDao extends BaseDaoTestCase { public void testCreateAndStoreContent() { // create a new Content object and store it in the backend Report bc = new Report(); String body = "eins zwei drei"; bc.setBody(body); String title = "Some Title"; String teaser = "Some Teaser..."; Attachment att1 = DataFactory.makeAttachment("image/jpeg", "foo.jpg", 1000); Attachment att2 = DataFactory.makeAttachment("image/png", "bar.png", 500); Attachment att3 = DataFactory.makeAttachment("image/gif", "baz.gif", 50); Set atts = DataFactory.makeAttachments(att1, att2, att3); Content content = DataFactory.makeContent(title, teaser, bc, atts); content.setTeaserImageId(att1.getId()); getContentDao().saveContent(content); flushSession(); long id = content.getId(); // load the new content object from dao Content storedContent = getContentDao().getContent(id); assertNotNull("getContent failed!", storedContent); assertEquals("ids mismatch!", id, storedContent.getId()); assertEquals("title mismatch", title, storedContent.getTitle()); assertEquals("teaserImageID mismatch", att1.getId(), storedContent.getTeaserImageId()); assertEquals("teaser mismatch", teaser, storedContent.getTeaser()); assertNotNull("contentData is null", storedContent.getData()); assertEquals("contentData mismatch", body, ((Report) storedContent.getData()).getBody()); // test attachment assertEquals("attachments length mismatch", atts.size(), storedContent.getAttachments().size()); } }