You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2006/04/12 02:22:54 UTC

svn commit: r393342 - in /incubator/roller/branches/roller-newbackend/tests/org/roller: TestUtils.java business/PingsTest.java business/WeblogTest.java

Author: agilliland
Date: Tue Apr 11 17:22:51 2006
New Revision: 393342

URL: http://svn.apache.org/viewcvs?rev=393342&view=rev
Log:
more updates to unit tests.


Modified:
    incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/PingsTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogTest.java

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=393342&r1=393341&r2=393342&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java (original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java Tue Apr 11 17:22:51 2006
@@ -6,9 +6,13 @@
 
 package org.roller;
 
+import org.roller.model.AutoPingManager;
+import org.roller.model.PingTargetManager;
 import org.roller.model.RollerFactory;
 import org.roller.model.UserManager;
 import org.roller.model.WeblogManager;
+import org.roller.pojos.AutoPingData;
+import org.roller.pojos.PingTargetData;
 import org.roller.pojos.UserData;
 import org.roller.pojos.WeblogEntryData;
 import org.roller.pojos.WebsiteData;
@@ -17,7 +21,7 @@
 /**
  * Utility class for unit test classes.
  */
-public class TestUtils {
+public final class TestUtils {
     
     
     /**
@@ -155,6 +159,77 @@
         
         // remove the entry
         mgr.removeWeblogEntry(entry);
+    }
+    
+    
+    /**
+     * Convenience method for creating a ping target.
+     */
+    public static PingTargetData setupPingTarget(String name, String url) 
+            throws Exception {
+        
+        PingTargetData testPing = new PingTargetData();
+        testPing.setName("testCommonPing");
+        testPing.setPingUrl("http://localhost/testCommonPing");
+        
+        // store ping
+        PingTargetManager pingMgr = RollerFactory.getRoller().getPingTargetManager();
+        pingMgr.storePingTarget(testPing);
+        
+        // query for it
+        PingTargetData ping = pingMgr.retrievePingTarget(testPing.getId());
+        
+        if(ping == null)
+            throw new RollerException("error setting up ping target");
+        
+        return ping;
+    }
+    
+    
+    /**
+     * Convenience method for removing a ping target.
+     */
+    public static void teardownPingTarget(String id) throws Exception {
+        
+        // remove the ping
+        PingTargetManager pingMgr = RollerFactory.getRoller().getPingTargetManager();
+        pingMgr.removePingTarget(id);
+    }
+    
+    
+    /**
+     * Convenience method for creating an auto ping.
+     */
+    public static AutoPingData setupAutoPing(PingTargetData ping, WebsiteData weblog)
+            throws Exception {
+        
+        AutoPingManager mgr = RollerFactory.getRoller().getAutopingManager();
+        
+        // store auto ping
+        AutoPingData autoPing = mgr.createAutoPing(ping, weblog);
+        mgr.storeAutoPing(autoPing);
+        
+        // query for it
+        autoPing = mgr.retrieveAutoPing(autoPing.getId());
+        
+        if(autoPing == null)
+            throw new RollerException("error setting up auto ping");
+        
+        return autoPing;
+    }
+    
+    
+    /**
+     * Convenience method for removing an auto ping.
+     */
+    public static void teardownAutoPing(String id) throws Exception {
+        
+        // query for it
+        AutoPingManager mgr = RollerFactory.getRoller().getAutopingManager();
+        AutoPingData autoPing = mgr.retrieveAutoPing(id);
+        
+        // remove the auto ping
+        mgr.removeAutoPing(autoPing);
     }
     
 }

Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/business/PingsTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/PingsTest.java?rev=393342&r1=393341&r2=393342&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/PingsTest.java (original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/PingsTest.java Tue Apr 11 17:22:51 2006
@@ -6,6 +6,7 @@
 
 package org.roller.business;
 
+import java.util.ArrayList;
 import java.util.List;
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -13,8 +14,10 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.roller.TestUtils;
+import org.roller.model.AutoPingManager;
 import org.roller.model.PingTargetManager;
 import org.roller.model.RollerFactory;
+import org.roller.pojos.AutoPingData;
 import org.roller.pojos.PingTargetData;
 import org.roller.pojos.UserData;
 import org.roller.pojos.WebsiteData;
@@ -204,6 +207,155 @@
         
         // remove common ping
         mgr.removePingTarget(commonId);
+    }
+    
+    
+    /**
+     * Test basic persistence operations ... Create, Update, Delete
+     */
+    public void testAutoPingCRUD() throws Exception {
+        
+        AutoPingManager mgr = RollerFactory.getRoller().getAutopingManager();
+        AutoPingData autoPing = null;
+        
+        // create ping target to use for tests
+        PingTargetData pingTarget = TestUtils.setupPingTarget("fooPing", "http://foo/null");
+        PingTargetData pingTarget2 = TestUtils.setupPingTarget("blahPing", "http://blah/null");
+        
+        // create autoPing
+        autoPing = mgr.createAutoPing(pingTarget, testWeblog);
+        mgr.storeAutoPing(autoPing);
+        String id = autoPing.getId();
+        
+        // make sure autoPing was stored
+        autoPing = null;
+        autoPing = mgr.retrieveAutoPing(id);
+        assertNotNull(autoPing);
+        assertEquals(pingTarget, autoPing.getPingTarget());
+        
+        // update autoPing
+        autoPing.setPingTarget(pingTarget2);
+        mgr.storeAutoPing(autoPing);
+        
+        // make sure autoPing was updated
+        autoPing = null;
+        autoPing = mgr.retrieveAutoPing(id);
+        assertNotNull(autoPing);
+        assertEquals(pingTarget2, autoPing.getPingTarget());
+        
+        // delete autoPing
+        mgr.removeAutoPing(autoPing);
+        
+        // make sure common autoPing was deleted
+        autoPing = null;
+        autoPing = mgr.retrieveAutoPing(id);
+        assertNull(autoPing);
+        
+        // teardown test ping target
+        TestUtils.teardownPingTarget(pingTarget.getId());
+        TestUtils.teardownPingTarget(pingTarget2.getId());
+    }
+    
+    
+    /**
+     * Test special ping target removal methods ... by weblog/target, collection, all
+     */
+    public void testPingTargetRemovals() throws Exception {
+        
+        AutoPingManager mgr = RollerFactory.getRoller().getAutopingManager();
+        AutoPingData testAutoPing = null;
+        
+        // create ping target to use for tests
+        PingTargetData pingTarget = TestUtils.setupPingTarget("fooPing", "http://foo/null");
+        PingTargetData pingTarget2 = TestUtils.setupPingTarget("blahPing", "http://blah/null");
+        PingTargetData pingTarget3 = TestUtils.setupPingTarget("gahPing", "http://gah/null");
+        
+        // create auto pings for test
+        AutoPingData autoPing = TestUtils.setupAutoPing(pingTarget, testWeblog);
+        AutoPingData autoPing2 = TestUtils.setupAutoPing(pingTarget2, testWeblog);
+        AutoPingData autoPing3 = TestUtils.setupAutoPing(pingTarget3, testWeblog);
+        
+        // remove by weblog/target
+        mgr.removeAutoPing(pingTarget, testWeblog);
+        
+        // make sure remove succeeded
+        testAutoPing = null;
+        testAutoPing = mgr.retrieveAutoPing(autoPing.getId());
+        assertNull(testAutoPing);
+        
+        // remove a collection
+        List autoPings = new ArrayList();
+        autoPings.add(autoPing2);
+        autoPings.add(autoPing3);
+        mgr.removeAutoPings(autoPings);
+        
+        // make sure delete was successful
+        autoPings = mgr.getAutoPingsByWebsite(testWeblog);
+        assertNotNull(autoPings);
+        assertEquals(0, autoPings.size());
+        
+        // need to create more test pings
+        autoPing = TestUtils.setupAutoPing(pingTarget, testWeblog);
+        autoPing2 = TestUtils.setupAutoPing(pingTarget2, testWeblog);
+        autoPing3 = TestUtils.setupAutoPing(pingTarget3, testWeblog);
+        
+        // remove all
+        mgr.removeAllAutoPings();
+        
+        // make sure remove succeeded
+        autoPings = mgr.getAutoPingsByWebsite(testWeblog);
+        assertNotNull(autoPings);
+        assertEquals(0, autoPings.size());
+        
+        // teardown test ping target
+        TestUtils.teardownPingTarget(pingTarget.getId());
+        TestUtils.teardownPingTarget(pingTarget2.getId());
+    }
+    
+    
+    /**
+     * Test lookup mechanisms ... id, ping target, weblog
+     */
+    public void testAutoPingLookups() throws Exception {
+        
+        AutoPingManager mgr = RollerFactory.getRoller().getAutopingManager();
+        AutoPingData autoPing = null;
+        
+        // create autoPing target to use for tests
+        PingTargetData pingTarget = TestUtils.setupPingTarget("fooPing", "http://foo/null");
+        
+        // create autoPing
+        autoPing = mgr.createAutoPing(pingTarget, testWeblog);
+        mgr.storeAutoPing(autoPing);
+        String id = autoPing.getId();
+        
+        // lookup by id
+        autoPing = null;
+        autoPing = mgr.retrieveAutoPing(id);
+        assertNotNull(autoPing);
+        assertEquals(pingTarget, autoPing.getPingTarget());
+        
+        // lookup by ping target
+        List autoPings = mgr.getAutoPingsByTarget(pingTarget);
+        assertNotNull(autoPings);
+        assertEquals(1, autoPings.size());
+        
+        // lookup by weblog
+        autoPings = null;
+        autoPings = mgr.getAutoPingsByWebsite(testWeblog);
+        assertNotNull(autoPing);
+        assertEquals(1, autoPings.size());
+        
+        // delete autoPing
+        mgr.removeAutoPing(autoPing);
+        
+        // teardown test ping target
+        TestUtils.teardownPingTarget(pingTarget.getId());
+    }
+    
+    
+    public void testApplicableAutoPings() throws Exception {
+        
     }
     
 }

Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogTest.java?rev=393342&r1=393341&r2=393342&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogTest.java (original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogTest.java Tue Apr 11 17:22:51 2006
@@ -225,4 +225,13 @@
         weblog = null;
     }
     
+    
+    /**
+     * Test that we can safely remove a fully loaded weblog.
+     * That means a weblog with entries, categories, bookmarks, pings, etc.
+     */
+    public void testRemoveLoadedWeblog() throws Exception {
+        // TODO: implement testRemoveLoadedWeblog
+    }
+    
 }