roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r500409 - in /incubator/roller/trunk/tests/org/apache/roller/business: PermissionTest.java WeblogTest.java
Date Fri, 26 Jan 2007 23:36:23 GMT
Author: agilliland
Date: Fri Jan 26 15:36:23 2007
New Revision: 500409

URL: http://svn.apache.org/viewvc?view=rev&rev=500409
Log:
some better logging and exception handling on a few tests.


Modified:
    incubator/roller/trunk/tests/org/apache/roller/business/PermissionTest.java
    incubator/roller/trunk/tests/org/apache/roller/business/WeblogTest.java

Modified: incubator/roller/trunk/tests/org/apache/roller/business/PermissionTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/business/PermissionTest.java?view=diff&rev=500409&r1=500408&r2=500409
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/PermissionTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/PermissionTest.java Fri Jan 26
15:36:23 2007
@@ -58,6 +58,9 @@
      * All tests in this suite require a user and a weblog.
      */
     public void setUp() throws Exception {
+        
+        log.info("BEGIN");
+        
         try {
             testUser = TestUtils.setupUser("permsTestUser");
             testWeblog = TestUtils.setupWeblog("permsTestWeblog", testUser);
@@ -66,9 +69,14 @@
             log.error(ex);
             throw new Exception("Test setup failed", ex);
         }
+        
+        log.info("END");
     }
     
     public void tearDown() throws Exception {
+        
+        log.info("BEGIN");
+        
         try {
             TestUtils.teardownWeblog(testWeblog.getId());
             TestUtils.teardownUser(testUser.getId());
@@ -77,6 +85,8 @@
             log.error(ex);
             throw new Exception("Test teardown failed", ex);
         }
+        
+        log.info("END");
     }
     
     
@@ -85,6 +95,8 @@
      */
     public void testPermissionsCRUD() throws Exception {
         
+        log.info("BEGIN");
+        
         UserManager mgr = RollerFactory.getRoller().getUserManager();
         PermissionsData perm = null;
         
@@ -124,6 +136,8 @@
         perm = mgr.getPermissions(testWeblog, testUser);
         assertNotNull(perm);
         assertEquals(PermissionsData.LIMITED, perm.getPermissionMask());
+        
+        log.info("END");
     }
     
     
@@ -131,64 +145,74 @@
      * Test lookup mechanisms.
      */
     public void testPermissionsLookups() throws Exception {
-
-        // we need a second user for this test
-        UserData user = TestUtils.setupUser("foofoo");
-        TestUtils.endSession(true);
-
-        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(TestUtils.getManagedUser(user));
-        perm.setWebsite(TestUtils.getManagedWebsite(testWeblog));
-        perm.setPending(true);
-        perm.setPermissionMask(PermissionsData.AUTHOR);
-        mgr.savePermissions(perm);
-        TestUtils.endSession(true);
-
-        // 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.getPermissions(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.getId());
-        TestUtils.endSession(true);
+        
+        log.info("BEGIN");
+        
+        try {
+            // we need a second user for this test
+            UserData user = TestUtils.setupUser("testPermissionsLookups");
+            TestUtils.endSession(true);
+            
+            UserManager mgr = RollerFactory.getRoller().getUserManager();
+            PermissionsData perm = null;
+            List perms = null;
+            
+            // get all permissions for a user
+            perms = mgr.getAllPermissions(TestUtils.getManagedUser(user));
+            assertEquals(0, perms.size());
+            perms = mgr.getAllPermissions(TestUtils.getManagedUser(testUser));
+            assertEquals(1, perms.size());
+            
+            // get all permissions for a weblog
+            perms = mgr.getAllPermissions(TestUtils.getManagedWebsite(testWeblog));
+            assertEquals(1, perms.size());
+            
+            perm = new PermissionsData();
+            perm.setUser(TestUtils.getManagedUser(user));
+            perm.setWebsite(TestUtils.getManagedWebsite(testWeblog));
+            perm.setPending(true);
+            perm.setPermissionMask(PermissionsData.AUTHOR);
+            mgr.savePermissions(perm);
+            TestUtils.endSession(true);
+            
+            // get pending permissions for a user
+            perms = mgr.getPendingPermissions(TestUtils.getManagedUser(testUser));
+            assertEquals(0, perms.size());
+            perms = mgr.getPendingPermissions(TestUtils.getManagedUser(user));
+            assertEquals(1, perms.size());
+            
+            // get pending permissions for a weblog
+            perms = mgr.getPendingPermissions(TestUtils.getManagedWebsite(testWeblog));
+            assertEquals(1, perms.size());
+            
+            // get permissions by id
+            String id = perm.getId();
+            perm = null;
+            perm = mgr.getPermissions(id);
+            assertNotNull(perm);
+            assertEquals(id, perm.getId());
+            
+            // get permissions for a specific user/weblog
+            perm = null;
+            perm = mgr.getPermissions(TestUtils.getManagedWebsite(testWeblog), TestUtils.getManagedUser(testUser));
+            assertNotNull(perm);
+            assertEquals(PermissionsData.ADMIN, perm.getPermissionMask());
+            perm = null;
+            perm = mgr.getPermissions(TestUtils.getManagedWebsite(testWeblog), TestUtils.getManagedUser(user));
+            assertNotNull(perm);
+            assertEquals(PermissionsData.AUTHOR, perm.getPermissionMask());
+            assertEquals(true, perm.isPending());
+            
+            // cleanup
+            TestUtils.teardownPermissions(perm.getId());
+            TestUtils.teardownUser(user.getId());
+            TestUtils.endSession(true);
+        } catch(Throwable t) {
+            log.error("Error running test", t);
+            throw (Exception) t;
+        }
+        
+        log.info("END");
     }
 
 
