roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r392622 [1/3] - in /incubator/roller/branches/roller-newbackend: ./ testdata/WEB-INF/classes/ tests/org/roller/ tests/org/roller/business/ tests/org/roller/presentation/velocity/
Date Sat, 08 Apr 2006 22:43:01 GMT
Author: agilliland
Date: Sat Apr  8 15:42:58 2006
New Revision: 392622

URL: http://svn.apache.org/viewcvs?rev=392622&view=rev
Log:
first batch of backend refactorings.

cleaning up unit tests, beginning with business tests.


Added:
    incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/PermissionTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/UserTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogTemplateTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogTest.java
Removed:
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/PermissionsTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/WebsiteTest.java
Modified:
    incubator/roller/branches/roller-newbackend/build.xml
    incubator/roller/branches/roller-newbackend/testdata/WEB-INF/classes/hibernate.cfg.xml
    incubator/roller/branches/roller-newbackend/testdata/WEB-INF/classes/log4j.properties
    incubator/roller/branches/roller-newbackend/tests/org/roller/RollerTestBase.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/BookmarkManagerTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/FileManagerTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/PlanetManagerTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/RefererManagerTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/TestAll.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/UserManagerTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogManagerTest.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/presentation/velocity/ExportRssTest.java

Modified: incubator/roller/branches/roller-newbackend/build.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/build.xml?rev=392622&r1=392621&r2=392622&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/build.xml (original)
+++ incubator/roller/branches/roller-newbackend/build.xml Sat Apr  8 15:42:58 2006
@@ -762,6 +762,7 @@
         <fileset dir="${basedir}/web/WEB-INF/classes">
             <include name="App*.properties"/>
             <include name="**/*.vm"/>
+	    <exclude name="hibernate.cfg.xml"/>
         </fileset>
     </copy>
     <copy file="${basedir}/web/WEB-INF/classes/roller.properties"
@@ -815,7 +816,9 @@
         <formatter type="xml"/>
         <batchtest toDir="${build.reports}/business/xml">
             <fileset dir="${build.tests}/WEB-INF/classes">
-               <include name="org/roller/business/*Test.class"/> 
+               <include name="org/roller/business/UserTest.class"/> 
+	       <include name="org/roller/business/WeblogTest.class"/>
+	       <include name="org/roller/business/PermissionsTest.class"/>
             </fileset>
         </batchtest>
     </junit>

Modified: incubator/roller/branches/roller-newbackend/testdata/WEB-INF/classes/hibernate.cfg.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/testdata/WEB-INF/classes/hibernate.cfg.xml?rev=392622&r1=392621&r2=392622&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/testdata/WEB-INF/classes/hibernate.cfg.xml (original)
+++ incubator/roller/branches/roller-newbackend/testdata/WEB-INF/classes/hibernate.cfg.xml Sat Apr  8 15:42:58 2006
@@ -10,6 +10,10 @@
         <property name="connection.datasource">java:comp/env/jdbc/rollerdb</property>
         <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
         -->
+        
+        <!-- use thread local Session context -->
+        <property name="hibernate.current_session_context_class">thread</property>
+        
         <!--
         If you want to use HSQLDB, PostgreSQL, DB2 or Derby, Oracle then use the right dialect   
         <property name="dialect">org.hibernate.dialect.HQLDBDialect</property> 
@@ -42,7 +46,6 @@
         <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
         -->
 
-        <mapping resource="org/roller/business/HitCountData.hbm.xml" />
         <mapping resource="org/roller/pojos/BookmarkData.hbm.xml" />
         <mapping resource="org/roller/pojos/CommentData.hbm.xml" />
         <mapping resource="org/roller/pojos/EntryAttributeData.hbm.xml" />

Modified: incubator/roller/branches/roller-newbackend/testdata/WEB-INF/classes/log4j.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/testdata/WEB-INF/classes/log4j.properties?rev=392622&r1=392621&r2=392622&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/testdata/WEB-INF/classes/log4j.properties (original)
+++ incubator/roller/branches/roller-newbackend/testdata/WEB-INF/classes/log4j.properties Sat Apr  8 15:42:58 2006
@@ -1,57 +1,23 @@
 # Properties for configuring Log4j for this application
 # This is the configuring for logging displayed in the Application Server
 # log4j.rootCategory=INFO, stdout, R, mail
-log4j.rootCategory=INFO, stdout
+log4j.rootCategory=INFO, roller
 
+# log to console
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-
-# Pattern to output the caller's file name and line number.
-#log4j.appender.stdout.layout.ConversionPattern=%p [%t] [%c] %C{1}.%M(%L) | %m%n
 log4j.appender.stdout.layout.ConversionPattern=%-5p %d{yyyy-MM-dd HH:mm:ss,SSS} | %C{1}:%M | %m%n
 
-log4j.appender.R=org.apache.log4j.RollingFileAppender
-log4j.appender.R.File=${catalina.base}/logs/roller.log
-
-# Keep two 1MB log backup files
-log4j.appender.R.MaxFileSize=1MB
-log4j.appender.R.MaxBackupIndex=2
-
-log4j.appender.R.layout=org.apache.log4j.PatternLayout
-#log4j.appender.R.layout.ConversionPattern=%5p %t %c - %m%n
-log4j.appender.R.layout.ConversionPattern=%-5p %d{yyyy-MM-dd HH:mm:ss,SSS} %C{1}:%M - %m%n
-
-# If programmed properly the most messages would be at DEBUG
-# and the least at FATAL.
-
-# Options are: DEBUG, INFO, WARN, ERROR, FATAL
-log4j.category.org.roller=ERROR
-log4j.category.com.ecyrd.jspwiki=ERROR
-log4j.category.com.opensymphony.oscache=ERROR
-log4j.category.org.hibernate=ERROR
-log4j.category.org.roller.business.utils=ERROR
-log4j.category.org.apache.struts=ERROR
-log4j.category.org.tuckey.web.filters.urlrewrite=DEBUG
-
-#log4j.category.org.roller.presentation.MainPageAction=DEBUG
-#log4j.category.org.roller.presentation.pagecache.rollercache.LRUCacheHandler=DEBUG
-#log4j.category.org.roller.presentation.filters.IfModifiedFilter=DEBUG
-#log4j.category.org.roller.persistence.hibernate.HibernateStrategy=DEBUG
-
-# Tomcat's ClientAbortExceptions cause Velocity to talk way
-# too much so by default Velocity is set to STFU mode.
-log4j.category.org.apache.velocity=FATAL
-
-# Configuration for receiving e-mails when ERROR messages occur.
-#log4j.appender.mail=org.apache.log4j.net.SMTPAppender
-#log4j.appender.mail.To=you@yours.com
-#log4j.appender.mail.From=you@yours.com
-#log4j.appender.mail.SMTPHost=127.0.0.1
-#log4j.appender.mail.Threshold=ERROR
-#log4j.appender.mail.BufferSize=1
-#log4j.appender.mail.Subject=Roller Exception
-
-#log4j.appender.mail.layout=org.apache.log4j.PatternLayout
-#log4j.appender.mail.layout.ConversionPattern=%p [%d{yyyy-MM-dd HH:mm:ss,SSS}] %C{1}.%M(%L) | %m%n
-
-
+# log to file
+log4j.appender.roller=org.apache.log4j.FileAppender
+log4j.appender.roller.File=${user.dir}/logs/roller-test.log
+log4j.appender.roller.layout=org.apache.log4j.PatternLayout
+log4j.appender.roller.layout.ConversionPattern=%-5p %d{yyyy-MM-dd HH:mm:ss,SSS} %C{1}:%M - %m%n
+
+# logging levels
+log4j.category.org.roller=INFO
+log4j.category.org.roller.business.hibernate=DEBUG
+log4j.category.org.roller.business.WeblogTest=DEBUG
+log4j.category.org.hibernate=INFO
+log4j.category.org.apache.struts=INFO
+log4j.category.org.apache.velocity=INFO

Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/RollerTestBase.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/RollerTestBase.java?rev=392622&r1=392621&r2=392622&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/RollerTestBase.java (original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/RollerTestBase.java Sat Apr  8 15:42:58 2006
@@ -111,7 +111,7 @@
         String FS = File.separator;
         RollerConfig.setContextRealPath(".." + FS + "roller");
         RollerConfig.setUploadsDir("." + FS + "roller_dat" + FS + "uploads");       
-        getRoller().begin(UserData.SYSTEM_USER);
+        
         mUser = createUser(
                 testUsername,
                 "password",
@@ -119,32 +119,25 @@
                 "testuser@example.com");
         UserManager umgr = getRoller().getUserManager();
         mWebsite = (WebsiteData)umgr.getWebsites(mUser, null, null).get(0);
-        getRoller().commit();
         
-        getRoller().begin(UserData.SYSTEM_USER);
         PropertiesManager propmgr = getRoller().getPropertiesManager();
         Map props = propmgr.getProperties();
         RollerPropertyData prop =
                 (RollerPropertyData)props.get("site.absoluteurl");
         prop.setValue("http://localhost:8080/roller");
         propmgr.store(props);
-        getRoller().commit();
         
-        getRoller().begin(UserData.SYSTEM_USER);
         PlanetManager planet = getRoller().getPlanetManager();
         PlanetConfigData config = config = new PlanetConfigData();
         config.setCacheDir("");
         config.setTitle("Test");
         config.setAdminEmail("admin@example.com");
         planet.saveConfiguration(config);
-        getRoller().commit();
         
-        getRoller().begin(UserData.SYSTEM_USER);
         PlanetGroupData group = new PlanetGroupData();
         group.setHandle("external");
         group.setTitle("external");
         planet.saveGroup(group);
-        getRoller().commit();
     }
     
     //-----------------------------------------------------------------------
