roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r500031 - in /incubator/roller/trunk: src/org/apache/roller/pojos/WeblogCategoryData.java tests/org/apache/roller/business/WeblogCategoryTest.java
Date Thu, 25 Jan 2007 22:45:28 GMT
Author: agilliland
Date: Thu Jan 25 14:45:27 2007
New Revision: 500031

URL: http://svn.apache.org/viewvc?view=rev&rev=500031
Log:
add method hasCategory(name) to weblog category pojo to check if a given category has the
named child category.  unit test included.


Modified:
    incubator/roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java
    incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java

Modified: incubator/roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java?view=diff&rev=500031&r1=500030&r2=500031
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java Thu Jan 25
14:45:27 2007
@@ -20,6 +20,7 @@
 
 import java.io.Serializable;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import org.apache.commons.lang.builder.EqualsBuilder;
@@ -279,6 +280,25 @@
     public List retrieveWeblogEntries(boolean subcats) throws RollerException {
         WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
         return wmgr.getWeblogEntries(this, subcats);
+    }
+    
+    
+    /**
+     * Does this category have a child category with the specified name?
+     *
+     * @param name The name of the category to check for.
+     * @return boolean true if child category exists, false otherwise.
+     */
+    public boolean hasCategory(String name) {
+        Iterator cats = this.getWeblogCategories().iterator();
+        WeblogCategoryData cat = null;
+        while(cats.hasNext()) {
+            cat = (WeblogCategoryData) cats.next();
+            if(name.equals(cat.getName())) {
+                return true;
+            }
+        }
+        return false;
     }
     
     

Modified: incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java?view=diff&rev=500031&r1=500030&r2=500031
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/WeblogCategoryTest.java Thu Jan
25 14:45:27 2007
@@ -363,4 +363,26 @@
         assertEquals(0, c1.retrieveWeblogEntries(false).size());
 
     }
+    
+    
+    /**
+     * Test the hasCategory() method on WeblogCategoryData.
+     */
+    public void testHasCategory() throws Exception {
+        
+        WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+        
+        WeblogCategoryData root = mgr.getRootWeblogCategory(testWeblog);
+        
+        // add some categories to test with
+        WeblogCategoryData c1 = new WeblogCategoryData(TestUtils.getManagedWebsite(testWeblog),
root, "c1", null, null);
+        mgr.saveWeblogCategory(c1);
+        
+        TestUtils.endSession(true);
+        
+        // check that root has category c1
+        root = mgr.getWeblogCategory(root.getId());
+        assertTrue(root.hasCategory("c1"));
+    }
+    
 }



Mime
View raw message