@@ -196,9 +220,11 @@
      * Tests weblog invitation process.
      */
     public void testInvitations() throws Exception {
-
+        
+        log.info("BEGIN");
+        
         // we need a second user for this test
-        UserData user = TestUtils.setupUser("foobee");
+        UserData user = TestUtils.setupUser("testInvitations");
         TestUtils.endSession(true);
 
         UserManager mgr = RollerFactory.getRoller().getUserManager();
@@ -226,7 +252,7 @@
 
         // assert that user is member of weblog
         assertFalse(mgr.getPermissions(testWeblog, user).isPending());
-        List weblogs = mgr.getWebsites(user, null, null, null, null, 0, -1);
+        List weblogs = mgr.getWebsites(TestUtils.getManagedUser(user), null, null, null,
null, 0, -1);
         assertEquals(1, weblogs.size());
         assertEquals(testWeblog.getId(), ((WebsiteData)weblogs.get(0)).getId());
 
@@ -245,6 +271,8 @@
         // cleanup the extra test user
         TestUtils.teardownUser(user.getId());
         TestUtils.endSession(true);
+        
+        log.info("END");
     }
+    
 }
-

Modified: incubator/roller/trunk/tests/org/apache/roller/business/WeblogTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/business/WeblogTest.java?view=diff&rev=500409&r1=500408&r2=500409
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/WeblogTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/WeblogTest.java Fri Jan 26 15:36:23
2007
@@ -58,6 +58,8 @@
      */
     public void setUp() throws Exception {
         
+        log.info("BEGIN");
+        
         try {
             testUser = TestUtils.setupUser("weblogTestUser");
             TestUtils.endSession(true);
@@ -65,10 +67,14 @@
             log.error(ex);
             throw new Exception("Test setup failed", ex);
         }
+        
+        log.info("END");
     }
     
     public void tearDown() throws Exception {
         
+        log.info("BEGIN");
+        
         try {
             TestUtils.teardownUser(testUser.getId());
             TestUtils.endSession(true);
@@ -76,6 +82,8 @@
             log.error(ex);
             throw new Exception("Test teardown failed", ex);
         }
+        
+        log.info("END");
     }
     
     
@@ -147,85 +155,85 @@
      */
     public void testWeblogLookups() throws Exception {
         
-        UserManager mgr = RollerFactory.getRoller().getUserManager();
-        WebsiteData weblog = null;
-        
-        // add test weblogs
-        WebsiteData testWeblog1 = TestUtils.setupWeblog("testWeblog1", testUser);
-        WebsiteData testWeblog2 = TestUtils.setupWeblog("testWeblog2", testUser);
-        TestUtils.endSession(true);
-        
-        // lookup by id
-        weblog = mgr.getWebsite(testWeblog1.getId());
-        assertNotNull(weblog);
-        assertEquals(testWeblog1.getHandle(), weblog.getHandle());
-        
-        // lookup by weblog handle
-        weblog = null;
-        weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
-        assertNotNull(weblog);
-        assertEquals(testWeblog1.getHandle(), weblog.getHandle());
-        
-        // make sure disable weblogs are not returned
-        weblog.setEnabled(Boolean.FALSE);
-        mgr.saveWebsite(weblog);
-        TestUtils.endSession(true);
-        weblog = null;
-        weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
-        assertNull(weblog);
-        
-        // restore enabled state
-        weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle(), Boolean.FALSE);
-        weblog.setEnabled(Boolean.TRUE);
-        mgr.saveWebsite(weblog);
-        TestUtils.endSession(true);
-        weblog = null;
-        weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
-        assertNotNull(weblog);
-        
-        // get all weblogs for user
-        weblog = null;
-        List weblogs1 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null,
0, -1);
-        assertEquals(2, weblogs1.size());
-        weblog = (WebsiteData) weblogs1.get(0);
-        assertNotNull(weblog);
-        
-        // testing paging
-        List weblogs11 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null,
0, 1);
-        assertEquals(1, weblogs11.size());     
-        List weblogs12 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null,
1, 1);
-        assertEquals(1, weblogs11.size());     
-        
-        // make sure disabled weblogs are not returned
-        weblog.setEnabled(Boolean.FALSE);
-        mgr.saveWebsite(weblog);
-        TestUtils.endSession(true);
-        List weblogs2 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null,
0, -1);
-        assertEquals(1, weblogs2.size());
-        weblog = (WebsiteData) weblogs2.get(0);
-        assertNotNull(weblog);
+        log.info("BEGIN");
         
