roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r216224 - in /incubator/roller/branches/roller_2.0: src/org/roller/business/ src/org/roller/business/hibernate/ src/org/roller/model/ src/org/roller/presentation/website/actions/ tests/org/roller/ tests/org/roller/business/
Date Wed, 13 Jul 2005 19:24:10 GMT
Author: snoopdave
Date: Wed Jul 13 12:24:09 2005
New Revision: 216224

URL: http://svn.apache.org/viewcvs?rev=216224&view=rev
Log:
Roller 2.0 backend unit tests are looking good. Time to turn attention to the frontend tests
and the UI.

Modified:
    incubator/roller/branches/roller_2.0/src/org/roller/business/UserManagerImpl.java
    incubator/roller/branches/roller_2.0/src/org/roller/business/hibernate/HibernateUserManagerImpl.java
    incubator/roller/branches/roller_2.0/src/org/roller/model/UserManager.java
    incubator/roller/branches/roller_2.0/src/org/roller/presentation/website/actions/UserAdminAction.java
    incubator/roller/branches/roller_2.0/tests/org/roller/RollerTestBase.java
    incubator/roller/branches/roller_2.0/tests/org/roller/business/PermissionsTest.java
    incubator/roller/branches/roller_2.0/tests/org/roller/business/UserManagerTest.java
    incubator/roller/branches/roller_2.0/tests/org/roller/business/WeblogManagerTest.java

Modified: incubator/roller/branches/roller_2.0/src/org/roller/business/UserManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/business/UserManagerImpl.java?rev=216224&r1=216223&r2=216224&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/business/UserManagerImpl.java (original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/business/UserManagerImpl.java Wed
Jul 13 12:24:09 2005
@@ -91,12 +91,12 @@
 
     public UserData getUser(String userName) throws RollerException
     {
-        return getUser(userName, true);
+        return getUser(userName, Boolean.TRUE);
     }
 
     public WebsiteData getWebsiteByHandle(String handle) throws RollerException
     {
-        return getWebsiteByHandle(handle, true);
+        return getWebsiteByHandle(handle, Boolean.TRUE);
     }
 
     //-----------------------------------------------------------------------
@@ -370,10 +370,11 @@
         }
         mStrategy.store(website); 
         
-        
+        // Add user as member of website
         PermissionsData perms = new PermissionsData();
         perms.setUser(ud);
         perms.setWebsite(website);
+        perms.setPending(false);
         perms.setPermissionMask(PermissionsData.ADMIN);
         perms.save();
 

