roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r393073 - in /incubator/roller/branches/roller-newbackend/tests/org/roller: TestUtils.java business/WeblogEntryTest.java
Date Mon, 10 Apr 2006 21:35:48 GMT
Author: agilliland
Date: Mon Apr 10 14:35:47 2006
New Revision: 393073

URL: http://svn.apache.org/viewcvs?rev=393073&view=rev
Log:
Weblog Entry unit tests now completed.


Modified:
    incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java
    incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogEntryTest.java

Modified: 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=393073&r1=393072&r2=393073&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java (original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/TestUtils.java Mon Apr 10
14:35:47 2006
@@ -8,9 +8,12 @@
 
 import org.roller.model.RollerFactory;
 import org.roller.model.UserManager;
+import org.roller.model.WeblogManager;
 import org.roller.pojos.UserData;
+import org.roller.pojos.WeblogEntryData;
 import org.roller.pojos.WebsiteData;
 
+
 /**
  * Utility class for unit test classes.
  */
@@ -98,12 +101,60 @@
      */
     public static void teardownWeblog(String handle) throws Exception {
         
-        // lookup the user
+        // lookup the weblog
         UserManager mgr = RollerFactory.getRoller().getUserManager();
         WebsiteData weblog = mgr.getWebsiteByHandle(handle);
         
         // remove the weblog
         mgr.removeWebsite(weblog);
+    }
+ 
+    
+    /**
+     * Convenience method for creating a weblog entry.
+     */
+    public static WeblogEntryData setupWeblogEntry(String anchor,
+                                                   WebsiteData weblog,
+                                                   UserData user)
+            throws Exception {
+        
+        WeblogEntryData testEntry = new WeblogEntryData();
+        testEntry.setTitle(anchor);
+        testEntry.setLink("testEntryLink");
+        testEntry.setText("blah blah entry");
+        testEntry.setAnchor(anchor);
+        testEntry.setPubTime(new java.sql.Timestamp(new java.util.Date().getTime()));
+        testEntry.setUpdateTime(new java.sql.Timestamp(new java.util.Date().getTime()));
+        testEntry.setStatus(WeblogEntryData.PUBLISHED);
+        testEntry.setWebsite(weblog);
+        testEntry.setCreator(user);
+        testEntry.setCategory(weblog.getDefaultCategory());
+        
+        // store entry
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        mgr.storeWeblogEntry(testEntry);
+        
+        // query for object
+        WeblogEntryData entry = mgr.retrieveWeblogEntry(testEntry.getId());
+        
+        if(entry == null)
+            throw new RollerException("error setting up weblog entry");
+        
+        return entry;
+    }
+    
+    
+    /**
+     * Convenience method for removing a weblog entry.
+     */
+    public static void teardownWeblogEntry(String id) throws Exception {
+        
+        // lookup the entry
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        WeblogEntryData entry = mgr.retrieveWeblogEntry(id);
+        
+        // remove the entry
+        mgr.removeWeblogEntry(entry);
     }
     
 }

Modified: incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogEntryTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogEntryTest.java?rev=393073&r1=393072&r2=393073&view=diff
==============================================================================
--- incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogEntryTest.java
(original)
+++ incubator/roller/branches/roller-newbackend/tests/org/roller/business/WeblogEntryTest.java
Mon Apr 10 14:35:47 2006
@@ -6,6 +6,8 @@
 
 package org.roller.business;
 
+import java.util.List;
+import java.util.Map;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -18,6 +20,7 @@
 import org.roller.pojos.WeblogEntryData;
 import org.roller.pojos.WebsiteData;
 