-        // make sure inactive weblogs are not returned
-        weblog.setActive(Boolean.FALSE);
-        mgr.saveWebsite(weblog);
-        TestUtils.endSession(true);
-        List weblogs3 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null,
0, -1);
-        assertEquals(0, weblogs3.size());
+        try {
+            UserManager mgr = RollerFactory.getRoller().getUserManager();
+            WebsiteData weblog = null;
+            
+            // add test weblogs
+            WebsiteData testWeblog1 = TestUtils.setupWeblog("testWeblog1", TestUtils.getManagedUser(testUser));
+            WebsiteData testWeblog2 = TestUtils.setupWeblog("testWeblog2", TestUtils.getManagedUser(testUser));
+            TestUtils.endSession(true);
+            
+            // lookup by id
+            weblog = mgr.getWebsite(testWeblog1.getId());
+            assertNotNull(weblog);
+            assertEquals(testWeblog1.getHandle(), weblog.getHandle());
+            
+            // lookup by weblog handle
+            weblog = null;
+            weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
+            assertNotNull(weblog);
+            assertEquals(testWeblog1.getHandle(), weblog.getHandle());
+            
+            // make sure disable weblogs are not returned
+            weblog.setEnabled(Boolean.FALSE);
+            mgr.saveWebsite(weblog);
+            TestUtils.endSession(true);
+            weblog = null;
+            weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
+            assertNull(weblog);
+            
+            // restore enabled state
+            weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle(), Boolean.FALSE);
+            weblog.setEnabled(Boolean.TRUE);
+            mgr.saveWebsite(weblog);
+            TestUtils.endSession(true);
+            weblog = null;
+            weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
+            assertNotNull(weblog);
+            
+            // get all weblogs for user
+            weblog = null;
+            List weblogs1 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE,
Boolean.TRUE, null, null, 0, -1);
+            assertEquals(2, weblogs1.size());
+            weblog = (WebsiteData) weblogs1.get(0);
+            assertNotNull(weblog);
+            
+            // testing paging
+            List weblogs11 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE,
Boolean.TRUE, null, null, 0, 1);
+            assertEquals(1, weblogs11.size());
+            List weblogs12 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE,
Boolean.TRUE, null, null, 1, 1);
+            assertEquals(1, weblogs11.size());
+            
+            // make sure disabled weblogs are not returned
+            weblog.setEnabled(Boolean.FALSE);
+            mgr.saveWebsite(weblog);
+            TestUtils.endSession(true);
+            List weblogs2 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE,
Boolean.TRUE, null, null, 0, -1);
+            assertEquals(1, weblogs2.size());
+            weblog = (WebsiteData) weblogs2.get(0);
+            assertNotNull(weblog);
+            
+            // make sure inactive weblogs are not returned
+            weblog.setActive(Boolean.FALSE);
+            mgr.saveWebsite(weblog);
+            TestUtils.endSession(true);
+            List weblogs3 = mgr.getWebsites(TestUtils.getManagedUser(testUser), Boolean.TRUE,
Boolean.TRUE, null, null, 0, -1);
+            assertEquals(0, weblogs3.size());
+            
+            // remove test weblogs
+            TestUtils.teardownWeblog(testWeblog1.getId());
+            TestUtils.teardownWeblog(testWeblog2.getId());
+            TestUtils.endSession(true);
+        } catch(Throwable t) {
+            log.error("Exception running test", t);
+            throw (Exception) t;
+        }
         
-        // remove test weblogs
-        TestUtils.teardownWeblog(testWeblog1.getId());
-        TestUtils.teardownWeblog(testWeblog2.getId());
-        TestUtils.endSession(true);
+        log.info("END");
     }
     
-    
-    /**
-     * Test that we can safely remove a fully loaded weblog.
-     * That means a weblog with entries, categories, bookmarks, pings, etc.
-     */
-    public void testRemoveLoadedWeblog() throws Exception {
-        // TODO: implement testRemoveLoadedWeblog
-    }
 }
-
 



Mime
View raw message