roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r394238 - in /incubator/roller/branches/roller-newbackend: build.xml tests/org/roller/business/PlanetManagerTest.java
Date Sat, 15 Apr 2006 01:01:30 GMT
Author: agilliland
Date: Fri Apr 14 18:01:27 2006
New Revision: 394238

URL: http://svn.apache.org/viewcvs?rev=394238&view=rev
Log:
fixed up planet manager unit tests.


Modified:
    incubator/roller/branches/roller-newbackend/build.xml
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/PlanetManagerTest.java

Modified: incubator/roller/branches/roller-newbackend/build.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/build.xml?rev=394238&r1=394237&r2=394238&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/build.xml (original)
+++ incubator/roller/branches/roller-newbackend/build.xml Fri Apr 14 18:01:27 2006
@@ -826,6 +826,7 @@
 	       <include name="org/roller/business/WeblogCategoryTest.class"/>
 	       <include name="org/roller/business/FileManagerTest.class"/>
 	       <include name="org/roller/business/CommentTest.class"/>
+	       <include name="org/roller/business/PlanetManagerTest.class"/>
             </fileset>
         </batchtest>
     </junit>

Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/business/PlanetManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/PlanetManagerTest.java?rev=394238&r1=394237&r2=394238&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/PlanetManagerTest.java
(original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/PlanetManagerTest.java
Fri Apr 14 18:01:27 2006
@@ -24,6 +24,8 @@
 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.RollerException;
 import org.roller.config.RollerConfig;
 import org.roller.model.PlanetManager;
@@ -33,8 +35,6 @@
 import org.roller.pojos.PlanetEntryData;
 import org.roller.pojos.PlanetGroupData;
 import org.roller.pojos.PlanetSubscriptionData;
-import org.roller.pojos.UserData;
-import org.roller.util.Blacklist;
 
 
 /**
@@ -42,125 +42,99 @@
  */
 public class PlanetManagerTest extends TestCase {
     
+    public static Log log = LogFactory.getLog(PlanetManagerTest.class);
+    
     private Roller roller = null;
     
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(PlanetManagerTest.class);
+    static {
+        try {
+            // planet config should always exist
+            PlanetConfigData config = new PlanetConfigData();
+            config.setTitle("test_title");
+            config.setAdminEmail("test_admin_email");
+            config.setProxyHost("webcache.sfbay.sun.com");
+            config.setProxyPort(8080);
+            RollerFactory.getRoller().getPlanetManager().saveConfiguration(config);
+        } catch (RollerException ex) {
+            log.error(ex);
+            throw new RuntimeException(ex);
+        }
     }
     
-    /**
-     * @see TestCase#setUp()
-     */
+    
+    public static Test suite() {
+        return new TestSuite(PlanetManagerTest.class);
+    }
+    
+    
     protected void setUp() throws Exception {
         super.setUp();
         RollerConfig.setPlanetCachePath("." + File.separator + "planet-cache");
     }
     
     public void testConfigurationStorage() throws Exception {
-        Roller roller = getRoller();
-        assertNotNull(roller);
-        PlanetManager planet = roller.getPlanetManager();
-        assertNotNull(planet);
         
-        {   // save config with default group
-            roller.begin();
-            
-            PlanetConfigData config = new PlanetConfigData();
-            //config.setCacheDir(cacheDir);
-            config.setTitle("test_title");
-            config.setAdminEmail("test_admin_email");
-            
-            PlanetGroupData group = new PlanetGroupData();
-            group.setDescription("test_group_desc");
-            group.setHandle("test_handle");
-            group.setTitle("test_title");
-            planet.saveGroup(group);
-            
-            config.setDefaultGroup(group);
-            planet.saveConfiguration(config);
-            
-            roller.commit();
-        }
-        {   // retrieve config and default group
-            roller.begin();
+        PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
+        
+        {   // retrieve config
             PlanetConfigData config = planet.getConfiguration();
+            assertNotNull(config);
             assertEquals("test_title", config.getTitle());
             assertEquals("test_admin_email", config.getAdminEmail());
-            
-            PlanetGroupData group = config.getDefaultGroup();
-            assertEquals("test_group_desc",group.getDescription());
-            assertEquals("test_title",group.getTitle());
-            
-            roller.rollback();
+            assertNull(config.getSiteUrl());
         }
-        {   // remove config
-            roller.begin();
+        {   // save config
             PlanetConfigData config = planet.getConfiguration();
-            config.remove();
-            roller.commit();
+            config.setSiteUrl("http://footest/lskdf/null");
+            planet.saveConfiguration(config);
         }
         {
-            // make sure config and group are gone
-            roller.begin();
+            // make sure config was saved
             PlanetConfigData config = planet.getConfiguration();
-            assertNull(config);
-            PlanetGroupData group = planet.getGroup("test_handle");
-            assertNull(group);
-            roller.rollback();
+            assertNotNull(config);
+            assertEquals("http://footest/lskdf/null", config.getSiteUrl());
         }
     }
+    
+    
     public void testGroupStorage() throws Exception {
-        Roller roller = getRoller();
-        assertNotNull(roller);
-        PlanetManager planet = roller.getPlanetManager();
-        assertNotNull(planet);
+        
+        PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
         
         {   // save group
-            roller.begin(UserData.SYSTEM_USER);
             PlanetGroupData group = new PlanetGroupData();
             group.setDescription("test_group_desc");
             group.setHandle("test_handle");
             group.setTitle("test_title");
             planet.saveGroup(group);
-            roller.commit();
         }
         {   // retrieve group
-            roller.begin();
             PlanetGroupData group = planet.getGroup("test_handle");
             assertEquals("test_group_desc",group.getDescription());
             assertEquals("test_title",group.getTitle());
             assertTrue(planet.getGroupHandles().size() > 0);
-            roller.rollback();
         }
         {   // remove group
-            roller.begin();
             PlanetGroupData group = planet.getGroup("test_handle");
             planet.deleteGroup(group);
-            roller.commit();
         }
         {   // verify that it is gone
-            roller.begin();
             PlanetGroupData group = planet.getGroup("test_handle");
             assertNull(group);
-            roller.rollback();
         }
     }
+    
+    
     public void testSubscriptionStorage() throws Exception {
-        Roller roller = getRoller();
-        assertNotNull(roller);
-        PlanetManager planet = roller.getPlanetManager();
-        assertNotNull(planet);
+        
+        PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
         
         {   // save subscription
-            roller.begin();
             PlanetSubscriptionData sub = new PlanetSubscriptionData();
             sub.setFeedUrl("test_url");
             planet.saveSubscription(sub);
-            roller.commit();
         }
         {   // retrieve subscription and add to group
-            roller.begin();
-            
             PlanetGroupData group = new PlanetGroupData();
             group.setDescription("test_group_desc");
             group.setHandle("test_handle");
@@ -180,19 +154,14 @@
             group.addSubscriptions(subs);
             
             planet.saveGroup(group);
-            
-            roller.commit();
         }
         {   // get group and check it's subscriptions, remove it
-            roller.begin();
             PlanetGroupData group = planet.getGroup("test_handle");
             Set subs = group.getSubscriptions();
             assertEquals(2, subs.size());
             planet.deleteGroup(group);
-            roller.commit();
         }
         {   // make sure group gone, subs still there, then remove them too
-            roller.begin();
             PlanetGroupData group = planet.getGroup("test_handle");
             assertNull(group);
             PlanetSubscriptionData sub = planet.getSubscription("test_url");
@@ -201,32 +170,26 @@
             assertNotNull(sub1);
             planet.deleteSubscription(sub);
             planet.deleteSubscription(sub1);
-            roller.commit();
         }
         {   // make sure subscriptions are gone
-            roller.begin();
             PlanetSubscriptionData sub = planet.getSubscription("test_url");
             assertNull(sub);
             PlanetSubscriptionData sub1 = planet.getSubscription("test_url1");
             assertNull(sub1);
-            roller.rollback();
         }
     }
+    
+    
     public void testSubscriptionEntryStorage() throws Exception {
-        Roller roller = getRoller();
-        assertNotNull(roller);
-        PlanetManager planet = roller.getPlanetManager();
-        assertNotNull(planet);
+        
+        PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
         
         {   // save subscription
-            roller.begin();
             PlanetSubscriptionData sub = new PlanetSubscriptionData();
             sub.setFeedUrl("test_url");
             planet.saveSubscription(sub);
-            roller.commit();
         }
         {   // retrieve subscription and add entries
-            roller.begin();
             PlanetSubscriptionData sub = planet.getSubscription("test_url");
             assertNotNull(sub);
             
@@ -235,7 +198,6 @@
             entry1.setCategoriesString("test,test2");
             entry1.setSubscription(sub);
             entry1.setPublished(new Date());
-            entry1.save();
             sub.addEntry(entry1);
             
             PlanetEntryData entry2 = new PlanetEntryData();
@@ -243,97 +205,99 @@
             entry2.setCategoriesString("test_cat1,test_cat2,test_cat3");
             entry2.setSubscription(sub);
             entry2.setPublished(new Date());
-            entry2.save();
             sub.addEntry(entry2);
             
-            roller.commit();
+            // save entries
+            planet.saveSubscription(sub);
+            
+            // get sub and check it's entries
+            sub = planet.getSubscription("test_url");
+            assertEquals(2, sub.getEntries().size());
         }
-        {   // get sub and check it's entries, remove it
-            roller.begin();
+        {
+            // add a single entry
             PlanetSubscriptionData sub = planet.getSubscription("test_url");
-            assertEquals(2, sub.getEntries().size());
-            planet.deleteSubscription(sub);
-            roller.commit();
+            assertNotNull(sub);
+            
+            PlanetEntryData entry3 = new PlanetEntryData();
+            entry3.setPermalink("test_entry3");
+            entry3.setCategoriesString("test,test3");
+            entry3.setSubscription(sub);
+            entry3.setPublished(new Date());
+            planet.saveEntry(entry3);
+            
+            // verify entry was added
+            sub = planet.getSubscription("test_url");
+            assertEquals(3, sub.getEntries().size());
         }
-        {   // make sure sub is gone
-            roller.begin();
+        {
+            // purge entries
             PlanetSubscriptionData sub = planet.getSubscription("test_url");
+            sub.purgeEntries();
+            planet.saveSubscription(sub);
+            
+            // make sure they were removed
+            sub = planet.getSubscription("test_url");
+            assertEquals(0, sub.getEntries().size());
+        }
+        {
+            // remove test subscription
+            PlanetSubscriptionData sub = planet.getSubscription("test_url");
+            planet.deleteSubscription(sub);
+            
+            // make sure sub is gone
+            sub = planet.getSubscription("test_url");
             assertNull(sub);
-            roller.rollback();
         }
     }
-    public void testRefreshEntries() {
-        try {
-            Roller roller = getRoller();
-            assertNotNull(roller);
-            PlanetManager planet = roller.getPlanetManager();
-            assertNotNull(planet);
-            String feed_url1 = "http://rollerweblogger.org/rss/roller";
-            {
-                roller.begin();
-                PlanetConfigData config = new PlanetConfigData();
-                //config.setCacheDir(cacheDir);
-                config.setTitle("test_title");
-                config.setAdminEmail("test_admin_email");
-                planet.saveConfiguration(config);
-                
-                PlanetGroupData group = new PlanetGroupData();
-                group.setDescription("test_group_desc");
-                group.setHandle("test_handle");
-                group.setTitle("test_title");
-                planet.saveGroup(group);
-                
-                PlanetSubscriptionData sub = new PlanetSubscriptionData();
-                sub.setFeedUrl(feed_url1);
-                planet.saveSubscription(sub);
-                
-                group.addSubscription(sub);
-                planet.saveGroup(group);
-                
-                roller.commit();
-            }
-            {
-                roller.begin();
-                planet.refreshEntries();
-                roller.commit();
-                
-                roller.begin();
-                PlanetSubscriptionData sub = planet.getSubscription(feed_url1);
-                int entriesSize = sub.getEntries().size();
-                
-                PlanetGroupData group = planet.getGroup("test_handle");
-                assertNotNull(group);
-                
-                planet.deleteGroup(group);
-                planet.deleteSubscription(sub);
-                
-                PlanetConfigData config = planet.getConfiguration();
-                config.remove();
-                roller.commit();
-                
-                assertTrue(entriesSize > 0);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail();
+    
+    
+    public void testRefreshEntries() throws Exception {
+        
+        PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
+        
+        String feed_url1 = "http://rollerweblogger.org/rss/roller";
+        
+        {
+            PlanetGroupData group = new PlanetGroupData();
+            group.setDescription("test_group_desc");
+            group.setHandle("test_handle");
+            group.setTitle("test_title");
+            planet.saveGroup(group);
+            
+            PlanetSubscriptionData sub = new PlanetSubscriptionData();
+            sub.setFeedUrl(feed_url1);
+            planet.saveSubscription(sub);
+            
+            group.addSubscription(sub);
+            planet.saveGroup(group);
+        }
+        {
+            planet.refreshEntries();
+            
+            PlanetSubscriptionData sub = planet.getSubscription(feed_url1);
+            int entriesSize = sub.getEntries().size();
+            
+            PlanetGroupData group = planet.getGroup("test_handle");
+            assertNotNull(group);
+            
+            planet.deleteGroup(group);
+            planet.deleteSubscription(sub);
+            
+            assertTrue(entriesSize > 0);
         }
     }
+    
+    
     public void testAggregations() throws Exception {
+        
         try {
-            Roller roller = getRoller();
-            assertNotNull(roller);
-            PlanetManager planet = roller.getPlanetManager();
-            assertNotNull(planet);
+            PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
+            
             String feed_url1 = "http://rollerweblogger.org/rss/roller";
             String feed_url2 = "http://linuxintegrators.com/acoliver/?flavor=rss2";
+            
             {
-                roller.begin();
-                PlanetConfigData config = new PlanetConfigData();
-                //config.setCacheDir(cacheDir);
-                config.setTitle("test_title");
-                config.setAdminEmail("test_admin_email");
-                planet.saveConfiguration(config);
-                
                 PlanetGroupData group = new PlanetGroupData();
                 group.setDescription("test_group_desc");
                 group.setHandle("test_handle");
@@ -351,15 +315,10 @@
                 group.addSubscription(sub1);
                 group.addSubscription(sub2);
                 planet.saveGroup(group);
-                
-                roller.commit();
             }
             {
-                roller.begin();
                 planet.refreshEntries();
-                roller.commit();
                 
-                roller.begin();
                 int count = 0;
                 Iterator subs = planet.getAllSubscriptions();
                 while  (subs.hasNext()) {
@@ -384,69 +343,40 @@
                 planet.deleteGroup(group);
                 planet.deleteSubscription(sub1);
                 planet.deleteSubscription(sub2);
-                
-                PlanetConfigData config = planet.getConfiguration();
-                config.remove();
-                roller.commit();
             }
         } catch (Exception e) {
             e.printStackTrace();
             fail();
         }
     }
+    
+    
     public void testSubscriptionCount() throws Exception {
+        
         try {
-            Roller roller = getRoller();
-            assertNotNull(roller);
-            PlanetManager planet = roller.getPlanetManager();
-            assertNotNull(planet);
+            PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
+            
             String feed_url1 = "http://rollerweblogger.org/rss/roller";
             String feed_url2 = "http://linuxintegrators.com/acoliver/?flavor=rss2";
+            
             {
-                roller.begin();
                 PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
                 sub1.setFeedUrl(feed_url1);
                 planet.saveSubscription(sub1);
                 PlanetSubscriptionData sub2 = new PlanetSubscriptionData();
                 sub2.setFeedUrl(feed_url2);
                 planet.saveSubscription(sub2);
-                roller.commit();
                 
-                roller.begin();
                 assertEquals(2, planet.getSubscriptionCount());
-                roller.rollback();
                 
-                roller.begin();
                 planet.getSubscription(feed_url1).remove();
                 planet.getSubscription(feed_url2).remove();
-                roller.commit();
             }
         } catch (Exception e) {
             e.printStackTrace();
             fail();
         }
     }
-    /*
-    public void testRankingRange()
-    {
-        int limit = 1000;
-        int count = 5500;
-        int mod = (count / limit) + 1;
-        for (int i=0; i<20; i++)
-        {
-            int start = (i % mod) * limit;
-            int end = start + 999;
-            end = end > count ? count : end;
-            System.out.println("start="+start+" end="+end);
-        }
-    }
-     */
-    public Roller getRoller() throws RollerException {
-        return RollerFactory.getRoller();
-    }
     
-    public static Test suite() {
-        return new TestSuite(PlanetManagerTest.class);
-    }
 }
 



Mime
View raw message