+
 /**
  * Test WeblogEntry related business operations.
  *
@@ -37,7 +40,7 @@
     
     
     public static Test suite() {
-        return new TestSuite(WeblogPageTest.class);
+        return new TestSuite(WeblogEntryTest.class);
     }
     
     
@@ -60,6 +63,9 @@
         testEntry.setAnchor("testEntryAnchor");
         testEntry.setPubTime(new java.sql.Timestamp(new java.util.Date().getTime()));
         testEntry.setUpdateTime(new java.sql.Timestamp(new java.util.Date().getTime()));
+        testEntry.setWebsite(testWeblog);
+        testEntry.setCreator(testUser);
+        testEntry.setCategory(testWeblog.getDefaultCategory());
     }
     
     public void tearDown() throws Exception {
@@ -106,6 +112,165 @@
         entry = null;
         entry = mgr.retrieveWeblogEntry(entryId);
         assertNull(entry);
+    }
+    
+    
+    public void testWeblogEntryLookups() throws Exception {
+        
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        WeblogEntryData entry = null;
+        List entries = null;
+        Map entryMap = null;
+        
+        // setup some test entries to use
+        WeblogEntryData entry1 = TestUtils.setupWeblogEntry("entry1", testWeblog, testUser);
+        WeblogEntryData entry2 = TestUtils.setupWeblogEntry("entry2", testWeblog, testUser);
+        WeblogEntryData entry3 = TestUtils.setupWeblogEntry("entry3", testWeblog, testUser);
+        
+        // make a couple changes
+        entry2.setPinnedToMain(Boolean.TRUE);
+        entry2.setUpdateTime(new java.sql.Timestamp(entry2.getUpdateTime().getTime()+8822384));
+        entry2.setPubTime(entry2.getUpdateTime());
+        mgr.storeWeblogEntry(entry2);
+        entry3.setStatus(WeblogEntryData.DRAFT);
+        entry3.setUpdateTime(new java.sql.Timestamp(entry3.getUpdateTime().getTime()+348829384));
+        entry3.setPubTime(entry3.getUpdateTime());
+        mgr.storeWeblogEntry(entry3);
+        
+        log.debug("entry1 = "+entry1.getUpdateTime());
+        log.debug("entry2 = "+entry2.getUpdateTime());
+        log.debug("entry3 = "+entry3.getUpdateTime());
+        
+        // get entry by id
+        entry = null;
+        entry = mgr.retrieveWeblogEntry(entry1.getId());
+        assertNotNull(entry);
+        assertEquals(entry1.getAnchor(), entry.getAnchor());
+        
+        // get entry by anchor
+        entry = null;
+        entry = mgr.getWeblogEntryByAnchor(testWeblog, entry1.getAnchor());
+        assertNotNull(entry);
+        assertEquals(entry1.getTitle(), entry.getTitle());
+        
+        // get all entries for weblog
+        entries = null;
+        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null);
+        assertNotNull(entries);
+        assertEquals(3, entries.size());
+        assertEquals(entry3, entries.get(0));
+        
+        // get all entries in category
+        entries = null;
+        entries = mgr.retrieveWeblogEntries(testWeblog.getDefaultCategory(), false);
+        assertNotNull(entries);
+        assertEquals(3, entries.size());
+        
+        // get all published entries only
+        entries = null;
+        entries = mgr.getWeblogEntries(testWeblog, null, null, null, WeblogEntryData.PUBLISHED,
null, null);
+        assertNotNull(entries);
+        assertEquals(2, entries.size());
+        
+        // get all entries in date range
+        entries = null;
+        entries = mgr.getWeblogEntries(testWeblog, entry2.getPubTime(), entry2.getPubTime(),
null, null, null, null);
+        assertNotNull(entries);
+        assertEquals(1, entries.size());
+        assertEquals(entry2, entries.get(0));
+        
+        // get all entries, limited to maxSize
+        entries = null;
+        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, new Integer(2));
+        assertNotNull(entries);
+        assertEquals(2, entries.size());
+        
+        // get all entries in category
+        entries = null;
+        entries = mgr.getWeblogEntries(testWeblog, null, null, testWeblog.getDefaultCategory().getName(),
null, null, null);
+        assertNotNull(entries);
+        assertEquals(3, entries.size());
+        
+        // get all entries, limited by offset/range
+        entries = null;
+        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, 1, 2);
+        assertNotNull(entries);
+        assertEquals(2, entries.size());
+        assertEquals(entry2, entries.get(0));
+        
+        // get pinned entries only
+        entries = null;
+        entries = mgr.getWeblogEntriesPinnedToMain(new Integer(5));
+        assertNotNull(entries);
+        assertEquals(1, entries.size());
+        assertEquals(entry2, entries.get(0));
+        
+        // get next entries
+        entries = null;
+        entries = mgr.getNextEntries(entry1, null, 5);
+        assertNotNull(entries);
+        assertEquals(1, entries.size());
+        assertEquals(entry2, entries.get(0));
+        
+        // get next entry
+        entry = null;
+        entry = mgr.getNextEntry(entry1, null);
+        assertNotNull(entry);
+        assertEquals(entry2, entry);
+        
+        // get previous entries
+        entries = null;
+        entries = mgr.getPreviousEntries(entry2, null, 5);
+        assertNotNull(entries);
+        assertEquals(1, entries.size());
+        assertEquals(entry1, entries.get(0));
+        
+        // get previous entry
+        entry = null;
+        entry = mgr.getPreviousEntry(entry2, null);
+        assertNotNull(entry);
+        assertEquals(entry1, entry);
+        
+        // get object map
+        entryMap = null;
+        entryMap = mgr.getWeblogEntryObjectMap(testWeblog, null, null, null, null, null);
+        assertNotNull(entryMap);
+        assertTrue(entryMap.keySet().size() > 1);
+        
+        // get string map
+        entryMap = null;
+        entryMap = mgr.getWeblogEntryStringMap(testWeblog, null, null, null, null, null);
+        assertNotNull(entryMap);
+        assertTrue(entryMap.keySet().size() > 1);
+                
+        // teardown our test entries
+        TestUtils.teardownWeblogEntry(entry1.getId());
+        TestUtils.teardownWeblogEntry(entry2.getId());
+        TestUtils.teardownWeblogEntry(entry3.getId());
+    }
+    
+    
+    public void testCreateAnchor() throws Exception {
+        
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        WeblogEntryData entry = null;
+        List entries = null;
+        
+        // setup some test entries to use
+        WeblogEntryData entry1 = TestUtils.setupWeblogEntry("entry1", testWeblog, testUser);
+        
+        // make sure createAnchor gives us a new anchor value
+        String anchor = mgr.createAnchor(entry1);
+        assertNotNull(anchor);
+        assertNotSame("entry1", anchor);
+        
+        // make sure we can create a new entry with specified anchor
+        WeblogEntryData entry2 = TestUtils.setupWeblogEntry(anchor, testWeblog, testUser);
+        assertNotNull(entry2);
+        
+        // teardown our test entries
+        TestUtils.teardownWeblogEntry(entry1.getId());
+        TestUtils.teardownWeblogEntry(entry2.getId());
     }
     
 }



Mime
View raw message