Modified: incubator/roller/branches/roller_2.0/src/org/roller/business/hibernate/HibernateUserManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/business/hibernate/HibernateUserManagerImpl.java?rev=216224&r1=216223&r2=216224&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/business/hibernate/HibernateUserManagerImpl.java
(original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/business/hibernate/HibernateUserManagerImpl.java
Wed Jul 13 12:24:09 2005
@@ -144,7 +144,7 @@
     /** 
      * Return website specified by handle.
      */
-    public WebsiteData getWebsiteByHandle(String handle, boolean enabledOnly)
+    public WebsiteData getWebsiteByHandle(String handle, Boolean enabled)
                     throws RollerException
     {
         if (handle==null )
@@ -154,12 +154,12 @@
         {
             Session session = ((HibernateStrategy)mStrategy).getSession();
             Criteria criteria = session.createCriteria(WebsiteData.class);
-            if (enabledOnly) 
+            if (enabled != null) 
             {
                 criteria.add(
                    Expression.conjunction()
                        .add(new EqExpression("handle", handle, true))
-                       .add(Expression.eq("isEnabled", Boolean.TRUE)));
+                       .add(Expression.eq("isEnabled", enabled)));
             }
             else
             {
@@ -176,7 +176,7 @@
     }
     
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -     
-    public UserData getUser(String userName, boolean enabledOnly) 
+    public UserData getUser(String userName, Boolean enabled) 
         throws RollerException
     {
         if (userName==null )
@@ -186,12 +186,12 @@
         {
             Session session = ((HibernateStrategy)mStrategy).getSession();
             Criteria criteria = session.createCriteria(UserData.class);
-            if (enabledOnly) 
+            if (enabled != null) 
             {
                 criteria.add(
                    Expression.conjunction()
                        .add(new EqExpression("userName", userName, true))
-                       .add(Expression.eq("isEnabled", Boolean.TRUE)));
+                       .add(Expression.eq("isEnabled", enabled)));
             }
             else
             {

Modified: incubator/roller/branches/roller_2.0/src/org/roller/model/UserManager.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/model/UserManager.java?rev=216224&r1=216223&r2=216224&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/model/UserManager.java (original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/model/UserManager.java Wed Jul 13
12:24:09 2005
@@ -105,7 +105,7 @@
     public UserData getUser( String userName ) throws RollerException;
 
 	/** Get user object by user name, optionally include dis-enabled users */
-	public UserData getUser( String userName, boolean enabledOnly ) throws RollerException;
+	public UserData getUser( String userName, Boolean enabled ) throws RollerException;
 
 
     /**
@@ -155,7 +155,7 @@
      * Get website specified by handle with option to return only enabled websites.
      * @param handle  Handle of website
      */
-    public WebsiteData getWebsiteByHandle(String handle, boolean enabled) 
+    public WebsiteData getWebsiteByHandle(String handle, Boolean enabled) 
         throws RollerException;
 
     public WebsiteData retrieveWebsite(String id) throws RollerException;
@@ -181,10 +181,12 @@
 
 
     /**
-     * Remove page safely.  This will throw an exception on attempts to remove mandatory
website pages such as the
+     * Remove page safely.  This will throw an exception on attempts to remove 
+     * mandatory website pages such as the
      * website's default page.
      * @param id  id of the page to be removed
-     * @throws RollerException with root cause <code>IllegalArgumentException</code>
if the page id is that of
+     * @throws RollerException with root cause <code>IllegalArgumentException</code>

+     * if the page id is that of
      * a page that will not be removed by this method.
      */
     public void removePageSafely(String id) throws RollerException;

Modified: incubator/roller/branches/roller_2.0/src/org/roller/presentation/website/actions/UserAdminAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/src/org/roller/presentation/website/actions/UserAdminAction.java?rev=216224&r1=216223&r2=216224&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/src/org/roller/presentation/website/actions/UserAdminAction.java
(original)
+++ incubator/roller/branches/roller_2.0/src/org/roller/presentation/website/actions/UserAdminAction.java
Wed Jul 13 12:24:09 2005
@@ -67,7 +67,7 @@
                 
                 if (userForm != null && userForm.getUserName() != null)
                 {
-                    UserData user = mgr.getUser( userForm.getUserName(), false );       
            
+                    UserData user = mgr.getUser(userForm.getUserName(), null);          
         
                     if (user != null)
                     {
                         userForm.copyFrom(user, request.getLocale());

Modified: incubator/roller/branches/roller_2.0/tests/org/roller/RollerTestBase.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/tests/org/roller/RollerTestBase.java?rev=216224&r1=216223&r2=216224&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/tests/org/roller/RollerTestBase.java (original)
+++ incubator/roller/branches/roller_2.0/tests/org/roller/RollerTestBase.java Wed Jul 13 12:24:09
2005
@@ -39,17 +39,21 @@
 
     private Roller mRoller = null;
 
-    /** Simple user and website */
+    /** Simple user created */
     protected UserData mUser = null;
-    protected WebsiteData mWebsite = null;
+    /** User name of simple user */
     protected String testUsername = "testuser";
+    /** Simple website created (no entryes, categories, bookmarks, etc.) */
+    protected WebsiteData mWebsite = null;
 
-    /** Collection of websites created, each with category tree. */
-    protected List mWebsites = new LinkedList();
-
-    /** Number of website/users to create */
-    protected int mBlogCount = 1;
+    /** Full websites created, each with entries, cats, bookmarks, etc. */
+    protected List mWebsitesCreated = new LinkedList();
+    
+    /** Users created, user X has permissions in full website X */
+    protected List mUsersCreated = new ArrayList();
 
+    /** Number of full website/users to create */
+    protected int mBlogCount = 2;
     /** Number of categories to create in each category of tree. */
     protected int mCatCount = 2;
     /** Depth of created category tree. */
@@ -59,15 +63,18 @@
     /** Number of comments to creaate per weblog entry */
     protected int mCommentCount = 2;
     
-    protected int mExpectedEntryCount = mEntriesPerCatCount + 
-                                        mEntriesPerCatCount*mCatCount + 
-                                        mEntriesPerCatCount*(mCatCount*mCatDepth);
-    protected int mExpectedPublishedEntryCount = (int)(mEntriesPerCatCount*0.5) + 
-                                        (int)(mEntriesPerCatCount*0.5)*mCatCount + 
-                                        (int)(mEntriesPerCatCount*0.5)*(mCatCount*mCatDepth);
+    /** Total number of entries created */
+    protected int mExpectedEntryCount = 
+        mEntriesPerCatCount + 
+        mEntriesPerCatCount*mCatCount + 
+        mEntriesPerCatCount*(mCatCount*mCatDepth);
+    
+    /** Total number of entries created in published status */
+    protected int mExpectedPublishedEntryCount = 
+        (int)(mEntriesPerCatCount*0.5) + 
+        (int)(mEntriesPerCatCount*0.5)*mCatCount + 
+        (int)(mEntriesPerCatCount*0.5)*(mCatCount*mCatDepth);
 
-    /** Store users to make teardown easy. */
-    protected List mUsersCreated = new ArrayList();
     /** Store categories for use in asserts. */
     protected List mCategoriesCreated = new ArrayList();
     /** Store entries for use in asserts. */
@@ -159,8 +166,9 @@
                 "Test User #"+i,      // fullName
                 "test"+i+"@test.com"  // emailAddress
                 );
+            ud.setIsEnabled(new Boolean(i%2 == 0)); // half of users are disabled
             WebsiteData website = (WebsiteData)umgr.getWebsites(ud, null).get(0);
-            mWebsites.add(website);
+            mWebsitesCreated.add(website);
             mUsersCreated.add(ud);
 
             getRoller().commit();
@@ -294,7 +302,7 @@
     {
         getRoller().begin(UserData.SYSTEM_USER);
         UserManager umgr = getRoller().getUserManager();
-        for (Iterator siteIter = mWebsites.iterator(); siteIter.hasNext();)
+        for (Iterator siteIter = mWebsitesCreated.iterator(); siteIter.hasNext();)
         {
             WebsiteData site = (WebsiteData) siteIter.next();
             site = umgr.retrieveWebsite(site.getId());
@@ -305,7 +313,7 @@
         {
             UserData user = (UserData) userIter.next();
             user = umgr.retrieveUser(user.getId());
-            user.remove();
+            if (user != null) user.remove();
         }
         getRoller().commit();
     }

Modified: incubator/roller/branches/roller_2.0/tests/org/roller/business/PermissionsTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/tests/org/roller/business/PermissionsTest.java?rev=216224&r1=216223&r2=216224&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/tests/org/roller/business/PermissionsTest.java (original)
+++ incubator/roller/branches/roller_2.0/tests/org/roller/business/PermissionsTest.java Wed
Jul 13 12:24:09 2005
@@ -240,12 +240,23 @@
             UserManager umgr = getRoller().getUserManager();
             String userName = "testuser0";
             String permsId;
+            UserData tuser = (UserData)mUsersCreated.get(0);       
+            WebsiteData tsite = (WebsiteData)mWebsitesCreated.get(0);
             
+            // first, remove existing permissions for tuser in tsite
+            getRoller().begin();
+            {
+                tuser = umgr.retrieveUser(tuser.getId());
+                tsite = umgr.retrieveWebsite(tsite.getId());
+                umgr.retireUser(tsite, tuser);
+            }
+            getRoller().commit();  
+
             // test invite user to website
             getRoller().begin();
             {
-                UserData tuser = umgr.getUser(userName);       
-                WebsiteData tsite = (WebsiteData)umgr.getWebsites(tuser, null).get(0);
+                tuser = umgr.retrieveUser(tuser.getId());
+                tsite = umgr.retrieveWebsite(tsite.getId());
                 PermissionsData perms = umgr.inviteUser(
                         tsite, tuser, PermissionsData.LIMITED);
                 permsId = perms.getId();
@@ -255,8 +266,8 @@
             // test user accepts invitation
             getRoller().begin();
             {
-                UserData tuser = umgr.getUser(userName);       
-                WebsiteData tsite = (WebsiteData)umgr.getWebsites(tuser, null).get(0);
+                tuser = umgr.retrieveUser(tuser.getId());
+                tsite = umgr.retrieveWebsite(tsite.getId());
                 
                 // can get pending permission object
                 PermissionsData perms = umgr.getPermissions(tsite, tuser);
@@ -282,8 +293,8 @@
             // test user is member of website, website has member user
             getRoller().begin();
             {
-                UserData tuser = umgr.getUser(userName);       
-                WebsiteData tsite = (WebsiteData)umgr.getWebsites(tuser, null).get(0);
+                tuser = umgr.retrieveUser(tuser.getId());
+                tsite = umgr.retrieveWebsite(tsite.getId());
 
                 // assert that invitation list is empty
                 assertTrue(umgr.getPendingPermissions(tuser).isEmpty());
@@ -307,15 +318,15 @@
             // test user can be retired from website
             getRoller().begin();
             {
-                UserData tuser = umgr.getUser(userName);       
-                WebsiteData tsite = (WebsiteData)umgr.getWebsites(tuser, null).get(0);
+                tuser = umgr.retrieveUser(tuser.getId());
+                tsite = umgr.retrieveWebsite(tsite.getId());
                 umgr.retireUser(tsite, tuser);
             }
             getRoller().commit();
             getRoller().begin();
             {
-                UserData tuser = umgr.getUser(userName);       
-                WebsiteData tsite = (WebsiteData)umgr.getWebsites(tuser, null).get(0);  
             
+                tuser = umgr.retrieveUser(tuser.getId());
+                tsite = umgr.retrieveWebsite(tsite.getId());
                 List websites = umgr.getWebsites(tuser, null);
                 assertEquals(0, websites.size());
                 List users = umgr.getUsers(tsite, null);
@@ -344,12 +355,23 @@
              UserManager umgr = getRoller().getUserManager();
              String userName = "testuser0";
              String permsId = null;
+             UserData tuser = (UserData)mUsersCreated.get(0);       
+             WebsiteData tsite = (WebsiteData)mWebsitesCreated.get(0);
              
-             // Create add user to website
+             // first, remove existing permissions for tuser in tsite
+             getRoller().begin();
+             {
+                 tuser = umgr.retrieveUser(tuser.getId());
+                 tsite = umgr.retrieveWebsite(tsite.getId());
+                 umgr.retireUser(tsite, tuser);
+             }
+             getRoller().commit();  
+
+             // add user to website
              getRoller().begin();
              {
-                 UserData tuser = umgr.getUser(userName);       
-                 WebsiteData tsite = (WebsiteData)umgr.getWebsites(tuser, null).get(0); 
              
+                 tuser = umgr.retrieveUser(tuser.getId());
+                 tsite = umgr.retrieveWebsite(tsite.getId());
                  PermissionsData perms = new PermissionsData();
                  perms.setUser(tuser);
                  perms.setWebsite(tsite);
@@ -361,8 +383,7 @@
              // delete website
              getRoller().begin(UserData.SYSTEM_USER);
              {
-                 UserData tuser = umgr.getUser(userName);       
-                 WebsiteData tsite = (WebsiteData)umgr.getWebsites(tuser, null).get(0);
+                 tsite = umgr.retrieveWebsite(tsite.getId());
                  tsite.remove();                 
              }
              getRoller().commit(); 
@@ -382,56 +403,5 @@
              fail();
          }               
      }
-     
-     /**
-      * Test permissions removal and related cascades, specifically:
-      * <ul>
-      * <li> when user is deleted, permissions are deleted too </li>
-      * <li> when website is deleted, permissions are deleted too </li>
-      * </ul>
-      */
-      public void testRemoveUserCascade() throws Exception
-      {
-          try 
-          {
-              UserManager umgr = getRoller().getUserManager();
-              String userName = "testuser0";
-              String permsId = null;
-              
-              // Create add user to website
-              getRoller().begin();
-              {
-                  UserData tuser = umgr.getUser(userName);       
-                  WebsiteData tsite = (WebsiteData)umgr.getWebsites(tuser, null).get(0);
               
-                  PermissionsData perms = new PermissionsData();
-                  perms.setUser(tuser);
-                  perms.setWebsite(tsite);
-                  perms.save();
-                  permsId = perms.getId();
-              }
-              getRoller().commit();    
-              
-              // delete user
-              getRoller().begin(UserData.SYSTEM_USER);
-              {
-                  UserData tuser = umgr.getUser(userName);       
-                  tuser.remove();              
-              }
-              getRoller().commit(); 
-              
-              // ensure that permission was deleted too
-              getRoller().begin();
-              {
-                  assertNull(getRoller().getPersistenceStrategy().load(
-                          permsId, PermissionsData.class));                 
-              }
-              getRoller().commit();   
-          }
-          catch (Exception e)
-          {
-              e.printStackTrace();
-              fail();
-          }               
-      }
 }
 

Modified: incubator/roller/branches/roller_2.0/tests/org/roller/business/UserManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/tests/org/roller/business/UserManagerTest.java?rev=216224&r1=216223&r2=216224&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/tests/org/roller/business/UserManagerTest.java (original)
+++ incubator/roller/branches/roller_2.0/tests/org/roller/business/UserManagerTest.java Wed
Jul 13 12:24:09 2005
@@ -74,19 +74,19 @@
         enabledUser = createUser(enabledUserName,
                                  "password",
                                  "EnabledUser",
-                                 "enabledUser@example.com"
-        );
+                                 "enabledUser@example.com");
+        enabledUser.setIsEnabled(Boolean.TRUE);
+        enabledSite = ((WebsiteData)umgr.getWebsites(enabledUser, null).get(0));
+        enabledSite.setIsEnabled(Boolean.TRUE);       
 
         disabledUser = createUser(disabledUserName,
                                  "password",
                                  "DisabledUser",
-                                 "disabledUser@example.com"
-        );
-        enabledSite = ((WebsiteData)umgr.getWebsites(enabledUser, null).get(0));
-        enabledSite.setIsEnabled(Boolean.TRUE);
-        
+                                 "disabledUser@example.com");
+                
+        disabledUser.setIsEnabled(Boolean.FALSE);
         disabledSite = ((WebsiteData)umgr.getWebsites(disabledUser, null).get(0));
-        disabledSite.setIsEnabled(Boolean.FALSE);
+        disabledSite.setIsEnabled(Boolean.FALSE);  
 
         getRoller().commit();
     }
@@ -205,7 +205,8 @@
         getRoller().begin(UserData.SYSTEM_USER);
         WebsiteData retrieved = umgr.retrieveWebsite(stored.getId());
         assertEquals(stored, retrieved);
-        getRoller().release();
+        retrieved.remove();
+        getRoller().commit();
 
         getRoller().begin(UserData.SYSTEM_USER);
         user = umgr.retrieveUser(user.getId());
@@ -255,9 +256,10 @@
         assertEquals(3, pages1.size());
         getRoller().rollback();
 
-        // Remove the user
-
+        // 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();
@@ -267,9 +269,6 @@
         UserData user2 = umgr.retrieveUser(user.getId());
         assertNull(user2);
 
-        WebsiteData website2 = (WebsiteData)umgr.getWebsites(user, null).get(0);
-        assertNull(website2);
-
         assertNull(getRoller().getBookmarkManager().retrieveFolder(root.getId()));
 
         List pages2 = getRoller().getUserManager().getPages(website);
@@ -286,8 +285,9 @@
                 umgr.getUser(enabledUserName), Boolean.TRUE).size() > 0);
 
         // can't get testuser1, who is disabled
+        disabledUser = umgr.retrieveUser(disabledUser.getId());
         assertTrue(umgr.getWebsites(
-                umgr.getUser(disabledUserName), Boolean.TRUE).size() == 0);
+                disabledUser, Boolean.TRUE).size() == 0);
 
         // can get testuser1 with enabledOnly flag set to false
         assertTrue(umgr.getWebsites(
@@ -306,7 +306,7 @@
         assertNull(getRoller().getUserManager().getUser(disabledUserName));
 
         // can get testuser1 with enabledOnly flag set to false
-        assertNotNull(getRoller().getUserManager().getUser(disabledUserName,false));
+        assertNotNull(getRoller().getUserManager().getUser(disabledUserName, null));
         
         getRoller().release();
     }

Modified: incubator/roller/branches/roller_2.0/tests/org/roller/business/WeblogManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller_2.0/tests/org/roller/business/WeblogManagerTest.java?rev=216224&r1=216223&r2=216224&view=diff
==============================================================================
--- incubator/roller/branches/roller_2.0/tests/org/roller/business/WeblogManagerTest.java
(original)
+++ incubator/roller/branches/roller_2.0/tests/org/roller/business/WeblogManagerTest.java
Wed Jul 13 12:24:09 2005
@@ -646,7 +646,7 @@
         WeblogManager wmgr = getRoller().getWeblogManager();
         UserManager umgr = getRoller().getUserManager();
         
-        WebsiteData website = (WebsiteData)mWebsites.get(0);
+        WebsiteData website = (WebsiteData)mWebsitesCreated.get(0);
         website = umgr.retrieveWebsite(website.getId());
 
         // PUBLISHISHED ONLY
@@ -698,7 +698,7 @@
         WeblogManager wmgr = getRoller().getWeblogManager();
         UserManager umgr = getRoller().getUserManager();
         
-        WebsiteData website = (WebsiteData)mWebsites.get(0);
+        WebsiteData website = (WebsiteData)mWebsitesCreated.get(0);
         website = umgr.retrieveWebsite(website.getId());
         List comments = wmgr.getRecentComments(website, 2);
         assertTrue(comments.size() > 1);
@@ -724,7 +724,7 @@
     {
         getRoller().begin(UserData.SYSTEM_USER);
         WeblogManager wmgr = getRoller().getWeblogManager();
-        WebsiteData website = (WebsiteData)mWebsites.get(0);
+        WebsiteData website = (WebsiteData)mWebsitesCreated.get(0);
         
         Date lastPub = wmgr.getWeblogLastPublishTime(website);
         //System.out.println(lastPub);
@@ -734,7 +734,7 @@
     public void testEntryAttributes() throws Exception {
         getRoller().begin(UserData.SYSTEM_USER);
         WeblogManager wmgr = getRoller().getWeblogManager();
-        WebsiteData website = (WebsiteData)mWebsites.get(0); 
+        WebsiteData website = (WebsiteData)mWebsitesCreated.get(0); 
         UserData user = (UserData)mUsersCreated.get(0);
         
         WeblogCategoryData cat = wmgr.getRootWeblogCategory(website);       



Mime
View raw message