1 18 23 24 package org.apache.roller.business; 25 26 import java.util.List ; 27 import junit.framework.Test; 28 import junit.framework.TestCase; 29 import junit.framework.TestSuite; 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 import org.apache.roller.TestUtils; 33 import org.apache.roller.model.RollerFactory; 34 import org.apache.roller.model.WeblogManager; 35 import org.apache.roller.pojos.CommentData; 36 import org.apache.roller.pojos.UserData; 37 import org.apache.roller.pojos.WeblogEntryData; 38 import org.apache.roller.pojos.WebsiteData; 39 40 41 46 public class CommentTest extends TestCase { 47 48 public static Log log = LogFactory.getLog(CommentTest.class); 49 50 UserData testUser = null; 51 WebsiteData testWeblog = null; 52 WeblogEntryData testEntry = null; 53 54 55 public CommentTest(String name) { 56 super(name); 57 } 58 59 60 public static Test suite() { 61 return new TestSuite(CommentTest.class); 62 } 63 64 65 68 public void setUp() throws Exception { 69 70 try { 71 testUser = TestUtils.setupUser("commentTestUser"); 72 testWeblog = TestUtils.setupWeblog("commentTestWeblog", testUser); 73 testEntry = TestUtils.setupWeblogEntry("commentTestEntry", testWeblog.getDefaultCategory(), testWeblog, testUser); 74 TestUtils.endSession(true); 75 } catch (Exception ex) { 76 log.error(ex); 77 throw new Exception ("Test setup failed", ex); 78 } 79 } 80 81 public void tearDown() throws Exception { 82 83 try { 84 TestUtils.teardownWeblogEntry(testEntry.getId()); 85 TestUtils.teardownWeblog(testWeblog.getId()); 86 TestUtils.teardownUser(testUser.getId()); 87 TestUtils.endSession(true); 88 } catch (Exception ex) { 89 log.error(ex); 90 throw new Exception ("Test teardown failed", ex); 91 } 92 } 93 94 95 98 public void testCommentCRUD() throws Exception { 99 100 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 101 102 CommentData comment = new CommentData(); 103 comment.setName("test"); 104 comment.setEmail("test"); 105 comment.setUrl("test"); 106 comment.setRemoteHost("foofoo"); 107 comment.setContent("this is a test comment"); 108 comment.setPostTime(new java.sql.Timestamp (new java.util.Date ().getTime())); 109 comment.setWeblogEntry(testEntry); 110 comment.setPending(Boolean.FALSE); 111 comment.setApproved(Boolean.TRUE); 112 113 mgr.saveComment(comment); 115 String id = comment.getId(); 116 TestUtils.endSession(true); 117 118 comment = null; 120 comment = mgr.getComment(id); 121 assertNotNull(comment); 122 assertEquals("this is a test comment", comment.getContent()); 123 124 comment.setContent("testtest"); 126 mgr.saveComment(comment); 127 TestUtils.endSession(true); 128 129 comment = null; 131 comment = mgr.getComment(id); 132 assertNotNull(comment); 133 assertEquals("testtest", comment.getContent()); 134 135 mgr.removeComment(comment); 137 TestUtils.endSession(true); 138 139 comment = null; 141 comment = mgr.getComment(id); 142 assertNull(comment); 143 } 144 145 146 149 public void testCommentLookups() throws Exception { 150 151 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 152 List comments = null; 153 154 CommentData comment1 = TestUtils.setupComment("comment1", testEntry); 156 CommentData comment2 = TestUtils.setupComment("comment2", testEntry); 157 CommentData comment3 = TestUtils.setupComment("comment3", testEntry); 158 TestUtils.endSession(true); 159 160 comments = null; 162 comments = mgr.getComments(null, null, null, null, null, null, null, null, false, 0, -1); 163 assertNotNull(comments); 164 assertEquals(3, comments.size()); 165 166 comments = null; 168 comments = mgr.getComments(null, testEntry, null, null, null, null, null, null, false, 0, -1); 169 assertNotNull(comments); 170 assertEquals(3, comments.size()); 171 172 comment3.setPending(Boolean.TRUE); 174 comment3.setApproved(Boolean.FALSE); 175 mgr.saveComment(comment3); 176 177 comments = null; 179 comments = mgr.getComments(null, null, null, null, null, Boolean.TRUE, null, null, false, 0, -1); 180 assertNotNull(comments); 181 assertEquals(1, comments.size()); 182 183 comments = null; 185 comments = mgr.getComments(null, null, null, null, null, null, Boolean.TRUE, null, false, 0, -1); 186 assertNotNull(comments); 187 assertEquals(2, comments.size()); 188 189 comments = null; 191 comments = mgr.getComments(null, null, null, null, null, null, null, null, false, 1, -1); 192 assertNotNull(comments); 193 assertEquals(2, comments.size()); 194 195 TestUtils.teardownComment(comment1.getId()); 197 TestUtils.teardownComment(comment2.getId()); 198 TestUtils.teardownComment(comment3.getId()); 199 TestUtils.endSession(true); 200 } 201 202 203 206 242 } 243 | Popular Tags |