@@ -188,7 +181,6 @@
         
         // Loop to create weblogs
         for (int i=0; i<mBlogCount; i++) {
-            getRoller().begin(UserData.SYSTEM_USER);
             
             UserData ud = createUser(
                     "testuser"+i,         // userName
@@ -212,7 +204,6 @@
             WeblogCategoryData rootCat = wmgr.getRootWeblogCategory(website);
             createCategoryPostsAndComments(0, wmgr, ud, website, rootCat);
             
-            getRoller().commit();
         }
         
         // commit all the objects
@@ -245,7 +236,7 @@
                     day,        // pubTime
                     day,        // updateTime
                     WeblogEntryData.PUBLISHED ); // publishEntry
-            wd.save();
+            wmgr.storeWeblogEntry(wd);
             
             // roll calendar back to today
             mCalendar.roll(Calendar.DATE, false);
@@ -272,7 +263,7 @@
                     day,        // pubTime
                     day,        // updateTime
                     status ); // publishEntry
-            wd.save();
+            wmgr.storeWeblogEntry(wd);
             
             // add at beginning of list
             mEntriesCreated.add(0, wd);
@@ -294,7 +285,7 @@
                 comment.setPending(Boolean.FALSE);
                 comment.setSpam(Boolean.FALSE);
                 comment.setNotify(Boolean.FALSE);
-                comment.save();
+                wmgr.saveComment(comment);
                 mCommentsCreated.add(comment);
                 mLogger.debug("         Created comment ["
                         +comment.getId()+"]"+ comment.getName());
@@ -311,7 +302,7 @@
                     rootCat.getName()+"-cat"+j,    // name
                     "desc",                        // description
                     null );                       // image
-            cat.save();
+            wmgr.storeWeblogCategory(cat);
             mCategoriesCreated.add(cat);
             mLogger.debug("   Created cat ["+cat.getId()+"]"+cat.getName());
             
@@ -324,20 +315,20 @@
     //-----------------------------------------------------------------------
     /** Tear down weblogs created in setupTestWeblogs() */
     public void tearDownTestWeblogs() throws Exception {
-        getRoller().begin(UserData.SYSTEM_USER);
         UserManager umgr = getRoller().getUserManager();
         for (Iterator siteIter = mWebsitesCreated.iterator(); siteIter.hasNext();) {
             WebsiteData site = (WebsiteData) siteIter.next();
             site = umgr.retrieveWebsite(site.getId());
-            if (site != null) site.remove();
+            if (site != null) {
+                umgr.removeWebsite(site);
+            }
         }
         
         for (Iterator userIter = mUsersCreated.iterator(); userIter.hasNext();) {
             UserData user = (UserData) userIter.next();
             user = umgr.retrieveUser(user.getId());
-            if (user != null) user.remove();
+            if (user != null) umgr.removeUser(user);
         }
-        getRoller().commit();
     }
     
     //------------------------------------------------------------------------
