Author: agilliland
Date: Wed Apr 12 16:10:14 2006
New Revision: 393647

URL: http://svn.apache.org/viewcvs?rev=393647&view=rev
Log:
adding unit tests for comments.


Added:
    
incubator/roller/branches/roller-newbackend/tests/org/roller/business/CommentTest.java
Modified:
    incubator/roller/branches/roller-newbackend/build.xml
    incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java
    
incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogEntryTest.java

Modified: incubator/roller/branches/roller-newbackend/build.xml
URL: 
http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/build.xml?rev=393647&r1=393646&r2=393647&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/build.xml (original)
+++ incubator/roller/branches/roller-newbackend/build.xml Wed Apr 12 16:10:14 
2006
@@ -824,6 +824,7 @@
               <include name="org/roller/business/PropertiesTest.class"/>
               <include name="org/roller/business/WeblogEntryTest.class"/>
               <include name="org/roller/business/FileManagerTest.class"/>
+              <include name="org/roller/business/CommentTest.class"/>
             </fileset>
         </batchtest>
     </junit>

Modified: 
incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java
URL: 
http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java?rev=393647&r1=393646&r2=393647&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java 
(original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java 
Wed Apr 12 16:10:14 2006
@@ -12,6 +12,7 @@
 import org.roller.model.UserManager;
 import org.roller.model.WeblogManager;
 import org.roller.pojos.AutoPingData;
+import org.roller.pojos.CommentData;
 import org.roller.pojos.PingTargetData;
 import org.roller.pojos.UserData;
 import org.roller.pojos.WeblogEntryData;
@@ -159,6 +160,48 @@
         
         // remove the entry
         mgr.removeWeblogEntry(entry);
+    }
+    
+    
+    /**
+     * Convenience method for creating a comment.
+     */
+    public static CommentData setupComment(String content, WeblogEntryData 
entry)
+            throws Exception {
+        
+        CommentData testComment = new CommentData();
+        testComment.setName("test");
+        testComment.setEmail("test");
+        testComment.setUrl("test");
+        testComment.setRemoteHost("foofoo");
+        testComment.setContent("this is a test comment");
+        testComment.setPostTime(new java.sql.Timestamp(new 
java.util.Date().getTime()));
+        testComment.setWeblogEntry(entry);
+        testComment.setPending(Boolean.FALSE);
+        testComment.setApproved(Boolean.TRUE);
+        
+        // store testComment
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        mgr.saveComment(testComment);
+        
+        // query for object
+        CommentData comment = mgr.retrieveComment(testComment.getId());
+        
+        if(comment == null)
+            throw new RollerException("error setting up comment");
+        
+        return comment;
+    }
+    
+    
+    /**
+     * Convenience method for removing a comment.
+     */
+    public static void teardownComment(String id) throws Exception {
+        
+        // remove the comment
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        mgr.removeComment(id);
     }
     
     

Added: 
incubator/roller/branches/roller-newbackend/tests/org/roller/business/CommentTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/CommentTest.java?rev=393647&view=auto
==============================================================================
--- 
incubator/roller/branches/roller-newbackend/tests/org/roller/business/CommentTest.java
 (added)
+++ 
incubator/roller/branches/roller-newbackend/tests/org/roller/business/CommentTest.java
 Wed Apr 12 16:10:14 2006
