roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r392622 [2/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
Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/business/RefererManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/RefererManagerTest.java?rev=392622&r1=392621&r2=392622&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/RefererManagerTest.java
(original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/RefererManagerTest.java
Sat Apr  8 15:42:58 2006
@@ -1 +1 @@
-package org.roller.business; 

import java.sql.Timestamp;
import java.util.Calendar;
import
java.util.Date;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.roller.RollerException;
import org.roller.model.PropertiesManager;
import org.roller.model.RefererManager;
import
org.roller.model.Roller;
import org.roller.pojos.RefererData;
import org.roller.pojos.RollerPropertyData;
import
org.roller.pojos.UserData;
import org.roller.pojos.WeblogEntryData;
import org.roller.pojos.WebsiteData;
import
org.roller.util.DateUtil;
import org.roller.RollerTestBase;

/**
 * Test Roller Referer Management.
*/
public class RefererManagerTest extends RollerTestBase 
{
    RefererManager rmgr;
   
//List refs;
    int count = 20;        
    String testDay;
    String origSpamWords;

 
  //------------------------------------------------------------------------
	public RefererManagerTest(String
name) 
    {
		super(name);
	}
    
    //--------
 ----------------------------------------------------------------
	public static void main(String
args[]) 
    {
		junit.textui.TestRunner.run(RefererManagerTest.class);
	}
    
    //------------------------------------------------------------------------
   public static Test suite() 
    {
        return new TestSuite(RefererManagerTest.class);
   }

    public void setUp() throws Exception
    {
        super.setUp();
        
    
   // add "spamtest" to refererSpamWords
        Roller mRoller = getRoller();
        PropertiesManager
pmgr = mRoller.getPropertiesManager();
        RollerPropertyData spamprop = pmgr.getProperty("spam.blacklist");
       this.origSpamWords = spamprop.getValue();
        spamprop.setValue(spamprop.getValue()
+ ", spamtest");
        pmgr.store(spamprop);
        
        // Process count unique referers
       rmgr = getRoller().getRefererManager();
        Calendar lCalendar = Calendar.getInstance();
       lCalendar.setTime(new Date()
 );
        for (int i = 0; i < count; i++)
        {
            lCalendar.add(Calendar.DATE,
-1);
            Timestamp day = new Timestamp(lCalendar.getTime().getTime());
          
 testDay = DateUtil.format8chars(day);
            
            getRoller().begin(UserData.SYSTEM_USER);
           /*
            MockRequest mock = new MockRequest(
                           
    DateUtil.format8chars(day),
                                "http://test"+i,
        
                       "http://test"+i,
                                null,
           
                    mWebsite
            );
            rmgr.processRequest(mock);
      
     */
            rmgr.processReferrer("http://test"+i, "http://test"+i, 
             
      mWebsite.getHandle(), null, testDay);
            getRoller().commit();
           

            //testDay = mock.getDateString();
        }
    }

    public void tearDown()
throws Exception
    {      
        List refs = rmgr.getReferers(mW
 ebsite);
        // Remove all referers processes
        for (int i = 0; i < refs.size();
i++)
        {
            rmgr.removeReferer(((RefererData)refs.get(i)).getId());    
  
     }
        
        // Make sure all were removed
        refs = rmgr.getReferers(mWebsite);
           
        assertEquals(0,refs.size());

        // reset refererSpamWords to original
value
        Roller mRoller = getRoller();
        PropertiesManager pmgr = mRoller.getPropertiesManager();
       RollerPropertyData spamprop = pmgr.getProperty("spam.blacklist");
        spamprop.setValue(this.origSpamWords);
       pmgr.store(spamprop);
        
        super.tearDown();
    }
    
    //------------------------------------------------------------------------
   public void testGetReferersToDate() throws Exception
    {
        List referers = rmgr.getReferersToDate(mWebsite,
testDay);
        assertEquals("Should be one Referer.", referers.size(), 1);
    }
    
   //---------------
 ---------------------------------------------------------
    public void testRefererProcessing()
throws RollerException
    {
        List refs = rmgr.getReferers(mWebsite);            
       assertEquals("number of referers should equal count", count, refs.size());
       

        int hits = rmgr.getDayHits(mWebsite);
        assertEquals("There should be one fewer
hits than referers", count, hits);         
    }
    
    /* Self-Referrer Denial is now
caught by the RefererFilter -- Allen G
    public void testSelfRefererDenial() throws RollerException
   {
        // test against "self referrals"
        getRoller().begin(UserData.SYSTEM_USER);
       // create "direct" referer
        boolean isSpam = rmgr.processRequest(
         
  new MockRequest(
                "20020101",
                "direct",
                "http://test.com",
               null, mWebsite
            )
        );
        getRoller().commit();
    
   assertFalse("is not spam", isSpam);
 
        int newRefCount = rmgr.getReferers(mWebsite).size();
        
        // now create
self-referer
        getRoller().begin(UserData.SYSTEM_USER);
        
        isSpam = rmgr.processRequest(
           new MockRequest(
                "20020202",
                "http://test.com/page/"
+ mWebsite.getHandle(),
                "http://test.com",
                null, mWebsite
           )
        );
        getRoller().commit();
        assertFalse("is not spam", isSpam);
       
        // number of referrers should not have changed
        List refs = rmgr.getReferers(mWebsite);
           
        assertEquals("self referal not ignored", newRefCount, refs.size()); 
       
        // now create self-referer from editor page
        isSpam = rmgr.processRequest(
           new MockRequest(
                "20020202",
                "http://test.com/weblog.do",
               "http://test.com",
                null, mWebsite
            )
        );
       
 getRoller().commit();
        assertFalse("is not spam", isSpam);
        
        // number
of referrers should not have changed
        refs = rmgr.getReferers(mWebsite);          
 
        assertEquals("editor referal not ignored", newRefCount, refs.size()); 
    }
  
 */
    
    /**
     * Test to see if Referer Spam detection works.
     */
    /* Referrer
spam detection now happens in the RefererFilter -- Allen G
    public void testSpamBlocking()
   {
        boolean isSpam = rmgr.processRequest(
            new MockRequest(
         
      "20040101",
                "http://www.spamtest.com",
                "http://test.com",
               null, mWebsite
            )
        );
        //assertTrue("failed to detect
referer spam", isSpam);
    }
    */
    
    public void testApplyRefererFilters() throws
Exception
    {
        List refs = rmgr.getReferers(mWebsite);
        assertEquals(count,
refs.size());
        String origWords = null;
        
        
 getRoller().begin(UserData.SYSTEM_USER);
        Roller mRoller = getRoller();
        PropertiesManager
pmgr = mRoller.getPropertiesManager();
        RollerPropertyData spamprop = pmgr.getProperty("spam.blacklist");
       origWords = spamprop.getValue();
        spamprop.setValue(spamprop.getValue() + ",
test");
        pmgr.store(spamprop);
        getRoller().commit();
        
        getRoller().begin(UserData.SYSTEM_USER);
       getRoller().getRefererManager().applyRefererFilters();
        getRoller().commit();
       
        refs = rmgr.getReferers(mWebsite);
        assertEquals(0, refs.size());

       getRoller().begin(UserData.SYSTEM_USER);
        spamprop = pmgr.getProperty("spam.blacklist");
       spamprop.setValue(origWords);
        pmgr.store(spamprop);
        getRoller().commit();
   }
    
    public void testApplyRefererFiltersWebsite() throws Exception
    {
       
List refs = rmgr.getReferers(mWebsite);
        assertEquals(count, refs.siz
 e());
        String origWords = null;
        
        getRoller().begin(UserData.SYSTEM_USER);
       mWebsite = getRoller().getUserManager().retrieveWebsite(mWebsite.getId());
       
origWords = mWebsite.getBlacklist();
        mWebsite.setBlacklist("test");
        mWebsite.save();
       getRoller().commit();
        
        getRoller().begin(UserData.SYSTEM_USER);
  
     getRoller().getRefererManager().applyRefererFilters();
        getRoller().commit();
       
        refs = rmgr.getReferers(mWebsite);
        assertEquals(0, refs.size());
   }
}
\ No newline at end of file
+package org.roller.business; 

import java.sql.Timestamp;
import java.util.Calendar;
import
java.util.Date;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.roller.RollerException;
import org.roller.model.PropertiesManager;
import org.roller.model.RefererManager;
import
org.roller.model.Roller;
import org.roller.pojos.RefererData;
import org.roller.pojos.RollerPropertyData;
import
org.roller.pojos.UserData;
import org.roller.pojos.WeblogEntryData;
import org.roller.pojos.WebsiteData;
import
org.roller.util.DateUtil;
import org.roller.RollerTestBase;

/**
 * Test Roller Referer Management.
*/
public class RefererManagerTest extends RollerTestBase 
{
    RefererManager rmgr;
   
//List refs;
    int count = 20;        
    String testDay;
    String origSpamWords;

 
  //------------------------------------------------------------------------
	public RefererManagerTest(String
name) 
    {
		super(name);
	}
    
    //--------
 ----------------------------------------------------------------
	public static void main(String
args[]) 
    {
		junit.textui.TestRunner.run(RefererManagerTest.class);
	}
    
    //------------------------------------------------------------------------
   public static Test suite() 
    {
        return new TestSuite(RefererManagerTest.class);
   }

    public void setUp() throws Exception
    {
        super.setUp();
        
    
   // add "spamtest" to refererSpamWords
        Roller mRoller = getRoller();
        PropertiesManager
pmgr = mRoller.getPropertiesManager();
        RollerPropertyData spamprop = pmgr.getProperty("spam.blacklist");
       this.origSpamWords = spamprop.getValue();
        spamprop.setValue(spamprop.getValue()
+ ", spamtest");
        pmgr.store(spamprop);
        
        // Process count unique referers
       rmgr = getRoller().getRefererManager();
        Calendar lCalendar = Calendar.getInstance();
       lCalendar.setTime(new Date()
 );
        for (int i = 0; i < count; i++)
        {
            lCalendar.add(Calendar.DATE,
-1);
            Timestamp day = new Timestamp(lCalendar.getTime().getTime());
          
 testDay = DateUtil.format8chars(day);
            
            /*
            MockRequest
mock = new MockRequest(
                                DateUtil.format8chars(day),
     
                          "http://test"+i,
                                "http://test"+i,
                               null,
                                mWebsite
           
);
            rmgr.processRequest(mock);
            */
            rmgr.processReferrer("http://test"+i,
"http://test"+i, 
                    mWebsite.getHandle(), null, testDay);
            getRoller().commit();
           
            //testDay = mock.getDateString();
        }
    }

    public void
tearDown() throws Exception
    {      
        List refs = rmgr.getReferers(mWebsite);
 
      // Remove all referers processes
   
      for (int i = 0; i < refs.size(); i++)
        {
            rmgr.removeReferer(((RefererData)refs.get(i)).getId());
   
        }
        
        // Make sure all were removed
        refs = rmgr.getReferers(mWebsite);
           
        assertEquals(0,refs.size());

        // reset refererSpamWords to original
value
        Roller mRoller = getRoller();
        PropertiesManager pmgr = mRoller.getPropertiesManager();
       RollerPropertyData spamprop = pmgr.getProperty("spam.blacklist");
        spamprop.setValue(this.origSpamWords);
       pmgr.store(spamprop);
        
        super.tearDown();
    }
    
    //------------------------------------------------------------------------
   public void testGetReferersToDate() throws Exception
    {
        List referers = rmgr.getReferersToDate(mWebsite,
testDay);
        assertEquals("Should be one Referer.", referers.size(), 1);
    }
    
   //--------------------------------------------------------------------
 ----
    public void testRefererProcessing() throws RollerException
    {
        List refs
= rmgr.getReferers(mWebsite);            
        assertEquals("number of referers should
equal count", count, refs.size());
        
        int hits = rmgr.getDayHits(mWebsite);
       assertEquals("There should be one fewer hits than referers", count, hits);        

    }
    
    /* Self-Referrer Denial is now caught by the RefererFilter -- Allen G
   
public void testSelfRefererDenial() throws RollerException
    {
        // test against "self
referrals"
        getRoller().begin(UserData.SYSTEM_USER);
        // create "direct" referer
       boolean isSpam = rmgr.processRequest(
            new MockRequest(
               
"20020101",
                "direct",
                "http://test.com",
                null,
mWebsite
            )
        );
        getRoller().commit();
        assertFalse("is not
spam", isSpam);
        int newRefCount = rmgr.getReferers(mWebsite)
 .size();
        
        // now create self-referer
        getRoller().begin(UserData.SYSTEM_USER);
       
        isSpam = rmgr.processRequest(
            new MockRequest(
              
 "20020202",
                "http://test.com/page/" + mWebsite.getHandle(),
            
   "http://test.com",
                null, mWebsite
            )
        );
        getRoller().commit();
       assertFalse("is not spam", isSpam);
        
        // number of referrers should
not have changed
        List refs = rmgr.getReferers(mWebsite);            
        assertEquals("self
referal not ignored", newRefCount, refs.size()); 
        
        // now create self-referer
from editor page
        isSpam = rmgr.processRequest(
            new MockRequest(
     
          "20020202",
                "http://test.com/weblog.do",
                "http://test.com",
               null, mWebsite
            )
        );
        getRoller().commit();
    
   assertFalse("is not spa
 m", isSpam);
        
        // number of referrers should not have changed
        refs
= rmgr.getReferers(mWebsite);            
        assertEquals("editor referal not ignored",
newRefCount, refs.size()); 
    }
    */
    
    /**
     * Test to see if Referer Spam detection
works.
     */
    /* Referrer spam detection now happens in the RefererFilter -- Allen G
   public void testSpamBlocking()
    {
        boolean isSpam = rmgr.processRequest(
   
        new MockRequest(
                "20040101",
                "http://www.spamtest.com",
               "http://test.com",
                null, mWebsite
            )
        );
       //assertTrue("failed to detect referer spam", isSpam);
    }
    */
    
    public
void testApplyRefererFilters() throws Exception
    {
        List refs = rmgr.getReferers(mWebsite);
       assertEquals(count, refs.size());
        String origWords = null;
        
      
 Roller mRoller = getRoller();
        PropertiesManag
 er pmgr = mRoller.getPropertiesManager();
        RollerPropertyData spamprop = pmgr.getProperty("spam.blacklist");
       origWords = spamprop.getValue();
        spamprop.setValue(spamprop.getValue() + ",
test");
        pmgr.store(spamprop);
        getRoller().commit();
        
        getRoller().getRefererManager().applyRefererFilters();
       getRoller().commit();
        
        refs = rmgr.getReferers(mWebsite);
        assertEquals(0,
refs.size());

        spamprop = pmgr.getProperty("spam.blacklist");
        spamprop.setValue(origWords);
       pmgr.store(spamprop);
        getRoller().commit();
    }
    
    public void testApplyRefererFiltersWebsite()
throws Exception
    {
        List refs = rmgr.getReferers(mWebsite);
        assertEquals(count,
refs.size());
        String origWords = null;
        
        mWebsite = getRoller().getUserManager().retrieveWebsite(mWebsite.getId());
       origWords = mWebsite.getBlacklist();
        mWebsite.setBlac
 klist("test");
        mWebsite.save();
        getRoller().commit();
        
        getRoller().getRefererManager().applyRefererFilters();
       getRoller().commit();
        
        refs = rmgr.getReferers(mWebsite);
        assertEquals(0,
refs.size());
    }
}
\ No newline at end of file

Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/business/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/TestAll.java?rev=392622&r1=392621&r2=392622&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/TestAll.java (original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/TestAll.java Sat
Apr  8 15:42:58 2006
@@ -7,35 +7,34 @@
 
 /**
  * Run the essential business layer tests (convenience test for IDEs)
- * 
- * @author llavandowska
  */
-public class TestAll extends TestCase
-{
-    public static Test suite()
-    {
+public class TestAll extends TestCase {
+    
+    
+    public TestAll(String testName) {
+        super(testName);
+    }
+    
+    
+    public static Test suite() {
         TestSuite suite = new TestSuite();
         
-        suite.addTest(WebsiteTest.suite());
-        suite.addTest(PermissionsTest.suite());        
-        suite.addTest(UserManagerTest.suite());       
-        suite.addTest(WeblogManagerTest.suite());        
-        suite.addTest(RefererManagerTest.suite());
-        suite.addTest(IndexManagerTest.suite());             
-        suite.addTest(BookmarkManagerTest.suite());
-        suite.addTest(FileManagerTest.suite());
-        suite.addTest(PlanetManagerTest.suite()); 
-        suite.addTest(PlanetManagerLocalTest.suite()); 
+        suite.addTest(WeblogTest.suite());
+        suite.addTest(PermissionTest.suite());
+        suite.addTest(UserManagerTest.suite());
+        //suite.addTest(WeblogManagerTest.suite());
+        //suite.addTest(RefererManagerTest.suite());
+        //suite.addTest(IndexManagerTest.suite());
+        //suite.addTest(BookmarkManagerTest.suite());
+        //suite.addTest(FileManagerTest.suite());
+        //suite.addTest(PlanetManagerTest.suite());
+        //suite.addTest(PlanetManagerLocalTest.suite());
         
         return suite;
     }
-    public TestAll(String testName)
-    {
-        super(testName);
-    }
-
-    public static void main(String[] args)
-    {
+    
+    
+    public static void main(String[] args) {
         String[] testCaseName = { TestAll.class.getName() };
         junit.textui.TestRunner.main(testCaseName);
     }

Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/business/UserManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/UserManagerTest.java?rev=392622&r1=392621&r2=392622&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/UserManagerTest.java
(original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/UserManagerTest.java
Sat Apr  8 15:42:58 2006
@@ -9,451 +9,131 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-
 import junit.framework.Test;
 import junit.framework.TestSuite;
-
 import org.roller.RollerException;
 import org.roller.RollerTestBase;
 import org.roller.model.UserManager;
 import org.roller.model.WeblogManager;
 import org.roller.pojos.FolderData;
-import org.roller.pojos.WeblogTemplate;
 import org.roller.pojos.UserData;
 import org.roller.pojos.WeblogCategoryData;
 import org.roller.pojos.WebsiteData;
 
-///////////////////////////////////////////////////////////////////////////////
+
 /**
  * Test Roller User Management.
+ *
+ * users, roles, permissions, weblogs, weblog pages.
+ *
+ * 
  */
-public class UserManagerTest  extends RollerTestBase
-{
+public class UserManagerTest  extends RollerTestBase {
+    
     WebsiteData enabledSite = null;
     UserData    enabledUser = null;
     String      enabledUserName = "enabledUser";
-
+    
     WebsiteData disabledSite = null;
     UserData    disabledUser = null;
     String      disabledUserName = "disabledUser";
-
+    
     //------------------------------------------------------------------------
-    public UserManagerTest()
-    {
+    public UserManagerTest() {
         super();
     }
-
+    
     //------------------------------------------------------------------------
-    public UserManagerTest(String name)
-    {
+    public UserManagerTest(String name) {
         super(name);
     }
-
+    
     //------------------------------------------------------------------------
-    public static Test suite()
-    {
+    public static Test suite() {
         return new TestSuite(UserManagerTest.class);
     }
-
+    
     //------------------------------------------------------------------------
-    public static void main(String args[])
-    {
+    public static void main(String args[]) {
         junit.textui.TestRunner.run(UserManagerTest.class);
     }
-
+    
     /**
      * @see junit.framework.TestCase#setUp()
      */
-    public void setUp() throws Exception
-    {
+    public void setUp() throws Exception {
         super.setUp();
-
-        getRoller().begin(UserData.SYSTEM_USER);
+        
         UserManager umgr = getRoller().getUserManager();
-
+        
         enabledUser = createUser(enabledUserName,
-                                 "password",
-                                 "EnabledUser",
-                                 "enabledUser@example.com");
+                "password",
+                "EnabledUser",
+                "enabledUser@example.com");
         enabledUser.setEnabled(Boolean.TRUE);
         enabledSite = ((WebsiteData)umgr.getWebsites(enabledUser, null, null).get(0));
-        enabledSite.setEnabled(Boolean.TRUE);       
-
+        enabledSite.setEnabled(Boolean.TRUE);
+        umgr.storeUser(enabledUser);
+        umgr.storeWebsite(enabledSite);
+        
         disabledUser = createUser(disabledUserName,
-                                 "password",
-                                 "DisabledUser",
-                                 "disabledUser@example.com");
-                
+                "password",
+                "DisabledUser",
+                "disabledUser@example.com");
         disabledUser.setEnabled(Boolean.FALSE);
         disabledSite = ((WebsiteData)umgr.getWebsites(disabledUser, null, null).get(0));
-        disabledSite.setEnabled(Boolean.FALSE);  
-
-        getRoller().commit();
+        disabledSite.setEnabled(Boolean.FALSE);
+        umgr.storeUser(disabledUser);
+        umgr.storeWebsite(disabledSite);
+        
     }
-
+    
     /**
      * @see junit.framework.TestCase#tearDown()
      */
-    public void tearDown() throws Exception
-    {
+    public void tearDown() throws Exception {
         super.tearDown();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        UserManager umgr = getRoller().getUserManager();
-
-        enabledSite = umgr.retrieveWebsite(enabledSite.getId());
-        enabledSite.remove();
         
-        enabledUser = umgr.retrieveUser(enabledUser.getId());
-        enabledUser.remove();
-
-        disabledSite = umgr.retrieveWebsite(disabledSite.getId());
-        disabledSite.remove();
-        
-        disabledUser = umgr.retrieveUser(disabledUser.getId());
-        disabledUser.remove();
-
-        getRoller().commit();
-    }
-
-    //------------------------------------------------------------------------
-    /** Tests storage and removal of user. */
-    public void testUserStorage() throws RollerException
-    {
-        UserManager umgr = getRoller().getUserManager();
-        UserData stored = null;
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        stored = new UserData(
-            null,
-            "testUserStorage2",
-            "password2",
-            "TestUser2",
-            "testuser2@example.com",
-            "en_US_WIN", "America/Los_Angeles",
-            new java.util.Date(), Boolean.TRUE);
-        umgr.storeUser(stored);
-        getRoller().commit();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        UserData retrieved = umgr.retrieveUser(stored.getId());
-        assertEquals(stored, retrieved);
-        getRoller().release();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        retrieved = umgr.retrieveUser(stored.getId());
-        retrieved.remove();
-        getRoller().commit();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        assertNull(umgr.retrieveUser(stored.getId()));
-        getRoller().release();
-    }
-
-    //------------------------------------------------------------------------
-    /** Tests storage and removal of website. */
-    public void testWebsiteStorage() throws RollerException
-    {
-        UserData user = null;
-        WebsiteData stored = null;
         UserManager umgr = getRoller().getUserManager();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-
-        user = new UserData(
-            null,
-            "testWebsiteStorage3",
-            "password3",
-            "TestUser3",
-            "testuser3@example.com",
-            "en_US_WIN", "America/Los_Angeles",
-            new java.util.Date(), Boolean.TRUE);
-        umgr.storeUser(user);
         
-        stored = new WebsiteData();
-        stored.setName("testsite3");
-        stored.setHandle("testsite3");
-        stored.setDescription("Testsite3");
-        stored.setCreator(user);
-        stored.setDefaultPageId("dpid");
-        stored.setWeblogDayPageId("ddid");
-        stored.setEnableBloggerApi(Boolean.FALSE);
-        stored.setEditorPage("edit-weblog.jsp");
-        stored.setAllowComments(Boolean.TRUE);
-        stored.setEmailComments(Boolean.FALSE);
-        stored.setEmailAddress("test@test.com");
-        stored.setEnabled(Boolean.TRUE);
-        stored.setEditorTheme("theme");
-        stored.setDateCreated(new Date());
-        stored.setBlacklist("ignore");
-        stored.setDefaultAllowComments(Boolean.TRUE);
-        stored.setDefaultCommentDays(7);
-        stored.setModerateComments(Boolean.FALSE);
-        umgr.storeWebsite(stored);
+        enabledSite = umgr.retrieveWebsite(enabledSite.getId());
+        umgr.removeWebsite(enabledSite);
         
-        WeblogCategoryData rootCategory = getRoller().getWeblogManager()
-            .createWeblogCategory(stored, null, "root", "root", "");
-        rootCategory.save();
-
-        stored.setBloggerCategory(rootCategory);
-        stored.setDefaultCategory(rootCategory);
+        enabledUser = umgr.retrieveUser(enabledUser.getId());
+        umgr.removeUser(enabledUser);
         
-        FolderData rootFolder = getRoller().getBookmarkManager()
-            .createFolder(null, "root", "root", stored);
-        rootFolder.save();
-
-        getRoller().commit();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        WebsiteData retrieved = umgr.retrieveWebsite(stored.getId());
-        assertEquals(stored, retrieved);
-        retrieved.remove();
-        getRoller().commit();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        user = umgr.retrieveUser(user.getId());
-        user.remove();
-        getRoller().commit();
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        assertNull(umgr.retrieveUser(user.getId()));
-        assertNull(umgr.retrieveWebsite(stored.getId()));
-        getRoller().rollback();
-    }
-
-    public void testAddRemoveUser() throws RollerException
-    {
-        UserManager umgr = getRoller().getUserManager();
-
-        // Add a user
-
-        getRoller().begin(UserData.SYSTEM_USER);
-        UserData user = new UserData(
-            null,
-            "testAddRemoveUser",
-            "password4",
-            "TestUser4",
-            "testuser4@example.com",
-            "en_US_WIN", "America/Los_Angeles",
-            new java.util.Date(), Boolean.TRUE);
-        Map pages = new HashMap();
-        pages.put("Weblog","Weblog page content");
-        pages.put("_day","Day page content");
-        pages.put("css","CSS page content");
-        umgr.addUser(user);
-        umgr.createWebsite(user, pages, 
-                user.getUserName(), user.getUserName(), user.getUserName(), 
-                "dummy@example.com","basic", "en_US_WIN", "America/Los_Angeles");
-        getRoller().commit();
-
-        // Verify that user has all the goodies
-        getRoller().begin(UserData.SYSTEM_USER);
-        UserData user1 = umgr.retrieveUser(user.getId());
-        assertNotNull(user1);
-
-        WebsiteData website = (WebsiteData)umgr.getWebsites(user, null, null).get(0);
-        assertNotNull(website);
-
-        FolderData root = getRoller().getBookmarkManager().getRootFolder(website);
-        assertNotNull(root);
-
-        List pages1 = getRoller().getUserManager().getPages(website);
-        // new registrations require a theme, so no pages are created -- Allen G
-        assertEquals(0, pages1.size());
-        getRoller().rollback();
-
-        // Remove the website and user
-        getRoller().begin(UserData.SYSTEM_USER);
-        website = umgr.retrieveWebsite(website.getId());
-        website.remove();
-        user = umgr.retrieveUser(user.getId());
-        user.remove();
-        getRoller().commit();
-
-        // Verify that user was completely deleted
-        getRoller().begin(UserData.SYSTEM_USER);
-        UserData user2 = umgr.retrieveUser(user.getId());
-        assertNull(user2);
-
-        assertNull(getRoller().getBookmarkManager().retrieveFolder(root.getId()));
-
-        List pages2 = getRoller().getUserManager().getPages(website);
-        assertEquals(0, pages2.size());
-        getRoller().rollback();
-    }
-
-    public void testGetWebsite() throws RollerException
-    {
-        UserManager umgr = getRoller().getUserManager();
+        disabledSite = umgr.retrieveWebsite(disabledSite.getId());
+        umgr.removeWebsite(disabledSite);
         
-        // can get testuser0 who is enabled
-        assertTrue(umgr.getWebsites(
-                umgr.getUser(enabledUserName), Boolean.TRUE, null).size() > 0);
-
-        // can't get testuser1, who is disabled
         disabledUser = umgr.retrieveUser(disabledUser.getId());
-        assertTrue(umgr.getWebsites(
-                disabledUser, Boolean.TRUE, null).size() == 0);
-
-        // can get testuser1 with enabledOnly flag set to false
-        assertTrue(umgr.getWebsites(
-                umgr.getUser(disabledUserName), Boolean.FALSE, null).size() == 1);
-    }
-
-    public void testGetUser() throws RollerException
-    {
-        // can get testuser0 who is enabled
-        getRoller().begin(UserData.SYSTEM_USER);
+        umgr.removeUser(disabledUser);
         
-        UserData user = getRoller().getUserManager().getUser(enabledUserName);
-        assertNotNull(user);
-        
-        // can't get testuser1, who is disabled
-        assertNull(getRoller().getUserManager().getUser(disabledUserName));
-
-        // can get testuser1 with enabledOnly flag set to false
-        assertNotNull(getRoller().getUserManager().getUser(disabledUserName, null));
-        
-        getRoller().release();
-    }
-
-    public void testGetUsers() throws RollerException
-    {
-        // There are users
-        int userCountEnabled = getRoller().getUserManager().getUsers().size();
-        assertTrue(userCountEnabled > 0);
-
-        // At least one user is disabled
-        int userCountAll = getRoller().getUserManager().getUsers(null).size();
-        assertTrue(userCountAll > userCountEnabled);
-    }
-
-    public void testUserRoles() throws Exception {
-        
-        UserData user = null;
-        
-        // check existing roles within a session
-        getRoller().begin(UserData.SYSTEM_USER);        
-        user = getRoller().getUserManager().getUser(enabledUserName);
-        assertNotNull(user);
-        assertNotNull(user.getRoles());
-        assertEquals(1, user.getRoles().size()); 
-        getRoller().release();
-        
-        // test hasRole within a session
-        getRoller().begin(UserData.SYSTEM_USER);        
-        user = getRoller().getUserManager().getUser(enabledUserName);
-        assertTrue(user.hasRole("editor"));
-        getRoller().release();
-        
-        // and without a session
-        assertTrue(user.hasRole("editor"));
-
-        // test revokeRole within session
-        getRoller().begin(UserData.SYSTEM_USER);
-        user = getRoller().getUserManager().getUser(enabledUserName);
-        user.revokeRole("editor");
-        assertFalse(user.hasRole("editor"));
-        getRoller().commit();
-        
-        // role has been removed after commit?
-        assertFalse(user.hasRole("editor"));
-        
-        // restore role
-        getRoller().begin(UserData.SYSTEM_USER);
-        user = getRoller().getUserManager().getUser(enabledUserName);
-        user.grantRole("editor");
-        assertTrue(user.hasRole("editor"));
-        getRoller().commit();
-
-        assertTrue(user.hasRole("editor"));
     }
     
+    
     /** Each website should be able to return a page named Weblog */
-    public void testGetPageByName() throws RollerException
-    {
+    public void testGetPageByName() throws RollerException {
         UserManager umgr = getRoller().getUserManager();
         WebsiteData wd0 = (WebsiteData)umgr.getWebsites(
                 umgr.getUser(enabledUserName), null, null).get(0);
         assertNotNull(wd0.getPageByName("Weblog"));
     }
-
+    
+    
     /** Each website should be able to return a page with link=Weblog */
-    public void testGetPageByLink() throws RollerException
-    {
+    public void testGetPageByLink() throws RollerException {
         UserManager umgr = getRoller().getUserManager();
         WebsiteData wd0 = (WebsiteData)umgr.getWebsites(
                 umgr.getUser(enabledUserName), null, null).get(0);
         assertNotNull(wd0.getPageByLink("Weblog"));
     }
-
-    public void testGetPages() throws RollerException
-    {
+    
+    
+    public void testGetPages() throws RollerException {
         UserManager umgr = getRoller().getUserManager();
         WebsiteData wd0 = (WebsiteData)umgr.getWebsites(
                 umgr.getUser(enabledUserName), null, null).get(0);
         assertEquals(5, wd0.getPages().size());
-    }
-
-    public void hide_testUpdateIfNeeded() throws Exception
-    {
-        UserManager umgr = getRoller().getUserManager();
-        WeblogManager wmgr = getRoller().getWeblogManager();
-        PersistenceStrategy pstrategy = getRoller().getPersistenceStrategy();
-
-        // create cats without a root
-        getRoller().begin(UserData.SYSTEM_USER);
-
-        WebsiteData website = umgr.retrieveWebsite(mWebsite.getId());
-        WeblogCategoryData origRoot = wmgr.getRootWeblogCategory(mWebsite);
-        website.setBloggerCategory(null);
-        website.setDefaultCategory(null);
-
-        if (null != origRoot) origRoot.remove();
-
-        WeblogCategoryData cat1 = wmgr.createWeblogCategory(
-            website, null, "cat1 name", "cat1 desc", null);
-        pstrategy.store(cat1);
-
-        WeblogCategoryData cat2 = wmgr.createWeblogCategory(
-            website, null, "cat2 name", "cat2 desc", null);
-        pstrategy.store(cat2);
-
-        WeblogCategoryData cat3 = wmgr.createWeblogCategory(
-            website, null, "cat3 name", "cat3 desc", null);
-        pstrategy.store(cat3);
-
-        getRoller().commit();
-
-        // upgrade site
-
-        // We need a database connection and the hibernate.properties file
-        // is easier to parse than the Castor database.xml file.
-        Properties hibernateProperties = new Properties();
-        hibernateProperties.load(new FileInputStream("hibernate.properties"));
-        String driverClass = hibernateProperties.getProperty("hibernate.connection.driver_class");
-        String connectionUrl = hibernateProperties.getProperty("hibernate.connection.url");
-        Class.forName(driverClass);
-        Connection con = DriverManager.getConnection(connectionUrl);
-
-        getRoller().upgradeDatabase(con);
-
-        // verify that upgrade created a root and assigned it to cats
-        getRoller().begin(UserData.SYSTEM_USER);
-        WeblogCategoryData root = wmgr.getRootWeblogCategory(mWebsite);
-        assertNotNull(root);
-
-        cat1 = wmgr.retrieveWeblogCategory(cat1.getId());
-        assertEquals(root, cat1.getParent());
-
-        cat2 = wmgr.retrieveWeblogCategory(cat2.getId());
-        assertEquals(root, cat2.getParent());
-
-        cat3 = wmgr.retrieveWeblogCategory(cat3.getId());
-        assertEquals(root, cat3.getParent());
-
-        getRoller().release();
-    }
-
-
+    }    
+    
 }

Added: incubator/roller/branches/roller-newbackend/tests/org/roller/business/UserTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/UserTest.java?rev=392622&view=auto
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/UserTest.java (added)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/UserTest.java Sat
Apr  8 15:42:58 2006
@@ -0,0 +1,209 @@
+
+package org.roller.business;
+
+import java.util.List;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.model.RollerFactory;
+import org.roller.model.UserManager;
+import org.roller.pojos.UserData;
+
+
+/**
+ * Test User related business operations.
+ *
+ * That includes:
+ *   - creating a user
+ *   - updating a user
+ *   - deleting a user
+ *   - getting a user by id
+ *   - getting a user by username (enabled and disabled)
+ *   - getting a user starting with XXX
+ *   - adding a role for a user
+ *   - removing a role for a user
+ *
+ */
+public class UserTest extends TestCase {
+    
+    public static Log log = LogFactory.getLog(UserTest.class);
+    
+    UserData testUser = null;
+    
+    
+    public UserTest(String name) {
+        super(name);
+    }
+    
+    
+    public static Test suite() {
+        return new TestSuite(UserTest.class);
+    }
+    
+    
+    public void setUp() throws Exception {
+        
+        testUser = new UserData();
+        testUser.setUserName("testUser");
+        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);
+    }
+    
+    public void tearDown() throws Exception {
+        testUser = null;
+    }
+    
+    
+    /**
+     * Test basic persistence operations ... Create, Update, Delete
+     */
+    public void testUserCRUD() throws Exception {
+        
+        UserManager mgr = RollerFactory.getRoller().getUserManager();
+        UserData user = null;
+        
+        // make sure test user does not exist
+        user = mgr.getUser(testUser.getUserName());
+        assertNull(user);
+        
+        // add test user
+        mgr.addUser(testUser);
+        
+        // make sure test user exists
+        user = mgr.getUser(testUser.getUserName());
+        assertNotNull(user);
+        assertEquals(testUser.getUserName(), user.getUserName());
+        
+        // modify user and save
+        user.setFullName("testtesttest");
+        mgr.storeUser(user);
+        user = null;
+        
+        // make sure changes were saved
+        user = mgr.getUser(testUser.getUserName());
+        assertNotNull(user);
+        assertEquals("testtesttest", user.getFullName());
+        
+        // remove test user
+        mgr.removeUser(user);
+        user = null;
+        
+        // make sure user no longer exists
+        user = mgr.getUser(testUser.getUserName());
+        assertNull(user);
+    }
+    
+    
+    /**
+     * Test lookup mechanisms ... Id, UserName, UserName (part), Email (part)
+     */
+    public void testUserLookups() throws Exception {
+        
+        UserManager mgr = RollerFactory.getRoller().getUserManager();
+        UserData user = null;
+        
+        // make sure test user does not exist
+        user = mgr.getUser(testUser.getUserName());
+        assertNull(user);
+        
+        // add test user
+        mgr.addUser(testUser);
+        
+        // lookup by username
+        user = mgr.getUser(testUser.getUserName());
+        assertNotNull(user);
+        assertEquals(testUser.getUserName(), user.getUserName());
+        
+        // lookup by id
+        String id = user.getId();
+        user = null;
+        user = mgr.retrieveUser(id);
+        assertNotNull(user);
+        assertEquals(testUser.getUserName(), user.getUserName());
+        
+        // lookup by UserName (part)
+        user = null;
+        List users1 = mgr.getUsersStartingWith(testUser.getUserName().substring(0, 3), 0,
1, Boolean.TRUE);
+        assertEquals(1, users1.size());
+        user = (UserData) users1.get(0);
+        assertNotNull(user);
+        assertEquals(testUser.getUserName(), user.getUserName());
+        
+        // lookup by Email (part)
+        user = null;
+        List users2 = mgr.getUsersStartingWith(testUser.getEmailAddress().substring(0, 3),
0, 1, Boolean.TRUE);
+        assertEquals(1, users2.size());
+        user = (UserData) users2.get(0);
+        assertNotNull(user);
+        assertEquals(testUser.getUserName(), user.getUserName());
+        
+        // make sure disable users are not returned
+        user.setEnabled(Boolean.FALSE);
+        mgr.storeUser(user);
+        user = null;
+        user = mgr.getUser(testUser.getUserName());
+        assertNull(user);
+        
+        // remove test user
+        user = mgr.getUser(testUser.getUserName(), Boolean.FALSE);
+        assertNotNull(user);
+        mgr.removeUser(user);
+        user = null;
+    }
+    
+    
+    /**
+     * Test basic user role persistence ... Add, Remove
+     */
+    public void testRoleCRUD() throws Exception {
+        
+        UserManager mgr = RollerFactory.getRoller().getUserManager();
+        UserData user = null;
+        
+        // make sure test user does not exist
+        user = mgr.getUser(testUser.getUserName());
+        assertNull(user);
+        
+        // add test user
+        mgr.addUser(testUser);
+        
+        // verify user has 2 roles, admin & editor
+        user = mgr.getUser(testUser.getUserName());
+        assertNotNull(user);
+        assertEquals(user.getRoles().size(), 2);
+        assertTrue(user.hasRole("editor"));
+        assertTrue(user.hasRole("admin"));
+        
+        // remove role
+        user.revokeRole("admin");
+        mgr.storeUser(user);
+        user = null;
+        user = mgr.getUser(testUser.getUserName());
+        assertNotNull(user);
+        assertEquals(user.getRoles().size(), 1);
+        assertTrue(user.hasRole("editor"));
+        assertFalse(user.hasRole("admin"));
+        
+        // add role
+        user.grantRole("admin");
+        mgr.storeUser(user);
+        user = null;
+        user = mgr.getUser(testUser.getUserName());
+        assertNotNull(user);
+        assertEquals(user.getRoles().size(), 2);
+        assertTrue(user.hasRole("editor"));
+        assertTrue(user.hasRole("admin"));
+        
+        // remove test user
+        mgr.removeUser(user);
+        user = null;
+    }
+    
+}



Mime
View raw message