@@ -351,13 +342,11 @@
      */
     public void tearDown() throws Exception {
         try {
-            getRoller().begin(UserData.SYSTEM_USER);
             PlanetManager planet = getRoller().getPlanetManager();
             PlanetConfigData config = planet.getConfiguration();
             PlanetGroupData group = planet.getGroup("external");
             group.remove();
             config.remove();
-            getRoller().commit();
             
             deleteWebsite(testUsername);
         } catch (RollerException e) {
@@ -373,17 +362,15 @@
      */
     private void deleteWebsite(String deleteMe) throws RollerException {
         mLogger.debug("try to delete " + deleteMe);
-        getRoller().begin(UserData.SYSTEM_USER);
         UserManager umgr = getRoller().getUserManager();
         
         UserData user = umgr.getUser(deleteMe);
         
         WebsiteData website = (WebsiteData)umgr.getWebsites(user, null, null).get(0);
-        website.remove();
+        umgr.removeWebsite(website);
         
-        user.remove();
+        umgr.removeUser(user);
         
-        getRoller().commit();
     }
     
     //------------------------------------------------------------------------

Added: 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=392622&view=auto
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java (added)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java Sat Apr  8 15:42:58 2006
@@ -0,0 +1,109 @@
+/*
+ * TestUtils.java
+ *
+ * Created on April 6, 2006, 8:38 PM
+ */
+
+package org.roller;
+
+import org.roller.model.RollerFactory;
+import org.roller.model.UserManager;
+import org.roller.pojos.UserData;
+import org.roller.pojos.WebsiteData;
+
+/**
+ * Utility class for unit test classes.
+ */
+public class TestUtils {
+    
+    
+    /**
+     * Convenience method that creates a user and stores it.
+     */
+    public static UserData setupUser(String username) throws Exception {
+        
+        UserData testUser = new UserData();
+        testUser.setUserName(username);
+        testUser.setPassword("password");
+        testUser.setFullName("Test User");
+        testUser.setEmailAddress("TestUser@dev.null");
+        testUser.setLocale("en_US");
+        testUser.setTimeZone("America/Los_Angeles");
+        testUser.setDateCreated(new java.util.Date());
+        testUser.setEnabled(Boolean.TRUE);
+        
+        // store the user
+        UserManager mgr = RollerFactory.getRoller().getUserManager();
+        mgr.addUser(testUser);
+        
+        // query for the user to make sure we return the persisted object
+        UserData user = mgr.getUser(username);
+        
+        if(user == null)
+            throw new RollerException("error inserting new user");
+        
+        return user;
+    }
+    
+    
+    /**
+     * Convenience method for removing a user.
+     */
+    public static void teardownUser(String username) throws Exception {
+        
+        // lookup the user
+        UserManager mgr = RollerFactory.getRoller().getUserManager();
+        UserData user = mgr.getUser(username);
+        
+        // remove the user
+        mgr.removeUser(user);
+    }
+    
+    
+    /**
+     * Convenience method that creates a weblog and stores it.
+     */
+    public static WebsiteData setupWeblog(String handle, UserData creator) throws Exception {
+        
+        WebsiteData testWeblog = new WebsiteData();
+        testWeblog.setName("Test Weblog");
+        testWeblog.setDescription("Test Weblog");
+        testWeblog.setHandle(handle);
+        testWeblog.setEmailAddress("testweblog@dev.null");
+        testWeblog.setEditorPage("editor-text.jsp");
+        testWeblog.setBlacklist("");
+        testWeblog.setEmailFromAddress("");
+        testWeblog.setEditorTheme("basic");
+        testWeblog.setLocale("en_US");
+        testWeblog.setTimeZone("America/Los_Angeles");
+        testWeblog.setDateCreated(new java.util.Date());
+        testWeblog.setCreator(creator);
+        
+        // add weblog
+        UserManager mgr = RollerFactory.getRoller().getUserManager();
+        mgr.createWebsite(testWeblog);
+        
+        // query for the new weblog and return it
+        WebsiteData weblog = mgr.getWebsiteByHandle(handle);
+        
+        if(weblog == null)
+            throw new RollerException("error setting up weblog");
+        
+        return weblog;
+    }
+    
+    
+    /**
+     * Convenience method for removing a weblog.
+     */
+    public static void teardownWeblog(String handle) throws Exception {
+        
+        // lookup the user
+        UserManager mgr = RollerFactory.getRoller().getUserManager();
+        WebsiteData weblog = mgr.getWebsiteByHandle(handle);
+        
+        // remove the weblog
+        mgr.removeWebsite(weblog);
+    }
+    
+}

Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/business/BookmarkManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/BookmarkManagerTest.java?rev=392622&r1=392621&r2=392622&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/BookmarkManagerTest.java (original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/BookmarkManagerTest.java Sat Apr  8 15:42:58 2006
@@ -26,387 +26,387 @@
  */
 public class BookmarkManagerTest extends RollerTestBase
 {
-    //------------------------------------------------------------------------
-    public BookmarkManagerTest()
-    {
-        super();
-    }
-
-    //------------------------------------------------------------------------
-    public BookmarkManagerTest(String name)
-    {
-        super(name);
-    }
-
-    //------------------------------------------------------------------------
-    public static Test suite()
-    {
-        return new TestSuite(BookmarkManagerTest.class);
-    }
-
-    //------------------------------------------------------------------------
-    public static void main(String args[])
-    {
-        junit.textui.TestRunner.run( BookmarkManagerTest.class );
-    }
-
-    //------------------------------------------------------------------------
-
-    public void testAddBookmarkToFolder() throws RollerException
-    {
-        BookmarkManager bmgr = getRoller().getBookmarkManager();
-        FolderData folder = null;
-        BookmarkData bookmark1 = null, bookmark2 = null;
-
-        getRoller().begin(UserData.SYSTEM_USER);
-
-        WebsiteData website =
-            getRoller().getUserManager().retrieveWebsite(mWebsite.getId());
-        FolderData root = bmgr.getRootFolder(website);
-
-        folder = bmgr.createFolder();
-        folder.setName("TestFolder1");
-        folder.setDescription("created by testAddBookmarkToFolder()");
-        folder.setWebsite(website);
-        folder.setParent(root);
-        folder.save();
-
-        // Add bookmark by adding to folder
-        bookmark1 = bmgr.createBookmark(
-            folder,
-            "TestBookmark1",
-            "created by testAddBookmarkToFolder()",
-            "http://www.example.com",
-            "http://www.example.com/rss.xml",
-            new Integer(1),
-            new Integer(12),
-            "test.jpg");
-        folder.addBookmark(bookmark1);
-
-        // Add another bookmark
-        bookmark2 = bmgr.createBookmark(
-            folder,
-            "TestBookmark2",
-            "created by testAddBookmarkToFolder()",
-            "http://www.example.com",
-            "http://www.example.com/rss.xml",
-            new Integer(1),
-            new Integer(12),
-            "test.jpf");
-        folder.addBookmark(bookmark2);
-
-        getRoller().commit();
-
-        FolderData testFolder = null;
-        BookmarkData bookmarkb = null, bookmarka = null;
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        // See that two bookmarks were stored
-        testFolder = bmgr.retrieveFolder(folder.getId());
-        assertEquals(2, testFolder.getBookmarks().size());
-        bookmarka = (BookmarkData)testFolder.getBookmarks().iterator().next();
-        bookmarkb = (BookmarkData)testFolder.getBookmarks().iterator().next();
-        // Remove one bookmark
-        testFolder.removeBookmark(bookmarka);
-        bmgr.removeBookmark(bookmarka.getId());
-        getRoller().commit();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        // Folder should now contain one bookmark
-        testFolder = bmgr.retrieveFolder(folder.getId());
-        assertEquals(1, testFolder.getBookmarks().size());
-        getRoller().release();
-
-        // Remove folder
-        getRoller().begin(UserData.SYSTEM_USER);
-        testFolder = bmgr.retrieveFolder(folder.getId());
-        testFolder.remove();
-        getRoller().commit();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        // Folder and one remaining bookmark should be gone
-        assertNull( bmgr.retrieveBookmark(bookmarkb.getId()) );
-        assertNull( bmgr.retrieveFolder(folder.getId()) );
-        getRoller().release();
-    }
-
-    //------------------------------------------------------------------------
-    public void testBookmarkImport() throws Exception
-    {
-        importBookmarks("/bookmarks.opml");
-    }
-
-    //------------------------------------------------------------------------
-    public void importBookmarks(String fileName) throws Exception
-    {
-        getRoller().begin(UserData.SYSTEM_USER);
-        InputStream fis = this.getClass().getResourceAsStream(fileName);
-        getRoller().getBookmarkManager().importBookmarks(
-            mWebsite, "ZZZ_imports_ZZZ", fileToString(fis));
-        getRoller().commit();
-        getRoller().release();
-
-        FolderData fd = null;
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        fd = getRoller().getBookmarkManager().getFolder(mWebsite, "ZZZ_imports_ZZZ");
-        assertTrue("no bookmarks found", fd.retrieveBookmarks(true).size() > 0 );
-        fd.remove();
-        getRoller().commit();
-    }
-
-    //------------------------------------------------------------------------
-    public String fileToString( InputStream is ) throws java.io.IOException
-    {
-        BufferedReader br = new BufferedReader(new InputStreamReader(is));
-        String s = null;
-        StringBuffer sb = new StringBuffer();
-        while ( (s=br.readLine()) != null )
-        {
-            sb.append( s );
-        }
-        return sb.toString();
-    }
-
-    //------------------------------------------------------------------------
-
-    /**
-     * Creates folder tree like this:
-     *    root/
-     *       dest/
-     *       f1/
-     *          b1
-     *          f2/
-     *             f3/
-     */
-    public void testMoveFolderContents() throws RollerException
-    {
-        WebsiteData wd = null;
-        BookmarkManager bmgr = getRoller().getBookmarkManager();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-
-        wd = getRoller().getUserManager().retrieveWebsite(mWebsite.getId());
-        FolderData root = bmgr.getRootFolder(wd);
-
-        FolderData dest = bmgr.createFolder();
-        dest.setName("dest");
-        dest.setParent(root);
-        dest.setWebsite(wd);
-        dest.save();
-
-        // create source folder f1
-        FolderData f1 = bmgr.createFolder();
-        f1.setName("f1");
-        f1.setParent(root);
-        f1.setWebsite(wd);
-        f1.save();
-
-        // create bookmark b1 inside source folder f1
-        BookmarkData b1 = bmgr.createBookmark(
-            f1, "b1", "testbookmark",
-            "http://example.com", "http://example.com/rss",
-            new Integer(1), new Integer(1), "image.gif");
-        b1.save();
-
-        // create folder f2 inside f1
-        FolderData f2 = bmgr.createFolder();
-        f2.setName("f2");
-        f2.setParent(f1);
-        f2.setWebsite(wd);
-        f2.save();
-
-        // create bookmark b2 inside folder f2
-        BookmarkData b2 = bmgr.createBookmark(
-            f2, "b2", "testbookmark",
-            "http://example.com", "http://example.com/rss",
-            new Integer(1), new Integer(1), "image.gif");
-        b2.save();
-
-        // create folder f3 inside folder f2
-        FolderData f3 = bmgr.createFolder();
-        f3.setName("f3");
-        f3.setParent(f2);
-        f3.setWebsite(wd);
-        f3.save();
-
-        // crete bookmark b3 inside folder f3
-        BookmarkData b3 = bmgr.createBookmark(
-            f3, "b3", "testbookmark",
-            "http://example.com", "http://example.com/rss",
-            new Integer(1), new Integer(1), "image.gif");
-        b3.save();
-
-        getRoller().commit();
-        
-        // test that parent cannot be moved into child
-        boolean safe = false;
-        try 
-        {
-            getRoller().begin(UserData.SYSTEM_USER);     
-                   
-            // Move folder into one of it's children
-            f1 = bmgr.retrieveFolder(f1.getId());       
-            f3 = bmgr.retrieveFolder(f3.getId());       
-            bmgr.moveFolderContents(f1, f3);
-            f3.save();
-            f1.save();
-            getRoller().commit(); 
-        }
-        catch (RollerException e)
-        {
-            safe = true;
-        }
-        assertTrue(safe);
-
-        getRoller().begin(UserData.SYSTEM_USER);
-
-        // verify number of entries in each folder
-        dest = bmgr.retrieveFolder(dest.getId());
-        f1 = bmgr.retrieveFolder(f1.getId());
-        assertEquals(0, dest.retrieveBookmarks(true).size());
-        assertEquals(0, dest.retrieveBookmarks(false).size());
-        assertEquals(1, f1.retrieveBookmarks(false).size());
-
-        List f1list = f1.retrieveBookmarks(true);
-        assertEquals(3, f1list.size());
-
-        // move contents of source category c1 to destination catetory dest
-        f1.moveContents(dest);
-
-        getRoller().commit();
-
-
-
-        getRoller().begin(UserData.SYSTEM_USER);
-
-        // after move, verify number of entries in eacch folder
-        dest = bmgr.retrieveFolder(dest.getId());
-        f1 = bmgr.retrieveFolder(f1.getId());
-        assertEquals(3, dest.retrieveBookmarks(true).size());
-        assertEquals(3, dest.retrieveBookmarks(false).size());
-        assertEquals(0, f1.retrieveBookmarks(true).size());
-        assertEquals(0, f1.retrieveBookmarks(false).size());
-
-        getRoller().commit();
-    }
-
-    /** Test bookmark folder paths. */
-    public void testPaths() throws Exception
-    {
-        WebsiteData wd = null;
-        BookmarkManager bmgr = getRoller().getBookmarkManager();
-        try
-        {
-            getRoller().begin(UserData.SYSTEM_USER);
-
-            wd = getRoller().getUserManager().retrieveWebsite(mWebsite.getId());
-            FolderData root = bmgr.getRootFolder(wd);
-
-            FolderData f1 = bmgr.createFolder();
-            f1.setName("f1");
-            f1.setParent(root);
-            f1.setWebsite(wd);
-            f1.save();
-
-            FolderData f2 = bmgr.createFolder();
-            f2.setName("f2");
-            f2.setParent(f1);
-            f2.setWebsite(wd);
-            f2.save();
-
-            FolderData f3 = bmgr.createFolder();
-            f3.setName("f3");
-            f3.setParent(f2);
-            f3.setWebsite(wd);
-            f3.save();
-
-            getRoller().commit();
-        }
-        catch (RollerException e)
-        {
-            getRoller().release();
-            mLogger.error(e);
-        }
-
-        try
-        {
-            getRoller().begin(UserData.SYSTEM_USER);
-
-            assertEquals("f1",bmgr.getFolderByPath(wd, null, "/f1").getName());
-            assertEquals("f2",bmgr.getFolderByPath(wd, null, "/f1/f2").getName());
-            assertEquals("f3",bmgr.getFolderByPath(wd, null, "/f1/f2/f3").getName());
-
-            FolderData f3 = bmgr.getFolderByPath(wd, null, "/f1/f2/f3");
-            String pathString = bmgr.getPath(f3);
-            String[] pathArray = Utilities.stringToStringArray(pathString,"/");
-            assertEquals("f1", pathArray[0]);
-            assertEquals("f2", pathArray[1]);
-            assertEquals("f3", pathArray[2]);
-
-            getRoller().release();
-        }
-        catch (RollerException e)
-        {
-            getRoller().release();
-            mLogger.error(e);
-        }
-    }
-
-    /** Ensure that duplicate folder name will throw RollerException */
-    public void testUniquenessOfFolderNames() throws Exception
-    {
-        boolean exception = false;
-        WebsiteData wd = null;
-        FolderData f3 = null;
-        BookmarkManager bmgr = getRoller().getBookmarkManager();
-        try
-        {
-            getRoller().begin(UserData.SYSTEM_USER);
-
-            wd = getRoller().getUserManager().retrieveWebsite(mWebsite.getId());
-            FolderData root = bmgr.getRootFolder(wd);
-
-            FolderData f1 = bmgr.createFolder();
-            f1.setName("f1");
-            f1.setParent(root);
-            f1.setWebsite(wd);
-            f1.save();
-
-            // first child folder
-            FolderData f2 = bmgr.createFolder();
-            f2.setName("f2");
-            f2.setParent(f1);
-            f2.setWebsite(wd);
-            f2.save();
-
-            getRoller().commit();
-
-            getRoller().begin(UserData.SYSTEM_USER);
-
-            // child folder with same name as first
-            f3 = bmgr.createFolder();
-            f3.setName("f2");
-            f3.setParent(f1);
-            f3.setWebsite(wd);
-            f3.save();
-
-            getRoller().commit();
-        }
-        catch (RollerException e)
-        {
-            exception = true;
-        }
-
-        assertTrue(exception);
-    }
-
-
+//    //------------------------------------------------------------------------
+//    public BookmarkManagerTest()
+//    {
+//        super();
+//    }
+//
+//    //------------------------------------------------------------------------
+//    public BookmarkManagerTest(String name)
+//    {
+//        super(name);
+//    }
+//
+//    //------------------------------------------------------------------------
+//    public static Test suite()
+//    {
+//        return new TestSuite(BookmarkManagerTest.class);
+//    }
+//
+//    //------------------------------------------------------------------------
+//    public static void main(String args[])
+//    {
+//        junit.textui.TestRunner.run( BookmarkManagerTest.class );
+//    }
+//
+//    //------------------------------------------------------------------------
+//
+//    public void testAddBookmarkToFolder() throws RollerException
+//    {
+//        BookmarkManager bmgr = getRoller().getBookmarkManager();
+//        FolderData folder = null;
+//        BookmarkData bookmark1 = null, bookmark2 = null;
+//
+//        getRoller().begin(UserData.SYSTEM_USER);
+//
+//        WebsiteData website =
+//            getRoller().getUserManager().retrieveWebsite(mWebsite.getId());
+//        FolderData root = bmgr.getRootFolder(website);
+//
+//        folder = bmgr.createFolder();
+//        folder.setName("TestFolder1");
+//        folder.setDescription("created by testAddBookmarkToFolder()");
+//        folder.setWebsite(website);
+//        folder.setParent(root);
+//        folder.save();
+//
+//        // Add bookmark by adding to folder
+//        bookmark1 = bmgr.createBookmark(
+//            folder,
+//            "TestBookmark1",
+//            "created by testAddBookmarkToFolder()",
+//            "http://www.example.com",
+//            "http://www.example.com/rss.xml",
+//            new Integer(1),
+//            new Integer(12),
+//            "test.jpg");
+//        folder.addBookmark(bookmark1);
+//
+//        // Add another bookmark
+//        bookmark2 = bmgr.createBookmark(
+//            folder,
+//            "TestBookmark2",
+//            "created by testAddBookmarkToFolder()",
+//            "http://www.example.com",
+//            "http://www.example.com/rss.xml",
+//            new Integer(1),
+//            new Integer(12),
+//            "test.jpf");
+//        folder.addBookmark(bookmark2);
+//
+//        getRoller().commit();
+//
+//        FolderData testFolder = null;
+//        BookmarkData bookmarkb = null, bookmarka = null;
+//
+//        getRoller().begin(UserData.SYSTEM_USER);
+//        // See that two bookmarks were stored
+//        testFolder = bmgr.retrieveFolder(folder.getId());
+//        assertEquals(2, testFolder.getBookmarks().size());
+//        bookmarka = (BookmarkData)testFolder.getBookmarks().iterator().next();
+//        bookmarkb = (BookmarkData)testFolder.getBookmarks().iterator().next();
+//        // Remove one bookmark
+//        testFolder.removeBookmark(bookmarka);
+//        bmgr.removeBookmark(bookmarka.getId());
+//        getRoller().commit();
+//
+//        getRoller().begin(UserData.SYSTEM_USER);
+//        // Folder should now contain one bookmark
+//        testFolder = bmgr.retrieveFolder(folder.getId());
+//        assertEquals(1, testFolder.getBookmarks().size());
+//        getRoller().release();
+//
+//        // Remove folder
+//        getRoller().begin(UserData.SYSTEM_USER);
+//        testFolder = bmgr.retrieveFolder(folder.getId());
+//        testFolder.remove();
+//        getRoller().commit();
+//
+//        getRoller().begin(UserData.SYSTEM_USER);
+//        // Folder and one remaining bookmark should be gone
+//        assertNull( bmgr.retrieveBookmark(bookmarkb.getId()) );
+//        assertNull( bmgr.retrieveFolder(folder.getId()) );
+//        getRoller().release();
+//    }
+//
+//    //------------------------------------------------------------------------
+//    public void testBookmarkImport() throws Exception
+//    {
+//        importBookmarks("/bookmarks.opml");
+//    }
+//
+//    //------------------------------------------------------------------------
+//    public void importBookmarks(String fileName) throws Exception
+//    {
+//        getRoller().begin(UserData.SYSTEM_USER);
+//        InputStream fis = this.getClass().getResourceAsStream(fileName);
+//        getRoller().getBookmarkManager().importBookmarks(
+//            mWebsite, "ZZZ_imports_ZZZ", fileToString(fis));
+//        getRoller().commit();
+//        getRoller().release();
+//
+//        FolderData fd = null;
+//
+//        getRoller().begin(UserData.SYSTEM_USER);
+//        fd = getRoller().getBookmarkManager().getFolder(mWebsite, "ZZZ_imports_ZZZ");
+//        assertTrue("no bookmarks found", fd.retrieveBookmarks(true).size() > 0 );
+//        fd.remove();
+//        getRoller().commit();
+//    }
+//
+//    //------------------------------------------------------------------------
+//    public String fileToString( InputStream is ) throws java.io.IOException
+//    {
+//        BufferedReader br = new BufferedReader(new InputStreamReader(is));
+//        String s = null;
+//        StringBuffer sb = new StringBuffer();
+//        while ( (s=br.readLine()) != null )
+//        {
+//            sb.append( s );
+//        }
+//        return sb.toString();
+//    }
+//
+//    //------------------------------------------------------------------------
+//
+//    /**
+//     * Creates folder tree like this:
+//     *    root/
+//     *       dest/
+//     *       f1/
+//     *          b1
+//     *          f2/
+//     *             f3/
+//     */
+//    public void testMoveFolderContents() throws RollerException
+//    {
+//        WebsiteData wd = null;
+//        BookmarkManager bmgr = getRoller().getBookmarkManager();
+//
+//        getRoller().begin(UserData.SYSTEM_USER);
+//
+//        wd = getRoller().getUserManager().retrieveWebsite(mWebsite.getId());
+//        FolderData root = bmgr.getRootFolder(wd);
+//
+//        FolderData dest = bmgr.createFolder();
+//        dest.setName("dest");
+//        dest.setParent(root);
+//        dest.setWebsite(wd);
+//        dest.save();
+//
+//        // create source folder f1
+//        FolderData f1 = bmgr.createFolder();
+//        f1.setName("f1");
+//        f1.setParent(root);
+//        f1.setWebsite(wd);
+//        f1.save();
+//
+//        // create bookmark b1 inside source folder f1
+//        BookmarkData b1 = bmgr.createBookmark(
+//            f1, "b1", "testbookmark",
+//            "http://example.com", "http://example.com/rss",
+//            new Integer(1), new Integer(1), "image.gif");
+//        b1.save();
+//
+//        // create folder f2 inside f1
+//        FolderData f2 = bmgr.createFolder();
+//        f2.setName("f2");
+//        f2.setParent(f1);
+//        f2.setWebsite(wd);
+//        f2.save();
+//
+//        // create bookmark b2 inside folder f2
+//        BookmarkData b2 = bmgr.createBookmark(
+//            f2, "b2", "testbookmark",
+//            "http://example.com", "http://example.com/rss",
+//            new Integer(1), new Integer(1), "image.gif");
+//        b2.save();
+//
+//        // create folder f3 inside folder f2
+//        FolderData f3 = bmgr.createFolder();
+//        f3.setName("f3");
+//        f3.setParent(f2);
+//        f3.setWebsite(wd);
+//        f3.save();
+//
+//        // crete bookmark b3 inside folder f3
+//        BookmarkData b3 = bmgr.createBookmark(
+//            f3, "b3", "testbookmark",
+//            "http://example.com", "http://example.com/rss",
+//            new Integer(1), new Integer(1), "image.gif");
+//        b3.save();
+//
+//        getRoller().commit();
+//        
+//        // test that parent cannot be moved into child
+//        boolean safe = false;
+//        try 
+//        {
+//            getRoller().begin(UserData.SYSTEM_USER);     
+//                   
+//            // Move folder into one of it's children
+//            f1 = bmgr.retrieveFolder(f1.getId());       
+//            f3 = bmgr.retrieveFolder(f3.getId());       
+//            bmgr.moveFolderContents(f1, f3);
+//            f3.save();
+//            f1.save();
+//            getRoller().commit(); 
+//        }
+//        catch (RollerException e)
+//        {
+//            safe = true;
+//        }
+//        assertTrue(safe);
+//
+//        getRoller().begin(UserData.SYSTEM_USER);
+//
+//        // verify number of entries in each folder
+//        dest = bmgr.retrieveFolder(dest.getId());
+//        f1 = bmgr.retrieveFolder(f1.getId());
+//        assertEquals(0, dest.retrieveBookmarks(true).size());
+//        assertEquals(0, dest.retrieveBookmarks(false).size());
+//        assertEquals(1, f1.retrieveBookmarks(false).size());
+//
+//        List f1list = f1.retrieveBookmarks(true);
+//        assertEquals(3, f1list.size());
+//
+//        // move contents of source category c1 to destination catetory dest
+//        f1.moveContents(dest);
+//
+//        getRoller().commit();
+//
+//
+//
+//        getRoller().begin(UserData.SYSTEM_USER);
+//
+//        // after move, verify number of entries in eacch folder
+//        dest = bmgr.retrieveFolder(dest.getId());
+//        f1 = bmgr.retrieveFolder(f1.getId());
+//        assertEquals(3, dest.retrieveBookmarks(true).size());
+//        assertEquals(3, dest.retrieveBookmarks(false).size());
+//        assertEquals(0, f1.retrieveBookmarks(true).size());
+//        assertEquals(0, f1.retrieveBookmarks(false).size());
+//
+//        getRoller().commit();
+//    }
+//
+//    /** Test bookmark folder paths. */
+//    public void testPaths() throws Exception
+//    {
+//        WebsiteData wd = null;
+//        BookmarkManager bmgr = getRoller().getBookmarkManager();
+//        try
+//        {
+//            getRoller().begin(UserData.SYSTEM_USER);
+//
+//            wd = getRoller().getUserManager().retrieveWebsite(mWebsite.getId());
+//            FolderData root = bmgr.getRootFolder(wd);
+//
+//            FolderData f1 = bmgr.createFolder();
+//            f1.setName("f1");
+//            f1.setParent(root);
+//            f1.setWebsite(wd);
+//            f1.save();
+//
+//            FolderData f2 = bmgr.createFolder();
+//            f2.setName("f2");
+//            f2.setParent(f1);
+//            f2.setWebsite(wd);
+//            f2.save();
+//
+//            FolderData f3 = bmgr.createFolder();
+//            f3.setName("f3");
+//            f3.setParent(f2);
+//            f3.setWebsite(wd);
+//            f3.save();
+//
+//            getRoller().commit();
+//        }
+//        catch (RollerException e)
+//        {
+//            getRoller().release();
+//            mLogger.error(e);
+//        }
+//
+//        try
+//        {
+//            getRoller().begin(UserData.SYSTEM_USER);
+//
+//            assertEquals("f1",bmgr.getFolderByPath(wd, null, "/f1").getName());
+//            assertEquals("f2",bmgr.getFolderByPath(wd, null, "/f1/f2").getName());
+//            assertEquals("f3",bmgr.getFolderByPath(wd, null, "/f1/f2/f3").getName());
+//
+//            FolderData f3 = bmgr.getFolderByPath(wd, null, "/f1/f2/f3");
+//            String pathString = bmgr.getPath(f3);
+//            String[] pathArray = Utilities.stringToStringArray(pathString,"/");
+//            assertEquals("f1", pathArray[0]);
+//            assertEquals("f2", pathArray[1]);
+//            assertEquals("f3", pathArray[2]);
+//
+//            getRoller().release();
+//        }
+//        catch (RollerException e)
+//        {
+//            getRoller().release();
+//            mLogger.error(e);
+//        }
+//    }
+//
+//    /** Ensure that duplicate folder name will throw RollerException */
+//    public void testUniquenessOfFolderNames() throws Exception
+//    {
+//        boolean exception = false;
+//        WebsiteData wd = null;
+//        FolderData f3 = null;
+//        BookmarkManager bmgr = getRoller().getBookmarkManager();
+//        try
+//        {
+//            getRoller().begin(UserData.SYSTEM_USER);
+//
+//            wd = getRoller().getUserManager().retrieveWebsite(mWebsite.getId());
+//            FolderData root = bmgr.getRootFolder(wd);
+//
+//            FolderData f1 = bmgr.createFolder();
+//            f1.setName("f1");
+//            f1.setParent(root);
+//            f1.setWebsite(wd);
+//            f1.save();
+//
+//            // first child folder
+//            FolderData f2 = bmgr.createFolder();
+//            f2.setName("f2");
+//            f2.setParent(f1);
+//            f2.setWebsite(wd);
+//            f2.save();
+//
+//            getRoller().commit();
+//
+//            getRoller().begin(UserData.SYSTEM_USER);
+//
+//            // child folder with same name as first
+//            f3 = bmgr.createFolder();
+//            f3.setName("f2");
+//            f3.setParent(f1);
+//            f3.setWebsite(wd);
+//            f3.save();
+//
+//            getRoller().commit();
+//        }
+//        catch (RollerException e)
+//        {
+//            exception = true;
+//        }
+//
+//        assertTrue(exception);
+//    }
+//
+//
 }
-
-
-
-
-
-
-
+//
+//
+//
+//
+//
+//
+//

Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/business/FileManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/FileManagerTest.java?rev=392622&r1=392621&r2=392622&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/FileManagerTest.java (original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/FileManagerTest.java Sat Apr  8 15:42:58 2006
@@ -115,7 +115,6 @@
         // do some setup for our test
         Roller mRoller = RollerFactory.getRoller();       
         UserManager umgr = mRoller.getUserManager();
-        mRoller.begin(UserData.SYSTEM_USER);
         UserData user = new UserData(null,
                 "FileManagerTest_userName",  
                 "FileManagerTest_password",       

Added: incubator/roller/branches/roller-newbackend/tests/org/roller/business/PermissionTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/PermissionTest.java?rev=392622&view=auto
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/PermissionTest.java (added)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/PermissionTest.java Sat Apr  8 15:42:58 2006
@@ -0,0 +1,219 @@
+package org.roller.business;
+
+import java.util.List;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.roller.TestUtils;
+import org.roller.model.RollerFactory;
+import org.roller.model.UserManager;
+import org.roller.pojos.PermissionsData;
+import org.roller.pojos.UserData;
+import org.roller.pojos.WebsiteData;
+
+
+/**
+ * Test User/Weblog Permissions related business operations.
+ *
+ * That includes:
+ *   - creating permissions for a user/weblog
+ *   - updating permissions for a user/weblog
+ *   - deleting permissions for a user/weblog
+ *   - get all permissions for a user
+ *   - get all permissions for a weblog
+ *   - get pending permissions for a user
+ *   - get pending permissions for a weblog
+ *   - get permissions by id
+ *   - get permissions for a specific user/weblog
+ *   - user can be invited to website
+ *   - user can retire from website
+ *
+ */
+public class PermissionTest extends TestCase {
+    
+    UserData testUser = null;
+    WebsiteData testWeblog = null;
+    
+    
+    public PermissionTest(String name) {
+        super(name);
+    }
+    
+    
+    public static Test suite() {
+        return new TestSuite(PermissionTest.class);
+    }
+    
+    
+    /**
+     * All tests in this suite require a user and a weblog.
+     */
+    public void setUp() throws Exception {
+        testUser = TestUtils.setupUser("permsTestUser");
+        testWeblog = TestUtils.setupWeblog("permsTestWeblog", testUser);
+    }
+    
+    public void tearDown() throws Exception {
+        TestUtils.teardownWeblog(testWeblog.getHandle());
+        TestUtils.teardownUser(testUser.getUserName());
+    }
+    
+    
+    /**
+     * Test basic persistence operations ... Create, Update, Delete
+     */
+    public void testPermissionsCRUD() throws Exception {
+        
+        UserManager mgr = RollerFactory.getRoller().getUserManager();
+        PermissionsData perm = null;
+        
+        // delete permissions
+        perm = mgr.getPermissions(testWeblog, testUser);
+        assertNotNull(perm);
+        mgr.removePermissions(perm);
+        
+        // check that delete was successful
+        perm = null;
+        perm = mgr.getPermissions(testWeblog, testUser);
+        assertNull(perm);
+        
+        // create permissions
+        perm = new PermissionsData();
+        perm.setUser(testUser);
+        perm.setWebsite(testWeblog);
+        perm.setPending(false);
+        perm.setPermissionMask(PermissionsData.ADMIN);
+        mgr.storePermissions(perm);
+        
+        // check that create was successful
+        perm = null;
+        perm = mgr.getPermissions(testWeblog, testUser);
+        assertNotNull(perm);
+        assertEquals(PermissionsData.ADMIN, perm.getPermissionMask());
+        
+        // update permissions
+        perm.setPermissionMask(PermissionsData.LIMITED);
+        mgr.storePermissions(perm);
+        
+        // check that update was successful
+        perm = null;
+        perm = mgr.getPermissions(testWeblog, testUser);
+        assertNotNull(perm);
+        assertEquals(PermissionsData.LIMITED, perm.getPermissionMask());
+    }
+    
+    
+    /**
+     * Test lookup mechanisms ...
+     */
+    public void testPermissionsLookups() throws Exception {
+        
+        // we need a second user for this test
+        UserData user = TestUtils.setupUser("foofoo");
+        
+        UserManager mgr = RollerFactory.getRoller().getUserManager();
+        PermissionsData perm = null;
+        List perms = null;
+        
+        // get all permissions for a user
+        perms = mgr.getAllPermissions(user);
+        assertEquals(0, perms.size());
+        perms = mgr.getAllPermissions(testUser);
+        assertEquals(1, perms.size());
+        
+        // get all permissions for a weblog
+        perms = mgr.getAllPermissions(testWeblog);
+        assertEquals(1, perms.size());
+        
+        perm = new PermissionsData();
+        perm.setUser(user);
+        perm.setWebsite(testWeblog);
+        perm.setPending(true);
+        perm.setPermissionMask(PermissionsData.AUTHOR);
+        mgr.storePermissions(perm);
+        
+        // get pending permissions for a user
+        perms = mgr.getPendingPermissions(testUser);
+        assertEquals(0, perms.size());
+        perms = mgr.getPendingPermissions(user);
+        assertEquals(1, perms.size());
+        
+        // get pending permissions for a weblog
+        perms = mgr.getPendingPermissions(testWeblog);
+        assertEquals(1, perms.size());
+        
+        // get permissions by id
+        String id = perm.getId();
+        perm = null;
+        perm = mgr.retrievePermissions(id);
+        assertNotNull(perm);
+        assertEquals(id, perm.getId());
+        
+        // get permissions for a specific user/weblog
+        perm = null;
+        perm = mgr.getPermissions(testWeblog, testUser);
+        assertNotNull(perm);
+        assertEquals(PermissionsData.ADMIN, perm.getPermissionMask());
+        perm = null;
+        perm = mgr.getPermissions(testWeblog, user);
+        assertNotNull(perm);
+        assertEquals(PermissionsData.AUTHOR, perm.getPermissionMask());
+        assertEquals(true, perm.isPending());
+        
+        // cleanup the extra test user
+        TestUtils.teardownUser(user.getUserName());
+    }
+    
+    
+    /**
+     * Tests weblog invitation process.
+     */
+    public void testInvitations() throws Exception {
+        
+        // we need a second user for this test
+        UserData user = TestUtils.setupUser("foobee");
+        
+        UserManager mgr = RollerFactory.getRoller().getUserManager();
+        PermissionsData perm = null;
+        List perms = null;
+        
+        // invite user to weblog
+        perm = mgr.inviteUser(testWeblog, user, PermissionsData.LIMITED);
+        String id = perm.getId();
+        
+        // accept invitation
+        perm = mgr.getPermissions(testWeblog, user);
+        perm.setPending(false);
+        mgr.storePermissions(perm);
+        
+        // re-query now that we have changed things
+        user = mgr.getUser(user.getUserName());
+        testWeblog = mgr.getWebsiteByHandle(testWeblog.getHandle());
+        
+        // assert that invitation list is empty
+        assertTrue(mgr.getPendingPermissions(user).isEmpty());
+        assertTrue(mgr.getPendingPermissions(testWeblog).isEmpty());
+        
+        // assert that user is member of weblog
+        assertFalse(mgr.getPermissions(testWeblog, user).isPending());
+        List weblogs = mgr.getWebsites(user, null, null);
+        assertEquals(1, weblogs.size());
+        assertEquals(testWeblog.getId(), ((WebsiteData)weblogs.get(0)).getId());
+        
+        // assert that website has user
+        List users = mgr.getUsers(testWeblog, null);
+        assertEquals(2, users.size());
+        
+        // test user can be retired from website
+        mgr.retireUser(testWeblog, user);
+        
+        user = mgr.retrieveUser(user.getId());
+        weblogs = mgr.getWebsites(user, null, null);
+        assertEquals(0, weblogs.size());
+        
+        // cleanup the extra test user
+        TestUtils.teardownUser(user.getUserName());
+    }
+    
+}
+

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=392622&r1=392621&r2=392622&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 Sat Apr  8 15:42:58 2006
@@ -50,426 +50,426 @@
     {
         junit.textui.TestRunner.run(PlanetManagerTest.class);
     }
-
-    /**
-     * @see TestCase#setUp()
-     */
-    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();
-            PlanetConfigData config = planet.getConfiguration();
-            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();
-        }
-        {   // remove config
-            roller.begin();
-            PlanetConfigData config = planet.getConfiguration();
-            config.remove();            
-            roller.commit();
-        }
-        {
-            // make sure config and group are gone
-            roller.begin();
-            PlanetConfigData config = planet.getConfiguration();
-            assertNull(config);
-            PlanetGroupData group = planet.getGroup("test_handle");
-            assertNull(group);
-            roller.rollback();
-        }
-    }
-    public void testGroupStorage() throws Exception
-    {
-        Roller roller = getRoller();
-        assertNotNull(roller);       
-        PlanetManager planet = roller.getPlanetManager();
-        assertNotNull(planet);  
-        
-        {   // 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);        
-        
-        {   // 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");
-            group.setTitle("test_title");
-            planet.saveGroup(group);
-            
-            PlanetSubscriptionData sub = planet.getSubscription("test_url");
-            assertNotNull(sub);
-            group.addSubscription(sub);
-            
-            PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
-            sub1.setFeedUrl("test_url1");
-            planet.saveSubscription(sub1);
-            
-            List subs = new ArrayList();
-            subs.add(sub1);
-            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");
-            assertNotNull(sub);
-            PlanetSubscriptionData sub1 = planet.getSubscription("test_url1");
-            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);        
-        
-        {   // 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);
-            
-            PlanetEntryData entry1 = new PlanetEntryData();
-            entry1.setPermalink("test_entry1");
-            entry1.setCategoriesString("test,test2");
-            entry1.setSubscription(sub);
-            entry1.setPublished(new Date());
-            entry1.save();
-            sub.addEntry(entry1);
-            
-            PlanetEntryData entry2 = new PlanetEntryData();
-            entry2.setPermalink("test_entry2");
-            entry2.setCategoriesString("test_cat1,test_cat2,test_cat3");
-            entry2.setSubscription(sub);
-            entry2.setPublished(new Date());
-            entry2.save();
-            sub.addEntry(entry2);
-            
-            roller.commit();
-        }
-        {   // get sub and check it's entries, remove it
-            roller.begin();
-            PlanetSubscriptionData sub = planet.getSubscription("test_url");
-            assertEquals(2, sub.getEntries().size());
-            planet.deleteSubscription(sub);
-            roller.commit();
-        }
-        {   // make sure sub is gone
-            roller.begin();
-            PlanetSubscriptionData 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 testAggregations() throws Exception
-    {
-        try 
-        {
-            Roller roller = getRoller();
-            assertNotNull(roller);       
-            PlanetManager planet = roller.getPlanetManager();
-            assertNotNull(planet);     
-            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");
-                group.setTitle("test_title");
-                planet.saveGroup(group);
-                
-                PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
-                sub1.setFeedUrl(feed_url1);
-                planet.saveSubscription(sub1);
-                
-                PlanetSubscriptionData sub2 = new PlanetSubscriptionData();
-                sub2.setFeedUrl(feed_url2);
-                planet.saveSubscription(sub2);
-                
-                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()) 
-                {
-                    PlanetSubscriptionData sub= (PlanetSubscriptionData)subs.next();
-                    count += sub.getEntries().size();    
-                }
-                PlanetSubscriptionData sub1 = planet.getSubscription(feed_url1);
-                assertTrue(sub1.getEntries().size() > 0);
-                PlanetSubscriptionData sub2 = planet.getSubscription(feed_url2);
-                assertTrue(sub2.getEntries().size() > 0);
-                assertEquals(count, sub1.getEntries().size() + sub2.getEntries().size());
-                
-                PlanetGroupData group = planet.getGroup("test_handle");
-                assertNotNull(group);
-    
-                List bigag = planet.getAggregation(group, 30);
-                assertEquals(30, bigag.size());
-                      
-                List littleag = planet.getAggregation(group, 10);
-                assertEquals(10, littleag.size());
-                                  
-                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);     
-            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);
-    }
+//
+//    /**
+//     * @see TestCase#setUp()
+//     */
+//    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();
+//            PlanetConfigData config = planet.getConfiguration();
+//            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();
+//        }
+//        {   // remove config
+//            roller.begin();
+//            PlanetConfigData config = planet.getConfiguration();
+//            config.remove();            
+//            roller.commit();
+//        }
+//        {
+//            // make sure config and group are gone
+//            roller.begin();
+//            PlanetConfigData config = planet.getConfiguration();
+//            assertNull(config);
+//            PlanetGroupData group = planet.getGroup("test_handle");
+//            assertNull(group);
+//            roller.rollback();
+//        }
+//    }
+//    public void testGroupStorage() throws Exception
+//    {
+//        Roller roller = getRoller();
+//        assertNotNull(roller);       
+//        PlanetManager planet = roller.getPlanetManager();
+//        assertNotNull(planet);  
+//        
+//        {   // 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);        
+//        
+//        {   // 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");
+//            group.setTitle("test_title");
+//            planet.saveGroup(group);
+//            
+//            PlanetSubscriptionData sub = planet.getSubscription("test_url");
+//            assertNotNull(sub);
+//            group.addSubscription(sub);
+//            
+//            PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
+//            sub1.setFeedUrl("test_url1");
+//            planet.saveSubscription(sub1);
+//            
+//            List subs = new ArrayList();
+//            subs.add(sub1);
+//            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");
+//            assertNotNull(sub);
+//            PlanetSubscriptionData sub1 = planet.getSubscription("test_url1");
+//            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);        
+//        
+//        {   // 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);
+//            
+//            PlanetEntryData entry1 = new PlanetEntryData();
+//            entry1.setPermalink("test_entry1");
+//            entry1.setCategoriesString("test,test2");
+//            entry1.setSubscription(sub);
+//            entry1.setPublished(new Date());
+//            entry1.save();
+//            sub.addEntry(entry1);
+//            
+//            PlanetEntryData entry2 = new PlanetEntryData();
+//            entry2.setPermalink("test_entry2");
+//            entry2.setCategoriesString("test_cat1,test_cat2,test_cat3");
+//            entry2.setSubscription(sub);
+//            entry2.setPublished(new Date());
+//            entry2.save();
+//            sub.addEntry(entry2);
+//            
+//            roller.commit();
+//        }
+//        {   // get sub and check it's entries, remove it
+//            roller.begin();
+//            PlanetSubscriptionData sub = planet.getSubscription("test_url");
+//            assertEquals(2, sub.getEntries().size());
+//            planet.deleteSubscription(sub);
+//            roller.commit();
+//        }
+//        {   // make sure sub is gone
+//            roller.begin();
+//            PlanetSubscriptionData 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 testAggregations() throws Exception
+//    {
+//        try 
+//        {
+//            Roller roller = getRoller();
+//            assertNotNull(roller);       
+//            PlanetManager planet = roller.getPlanetManager();
+//            assertNotNull(planet);     
+//            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");
+//                group.setTitle("test_title");
+//                planet.saveGroup(group);
+//                
+//                PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
+//                sub1.setFeedUrl(feed_url1);
+//                planet.saveSubscription(sub1);
+//                
+//                PlanetSubscriptionData sub2 = new PlanetSubscriptionData();
+//                sub2.setFeedUrl(feed_url2);
+//                planet.saveSubscription(sub2);
+//                
+//                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()) 
+//                {
+//                    PlanetSubscriptionData sub= (PlanetSubscriptionData)subs.next();
+//                    count += sub.getEntries().size();    
+//                }
+//                PlanetSubscriptionData sub1 = planet.getSubscription(feed_url1);
+//                assertTrue(sub1.getEntries().size() > 0);
+//                PlanetSubscriptionData sub2 = planet.getSubscription(feed_url2);
+//                assertTrue(sub2.getEntries().size() > 0);
+//                assertEquals(count, sub1.getEntries().size() + sub2.getEntries().size());
+//                
+//                PlanetGroupData group = planet.getGroup("test_handle");
+//                assertNotNull(group);
+//    
+//                List bigag = planet.getAggregation(group, 30);
+//                assertEquals(30, bigag.size());
+//                      
+//                List littleag = planet.getAggregation(group, 10);
+//                assertEquals(10, littleag.size());
+//                                  
+//                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);     
+//            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