@@ -0,0 +1,213 @@
+/*
+ * CommentTest.java
+ *
+ * Created on April 12, 2006, 3:12 PM
+ */
+
+package org.roller.business;
+
+import java.util.List;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.TestUtils;
+import org.roller.model.RollerFactory;
+import org.roller.model.WeblogManager;
+import org.roller.pojos.CommentData;
+import org.roller.pojos.UserData;
+import org.roller.pojos.WeblogEntryData;
+import org.roller.pojos.WebsiteData;
+
+
+/**
+ * Test Comment related business operations.
+ *
+ * That includes:
+ */
+public class CommentTest extends TestCase {
+    
+    public static Log log = LogFactory.getLog(CommentTest.class);
+    
+    UserData testUser = null;
+    WebsiteData testWeblog = null;
+    WeblogEntryData testEntry = null;
+    
+    
+    public CommentTest(String name) {
+        super(name);
+    }
+    
+    
+    public static Test suite() {
+        return new TestSuite(CommentTest.class);
+    }
+    
+    
+    /**
+     * All tests in this suite require a user, weblog, and an entry.
+     */
+    public void setUp() throws Exception {
+        
+        try {
+            testUser = TestUtils.setupUser("entryTestUser");
+            testWeblog = TestUtils.setupWeblog("entryTestWeblog", testUser);
+            testEntry = TestUtils.setupWeblogEntry("testEntry", testWeblog, 
testUser);
+        } catch (Exception ex) {
+            log.error(ex);
+        }
+    }
+    
+    public void tearDown() throws Exception {
+        
+        try {
+            TestUtils.teardownWeblogEntry(testEntry.getId());
+            TestUtils.teardownWeblog(testWeblog.getHandle());
+            TestUtils.teardownUser(testUser.getUserName());
+        } catch (Exception ex) {
+            log.error(ex);
+        }
+    }
+    
+    
+    /**
+     * Test basic persistence operations ... Create, Update, Delete
+     */
+    public void testCommentCRUD() throws Exception {
+        
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        
+        CommentData comment = new CommentData();
+        comment.setName("test");
+        comment.setEmail("test");
+        comment.setUrl("test");
+        comment.setRemoteHost("foofoo");
+        comment.setContent("this is a test comment");
+        comment.setPostTime(new java.sql.Timestamp(new 
java.util.Date().getTime()));
+        comment.setWeblogEntry(testEntry);
+        comment.setPending(Boolean.FALSE);
+        comment.setApproved(Boolean.TRUE);
+        
+        // create a comment
+        mgr.saveComment(comment);
+        String id = comment.getId();
+        
+        // make sure comment was created
+        comment = null;
+        comment = mgr.retrieveComment(id);
+        assertNotNull(comment);
+        assertEquals("this is a test comment", comment.getContent());
+        
+        // update a comment
+        comment.setContent("testtest");
+        mgr.saveComment(comment);
+        
+        // make sure comment was updated
+        comment = null;
+        comment = mgr.retrieveComment(id);
+        assertNotNull(comment);
+        assertEquals("testtest", comment.getContent());
+        
+        // delete a comment
+        mgr.removeComment(id);
+        
+        // make sure comment was deleted
+        comment = null;
+        comment = mgr.retrieveComment(id);
+        assertNull(comment);
+    }
+    
+    
+    /**
+     * Test lookup mechanisms ... 
+     */
+    public void testCommentLookups() throws Exception {
+        
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        List comments = null;
+        
+        // we need some comments to play with
+        CommentData comment1 = TestUtils.setupComment("comment1", testEntry);
+        CommentData comment2 = TestUtils.setupComment("comment2", testEntry);
+        CommentData comment3 = TestUtils.setupComment("comment3", testEntry);
+        
+        // get all comments
+        comments = null;
+        comments = mgr.getComments(null, null, null, null, null, null, null, 
null, false, 0, -1);
+        assertNotNull(comments);
+        assertEquals(3, comments.size());
+        
+        // get all comments for entry
+        comments = null;
+        comments = mgr.getComments(null, testEntry, null, null, null, null, 
null, null, false, 0, -1);
+        assertNotNull(comments);
+        assertEquals(3, comments.size());
+        
+        // make some changes
+        comment3.setPending(Boolean.TRUE);
+        comment3.setApproved(Boolean.FALSE);
+        mgr.saveComment(comment3);
+        
+        // get pending comments
+        comments = null;
+        comments = mgr.getComments(null, null, null, null, null, Boolean.TRUE, 
null, null, false, 0, -1);
+        assertNotNull(comments);
+        assertEquals(1, comments.size());
+        
+        // get approved comments
+        comments = null;
+        comments = mgr.getComments(null, null, null, null, null, null, 
Boolean.TRUE, null, false, 0, -1);
+        assertNotNull(comments);
+        assertEquals(2, comments.size());
+        
+        // get comments with offset
+        comments = null;
+        comments = mgr.getComments(null, null, null, null, null, null, null, 
null, false, 1, -1);
+        assertNotNull(comments);
+        assertEquals(2, comments.size());
+        
+        // remove test comments
+        TestUtils.teardownComment(comment1.getId());
+        TestUtils.teardownComment(comment2.getId());
+        TestUtils.teardownComment(comment3.getId());
+    }
+    
+    
+    /**
+     * Test extra CRUD methods ... removeComments(ids), removeCommentsForEntry
+     */
+    public void testAdvancedCommentCRUD() throws Exception {
+        
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        List comments = null;
+        
+        // we need some comments to play with
+        CommentData comment1 = TestUtils.setupComment("comment1", testEntry);
+        CommentData comment2 = TestUtils.setupComment("comment2", testEntry);
+        CommentData comment3 = TestUtils.setupComment("comment3", testEntry);
+        CommentData comment4 = TestUtils.setupComment("comment4", testEntry);
+        
+        // remove a collection of comments
+        String[] delComments = new String[2];
+        delComments[0] = comment1.getId();
+        delComments[1] = comment2.getId();
+        mgr.removeComments(delComments);
+        
+        // make sure comments were deleted
+        comments = null;
+        comments = mgr.getComments(null, null, null, null, null, null, null, 
null, false, 0, -1);
+        assertNotNull(comments);
+        assertEquals(2, comments.size());
+        
+        // remove all comments for entry
+        mgr.removeCommentsForEntry(testEntry.getId());
+        
+        // make sure comments were deleted
+        comments = null;
+        comments = mgr.getComments(null, null, null, null, null, null, null, 
null, false, 0, -1);
+        assertNotNull(comments);
+        assertEquals(0, comments.size());
+    }
+    
+}

Modified: 
incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogEntryTest.java
URL: 
http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogEntryTest.java?rev=393647&r1=393646&r2=393647&view=diff
==============================================================================
--- 
incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogEntryTest.java
 (original)
+++ 
incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogEntryTest.java
 Wed Apr 12 16:10:14 2006
@@ -81,6 +81,9 @@
     }
     
     
+    /**
+     * Test basic persistence operations ... Create, Update, Delete
+     */
     public void testWeblogEntryCRUD() throws Exception {
         
         WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
@@ -115,6 +118,9 @@
     }
     
     
+    /**
+     * Test lookup mechanisms ... 
+     */
     public void testWeblogEntryLookups() throws Exception {
         
         WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
@@ -250,6 +256,9 @@
     }
     
     
+    /**
+     * Test that the createAnchor() method actually ensures unique anchors.
+     */
     public void testCreateAnchor() throws Exception {
         
         WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
@@ -271,6 +280,15 @@
         // teardown our test entries
         TestUtils.teardownWeblogEntry(entry1.getId());
         TestUtils.teardownWeblogEntry(entry2.getId());
+    }
+    
+    
+    /**
+     * Test that we can add and remove entry attributes for an entry.
+     */
+    public void testEntryAttributeCRUD() throws Exception {
+        
+        // TODO: implement entry attribute test
     }
     
 }


Reply via email to