[jboss-svn-commits] JBL Code SVN: r5903 - in labs/jbossrules/trunk/drools-repository: . src/java/org/drools/repository src/java/org/drools/repository/test

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Aug 15 17:10:35 EDT 2006


Author: michael.neale at jboss.com
Date: 2006-08-15 17:10:20 -0400 (Tue, 15 Aug 2006)
New Revision: 5903

Added:
   labs/jbossrules/trunk/drools-repository/.classpath
   labs/jbossrules/trunk/drools-repository/.project
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/CategoryItem.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulePackageIterator.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/CategoryItemTestCase.java
Removed:
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/TagItem.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/TagItemTestCase.java
Modified:
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulePackageItem.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepository.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepositoryException.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/AllTests.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RulePackageItemTestCase.java
   labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RulesRepositoryTestCase.java
Log:
JBRULES-395 - whole lot of repo features

Added: labs/jbossrules/trunk/drools-repository/.classpath
===================================================================
--- labs/jbossrules/trunk/drools-repository/.classpath	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/.classpath	2006-08-15 21:10:20 UTC (rev 5903)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/java"/>
+	<classpathentry kind="lib" path="lib/commons-collections-3.1.jar"/>
+	<classpathentry kind="lib" path="lib/concurrent-1.3.4.jar"/>
+	<classpathentry kind="lib" path="lib/derby-10.1.1.0.jar"/>
+	<classpathentry kind="lib" path="lib/geronimo-spec-jta-1.0-M1.jar"/>
+	<classpathentry kind="lib" path="lib/jackrabbit-core-1.0-SNAPSHOT.jar"/>
+	<classpathentry kind="lib" path="lib/jcr-1.0.jar"/>
+	<classpathentry kind="lib" path="lib/junit-3.8.1.jar"/>
+	<classpathentry kind="lib" path="lib/log4j-1.2.8.jar"/>
+	<classpathentry kind="lib" path="lib/lucene-1.4.3.jar"/>
+	<classpathentry kind="lib" path="lib/slf4j-log4j12-1.0.jar"/>
+	<classpathentry kind="lib" path="lib/svnant.jar"/>
+	<classpathentry kind="lib" path="lib/svnClientAdapter.jar"/>
+	<classpathentry kind="lib" path="lib/svnjavahl.jar"/>
+	<classpathentry kind="lib" path="lib/xercesImpl-2.6.2.jar"/>
+	<classpathentry kind="lib" path="lib/xmlParserAPIs-2.0.2.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: labs/jbossrules/trunk/drools-repository/.project
===================================================================
--- labs/jbossrules/trunk/drools-repository/.project	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/.project	2006-08-15 21:10:20 UTC (rev 5903)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>drools-repository</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Copied: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/CategoryItem.java (from rev 5888, labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/TagItem.java)
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/TagItem.java	2006-08-15 09:38:05 UTC (rev 5888)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/CategoryItem.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -0,0 +1,110 @@
+package org.drools.repository;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+
+import org.apache.log4j.Logger;
+
+/**
+ * The TagItem class abstracts away details of the underlying JCR repository.
+ * 
+ * @author btruitt
+ */
+public class CategoryItem extends Item {
+    private Logger log = Logger.getLogger(CategoryItem.class);
+    
+    /**
+     * The name of the tag node type
+     */
+    public static final String TAG_NODE_TYPE_NAME = "drools:tag_node_type";
+    
+    /**
+     * Constructs an object of type TagItem corresponding the specified node
+     * @param rulesRepository the rulesRepository that instantiated this object
+     * @param node the node to which this object corresponds
+     * @throws RulesRepositoryException 
+     */
+    public CategoryItem(RulesRepository rulesRepository, Node node) throws RulesRepositoryException {
+        super(rulesRepository, node);
+        
+        try {
+            //make sure this node is a tag node       
+            if(!(this.node.getPrimaryNodeType().getName().equals(TAG_NODE_TYPE_NAME))) {
+                String message = this.node.getName() + " is not a node of type " + TAG_NODE_TYPE_NAME + ". It is a node of type: " + this.node.getPrimaryNodeType().getName();
+                log.error(message);
+                throw new RulesRepositoryException(message);
+            }    
+        }
+        catch(Exception e) {
+            log.error("Caught exception: " + e);
+            throw new RulesRepositoryException(e);
+        }
+    }
+
+    /**
+     * @return the full path of this tag, rooted at the tag area of the repository. 
+     * @throws RulesRepositoryException 
+     */
+    public String getFullPath() throws RulesRepositoryException {        
+        try {
+            log.debug("getting full path for node named: " + this.node.getName());
+            
+            StringBuffer returnString = new StringBuffer();
+            returnString.append(this.node.getName());
+            Node parentNode = this.node.getParent();
+            while(!parentNode.getName().equals(RulesRepository.TAG_AREA)) {
+                returnString.insert(0, parentNode.getName() + "/");
+                parentNode = parentNode.getParent();
+            }
+            return returnString.toString();                           
+        }
+        catch(Exception e) {            
+            log.error("Caught Exception: " + e);
+            throw new RulesRepositoryException(e);
+        }
+    }
+    
+    /**
+     * @return a List of the immediate children of this tag
+     * @throws RulesRepositoryException 
+     */
+    public List getChildTags() throws RulesRepositoryException {
+        List children = new ArrayList();
+        
+        try {
+            NodeIterator it = this.node.getNodes();
+            while(it.hasNext()) {
+                Node currentNode = it.nextNode();
+                children.add(new CategoryItem(this.rulesRepository, currentNode));
+            }
+        }
+        catch(Exception e) {
+            log.error("Caught Exception: " + e);
+            throw new RulesRepositoryException(e);
+        }        
+        
+        return children;
+    }
+
+    /**
+     * Gets a TagItem object encapsulating the specified child tag. If the child tag 
+     * doesn't exist, it is created.
+     * 
+     * @param tagName the name of the child tag to get or add
+     * @return a TagItem encapsulating the specified child tag
+     * @throws RulesRepositoryException
+     */
+    public CategoryItem getChildTag(String tagName) throws RulesRepositoryException {
+        try {
+            return this.rulesRepository.getOrCreateCategory(this.getFullPath() + "/" + tagName);
+        }
+        catch(Exception e) {
+            log.error("Caught Exception: " + e);
+            throw new RulesRepositoryException(e);
+        }
+    }
+}

Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RuleItem.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -163,7 +163,7 @@
                 throw new RulesRepositoryException(message);
             }                                       
             
-            TagItem tagItem = this.rulesRepository.getTag(tag);
+            CategoryItem tagItem = this.rulesRepository.getOrCreateCategory(tag);
                                     
             //now set the tag property of the rule
             Property tagReferenceProperty;
@@ -301,7 +301,7 @@
                 Value[] tagValues = tagReferenceProperty.getValues();                
                 for(int i=0; i<tagValues.length; i++) {
                     Node tagNode = this.node.getSession().getNodeByUUID(tagValues[i].getString());
-                    TagItem tagItem = new TagItem(this.rulesRepository, tagNode);
+                    CategoryItem tagItem = new CategoryItem(this.rulesRepository, tagNode);
                     returnList.add(tagItem);
                 }
             }
@@ -430,7 +430,7 @@
             
             returnString.append("Rule tags:\n");
             for(Iterator it=this.getTags().iterator(); it.hasNext();) {
-                TagItem currentTag = (TagItem)it.next();
+                CategoryItem currentTag = (CategoryItem)it.next();
                 returnString.append(currentTag.getName() + "\n");
             }
             returnString.append("--------------\n");

Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulePackageItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulePackageItem.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulePackageItem.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -200,7 +200,7 @@
         try {                       
             Value[] valueArray = this.node.getProperty(RULE_REFERENCE_PROPERTY_NAME).getValues();
             List returnList = new ArrayList();
-            
+           
             for(int i=0; i<valueArray.length; i++) {
                 Node ruleNode = this.node.getSession().getNodeByUUID(valueArray[i].getString());
                 returnList.add(new RuleItem(this.rulesRepository, ruleNode));

Added: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulePackageIterator.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulePackageIterator.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulePackageIterator.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -0,0 +1,37 @@
+package org.drools.repository;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+/**
+ * This wraps a node iterator, and provides RulePackageItems when requested.
+ * This supports lazy loading if needed.
+ */
+public class RulePackageIterator
+    implements
+    Iterator {
+    
+    
+    
+    private NodeIterator packageNodeIterator;
+    private RulesRepository repository;
+
+    public RulePackageIterator(RulesRepository repository, NodeIterator packageNodes) {
+        this.packageNodeIterator = packageNodes;
+    }
+
+    public boolean hasNext() {
+        return this.packageNodeIterator.hasNext();
+    }
+
+    public Object next() {        
+        return new RulePackageItem(this.repository, (Node) this.packageNodeIterator.next());
+    }
+
+    public void remove() {
+        this.packageNodeIterator.remove();
+    }
+
+}

Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepository.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepository.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepository.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -630,7 +630,7 @@
      * @return a TagItem object encapsulating the node for the tag in the repository
      * @throws RulesRepositoryException 
      */
-    public TagItem getTag(String tagName) throws RulesRepositoryException {
+    public CategoryItem getOrCreateCategory(String tagName) throws RulesRepositoryException {
         log.debug("getting tag with name: " + tagName);
         
         try {
@@ -641,11 +641,11 @@
             while(tok.hasMoreTokens()) {                                
                 String currentTagName = tok.nextToken();
                 
-                tagNode = this.addNodeIfNew(folderNode, currentTagName, TagItem.TAG_NODE_TYPE_NAME);
+                tagNode = this.addNodeIfNew(folderNode, currentTagName, CategoryItem.TAG_NODE_TYPE_NAME);
                 folderNode = tagNode;
             }             
                                     
-            return new TagItem(this, tagNode);
+            return new CategoryItem(this, tagNode);
         }
         catch(Exception e) {
             log.error("Caught Exception: " + e);
@@ -653,9 +653,15 @@
         }
     }
 
+    /**
+     * This will retrieve a list of RuleItem objects - that are allocated to the 
+     * provided category.
+     * Only the latest versions of each RuleItem will be returned (you will have 
+     * to delve into the rules deepest darkest history yourself... mahahahaha).
+     */
     public List findRulesByTag(String categoryTag) throws RulesRepositoryException {
         
-        TagItem item = this.getTag( categoryTag );
+        CategoryItem item = this.getOrCreateCategory( categoryTag );
         List results = new ArrayList();
         try {
             PropertyIterator it = item.getNode().getReferences();
@@ -668,4 +674,39 @@
             throw new RulesRepositoryException(e);
         }        
     }
+    
+    /**
+     * @return an Iterator which will provide RulePackageItem's.
+     * This will show ALL the packages, only returning latest versions, by default.
+     */
+    public Iterator listPackages()  {
+        Node folderNode = this.getAreaNode(RULE_PACKAGE_AREA);
+        try {
+            return new RulePackageIterator(this, folderNode.getNodes());
+        } catch ( RepositoryException e ) {
+            throw new RulesRepositoryException(e);
+        }
+    }
+    
+    /** 
+     * This will provide a list of top level category strings. 
+     * Use getCategory to get a specific category to drill down into it.
+     */
+    public List listCategoryNames() throws RulesRepositoryException {
+        try {
+            
+            Node folderNode = this.getAreaNode(TAG_AREA);
+            NodeIterator it = folderNode.getNodes();            
+            
+            List nodeNames = new ArrayList();
+            while(it.hasNext()) {
+                Node catNode = (Node) it.next();
+                nodeNames.add( catNode.getName() );
+            }
+            
+            return nodeNames;
+        } catch ( RepositoryException e ) {
+            throw new RulesRepositoryException(e);
+        }
+    }
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepositoryException.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepositoryException.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/RulesRepositoryException.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -6,7 +6,7 @@
  * 
  * @author btruitt
  */
-public class RulesRepositoryException extends Exception {
+public class RulesRepositoryException extends RuntimeException {
 
     /**
      * version id for serialization purposes

Deleted: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/TagItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/TagItem.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/TagItem.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -1,110 +0,0 @@
-package org.drools.repository;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-
-import org.apache.log4j.Logger;
-
-/**
- * The TagItem class abstracts away details of the underlying JCR repository.
- * 
- * @author btruitt
- */
-public class TagItem extends Item {
-    private Logger log = Logger.getLogger(TagItem.class);
-    
-    /**
-     * The name of the tag node type
-     */
-    public static final String TAG_NODE_TYPE_NAME = "drools:tag_node_type";
-    
-    /**
-     * Constructs an object of type TagItem corresponding the specified node
-     * @param rulesRepository the rulesRepository that instantiated this object
-     * @param node the node to which this object corresponds
-     * @throws RulesRepositoryException 
-     */
-    public TagItem(RulesRepository rulesRepository, Node node) throws RulesRepositoryException {
-        super(rulesRepository, node);
-        
-        try {
-            //make sure this node is a tag node       
-            if(!(this.node.getPrimaryNodeType().getName().equals(TAG_NODE_TYPE_NAME))) {
-                String message = this.node.getName() + " is not a node of type " + TAG_NODE_TYPE_NAME + ". It is a node of type: " + this.node.getPrimaryNodeType().getName();
-                log.error(message);
-                throw new RulesRepositoryException(message);
-            }    
-        }
-        catch(Exception e) {
-            log.error("Caught exception: " + e);
-            throw new RulesRepositoryException(e);
-        }
-    }
-
-    /**
-     * @return the full path of this tag, rooted at the tag area of the repository. 
-     * @throws RulesRepositoryException 
-     */
-    public String getFullPath() throws RulesRepositoryException {        
-        try {
-            log.debug("getting full path for node named: " + this.node.getName());
-            
-            StringBuffer returnString = new StringBuffer();
-            returnString.append(this.node.getName());
-            Node parentNode = this.node.getParent();
-            while(!parentNode.getName().equals(RulesRepository.TAG_AREA)) {
-                returnString.insert(0, parentNode.getName() + "/");
-                parentNode = parentNode.getParent();
-            }
-            return returnString.toString();                           
-        }
-        catch(Exception e) {            
-            log.error("Caught Exception: " + e);
-            throw new RulesRepositoryException(e);
-        }
-    }
-    
-    /**
-     * @return a List of the immediate children of this tag
-     * @throws RulesRepositoryException 
-     */
-    public List getChildTags() throws RulesRepositoryException {
-        List children = new ArrayList();
-        
-        try {
-            NodeIterator it = this.node.getNodes();
-            while(it.hasNext()) {
-                Node currentNode = it.nextNode();
-                children.add(new TagItem(this.rulesRepository, currentNode));
-            }
-        }
-        catch(Exception e) {
-            log.error("Caught Exception: " + e);
-            throw new RulesRepositoryException(e);
-        }        
-        
-        return children;
-    }
-
-    /**
-     * Gets a TagItem object encapsulating the specified child tag. If the child tag 
-     * doesn't exist, it is created.
-     * 
-     * @param tagName the name of the child tag to get or add
-     * @return a TagItem encapsulating the specified child tag
-     * @throws RulesRepositoryException
-     */
-    public TagItem getChildTag(String tagName) throws RulesRepositoryException {
-        try {
-            return this.rulesRepository.getTag(this.getFullPath() + "/" + tagName);
-        }
-        catch(Exception e) {
-            log.error("Caught Exception: " + e);
-            throw new RulesRepositoryException(e);
-        }
-    }
-}

Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/AllTests.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/AllTests.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/AllTests.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -12,7 +12,7 @@
         suite.addTestSuite(RulePackageItemTestCase.class);
         suite.addTestSuite(DslItemTestCase.class);
         suite.addTestSuite(RuleItemTestCase.class);
-        suite.addTestSuite(TagItemTestCase.class);
+        suite.addTestSuite(CategoryItemTestCase.class);
         suite.addTestSuite(RulesRepositoryTestCase.class);
         //$JUnit-END$
         return suite;

Copied: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/CategoryItemTestCase.java (from rev 5888, labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/TagItemTestCase.java)
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/TagItemTestCase.java	2006-08-15 09:38:05 UTC (rev 5888)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/CategoryItemTestCase.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -0,0 +1,126 @@
+package org.drools.repository.test;
+
+import java.util.List;
+
+import org.drools.repository.RulesRepository;
+import org.drools.repository.CategoryItem;
+
+import junit.framework.TestCase;
+
+public class CategoryItemTestCase extends TestCase {
+    private RulesRepository rulesRepository = null;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        rulesRepository = new RulesRepository(true);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        rulesRepository.logout();
+    }
+
+    public void testTagItem() {
+        try {            
+            CategoryItem tagItem1 = rulesRepository.getOrCreateCategory("TestTag");
+            assertNotNull(tagItem1);
+            assertEquals("TestTag", tagItem1.getName());                        
+            
+            CategoryItem tagItem2 = rulesRepository.getOrCreateCategory("TestTag");
+            assertNotNull(tagItem2);
+            assertEquals("TestTag", tagItem2.getName());
+            assertEquals(tagItem1, tagItem2);
+            
+            rulesRepository.getOrCreateCategory( "Foo" );
+            
+            List cats = rulesRepository.listCategoryNames();
+            assertEquals(2, cats.size());
+            
+            assertEquals("TestTag", cats.get( 0 ));
+            assertEquals("Foo", cats.get( 1 ));
+            
+        }
+        catch(Exception e) {
+            fail("Unexpected Exception caught: " + e);
+        }        
+    }    
+    
+    public void testGetChildTags() {
+        try {            
+            CategoryItem tagItem1 = rulesRepository.getOrCreateCategory("TestTag");
+            assertNotNull(tagItem1);
+            assertEquals("TestTag", tagItem1.getName());                        
+            
+            List childTags = tagItem1.getChildTags();
+            assertNotNull(childTags);
+            assertEquals(0, childTags.size());
+            
+            CategoryItem childTagItem1 = tagItem1.getChildTag("TestChildTag1");
+            assertNotNull(childTagItem1);
+            assertEquals("TestChildTag1", childTagItem1.getName());
+            
+            childTags = tagItem1.getChildTags();
+            assertNotNull(childTags);
+            assertEquals(1, childTags.size());
+            assertEquals("TestChildTag1", ((CategoryItem)childTags.get(0)).getName());
+            
+            CategoryItem childTagItem2 = tagItem1.getChildTag("TestChildTag2");
+            assertNotNull(childTagItem2);
+            assertEquals("TestChildTag2", childTagItem2.getName());
+            
+            childTags = tagItem1.getChildTags();
+            assertNotNull(childTags);
+            assertEquals(2, childTags.size());
+        }
+        catch(Exception e) {
+            fail("Unexpected Exception caught: " + e);
+        }
+    }
+    
+    public void testGetChildTag() {
+        try {            
+            CategoryItem tagItem1 = rulesRepository.getOrCreateCategory("TestTag");
+            assertNotNull(tagItem1);
+            assertEquals("TestTag", tagItem1.getName());                        
+            
+            //test that child is added if not already in existence
+            List childTags = tagItem1.getChildTags();
+            assertNotNull(childTags);
+            assertEquals(0, childTags.size());
+            
+            CategoryItem childTagItem1 = tagItem1.getChildTag("TestChildTag1");
+            assertNotNull(childTagItem1);
+            assertEquals("TestChildTag1", childTagItem1.getName());
+                        
+            //test that if already there, it is returned
+            CategoryItem childTagItem2 = tagItem1.getChildTag("TestChildTag1");
+            assertNotNull(childTagItem2);
+            assertEquals("TestChildTag1", childTagItem2.getName());
+            assertEquals(childTagItem1, childTagItem2);
+        }
+        catch(Exception e) {
+            fail("Unexpected Exception caught: " + e);
+        }
+    }
+    
+    public void testGetFullPath() {
+        try {            
+            CategoryItem tagItem1 = rulesRepository.getOrCreateCategory("TestTag");
+            assertNotNull(tagItem1);
+            assertEquals("TestTag", tagItem1.getFullPath());                        
+                                    
+            CategoryItem childTagItem1 = tagItem1.getChildTag("TestChildTag1");
+            assertNotNull(childTagItem1);
+            assertEquals("TestTag/TestChildTag1", childTagItem1.getFullPath());
+                        
+            CategoryItem childTagItem2 = childTagItem1.getChildTag("TestChildTag2");
+            assertNotNull(childTagItem2);
+            assertEquals("TestTag/TestChildTag1/TestChildTag2", childTagItem2.getFullPath());
+            
+            
+        }
+        catch(Exception e) {
+            fail("Unexpected Exception caught: " + e);
+        }
+    }
+}

Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RuleItemTestCase.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -89,7 +89,7 @@
             ruleItem1.addTag("TestTag");
             List tags = ruleItem1.getTags();
             assertEquals(1, tags.size());
-            assertEquals("TestTag", ((TagItem)tags.get(0)).getName());
+            assertEquals("TestTag", ((CategoryItem)tags.get(0)).getName());
             
             ruleItem1.addTag("TestTag2");
             tags = ruleItem1.getTags();
@@ -97,12 +97,8 @@
             
             
             //now test retrieve by tags
-            
-            System.out.println(System.currentTimeMillis());
-            List result = this.rulesRepository.findRulesByTag("TestTag");
-            System.out.println(System.currentTimeMillis());
-            assertEquals(1, result.size());
-            
+            List result = this.rulesRepository.findRulesByTag("TestTag");            
+            assertEquals(1, result.size());            
             RuleItem retItem = (RuleItem) result.get( 0 );
             assertEquals("drl1.drl", retItem.getName());
             
@@ -127,7 +123,7 @@
             ruleItem1.removeTag("TestTag2");
             tags = ruleItem1.getTags();
             assertEquals(1, tags.size());
-            assertEquals("TestTag3", ((TagItem)tags.get(0)).getName());            
+            assertEquals("TestTag3", ((CategoryItem)tags.get(0)).getName());            
         }
         catch(Exception e) {
             fail("Caught unexpected exception: " + e);
@@ -146,7 +142,7 @@
             ruleItem1.addTag("TestTag");                                    
             tags = ruleItem1.getTags();
             assertEquals(1, tags.size());
-            assertEquals("TestTag", ((TagItem)tags.get(0)).getName());
+            assertEquals("TestTag", ((CategoryItem)tags.get(0)).getName());
         }
         catch(Exception e) {
             fail("Caught unexpected exception: " + e);

Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RulePackageItemTestCase.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RulePackageItemTestCase.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RulePackageItemTestCase.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -1,6 +1,7 @@
 package org.drools.repository.test;
 
 import java.io.File;
+import java.util.Iterator;
 import java.util.List;
 
 import org.drools.repository.*;
@@ -77,7 +78,13 @@
             
             rules = rulePackageItem1.getRules();
             assertNotNull(rules);
-            assertEquals(2, rules.size());            
+            assertEquals(2, rules.size());  
+            
+            Iterator it = rulesRepository.listPackages();
+            assertTrue(it.hasNext());
+            
+            RulePackageItem pack = (RulePackageItem) it.next();
+            assertEquals("testRulePackage", pack.getName());
         }
         catch(Exception e) {
             e.printStackTrace();

Modified: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RulesRepositoryTestCase.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RulesRepositoryTestCase.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/RulesRepositoryTestCase.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -188,18 +188,18 @@
         try {
             rulesRepository = new RulesRepository(true);
             
-            TagItem tagItem1 = rulesRepository.getTag("TestTag");
+            CategoryItem tagItem1 = rulesRepository.getOrCreateCategory("TestTag");
             assertNotNull(tagItem1);
             assertEquals("TestTag", tagItem1.getName());
             assertEquals("TestTag", tagItem1.getFullPath());
             
-            TagItem tagItem2 = rulesRepository.getTag("TestTag");
+            CategoryItem tagItem2 = rulesRepository.getOrCreateCategory("TestTag");
             assertNotNull(tagItem2);
             assertEquals("TestTag", tagItem2.getName());
             assertEquals(tagItem1, tagItem2);
             
             //now test getting a tag down in the tag hierarchy
-            TagItem tagItem3 = rulesRepository.getTag("TestTag/TestChildTag1");
+            CategoryItem tagItem3 = rulesRepository.getOrCreateCategory("TestTag/TestChildTag1");
             assertNotNull(tagItem3);
             assertEquals("TestChildTag1", tagItem3.getName());
             assertEquals("TestTag/TestChildTag1", tagItem3.getFullPath());                                   

Deleted: labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/TagItemTestCase.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/TagItemTestCase.java	2006-08-15 20:05:28 UTC (rev 5902)
+++ labs/jbossrules/trunk/drools-repository/src/java/org/drools/repository/test/TagItemTestCase.java	2006-08-15 21:10:20 UTC (rev 5903)
@@ -1,115 +0,0 @@
-package org.drools.repository.test;
-
-import java.util.List;
-
-import org.drools.repository.RulesRepository;
-import org.drools.repository.TagItem;
-
-import junit.framework.TestCase;
-
-public class TagItemTestCase extends TestCase {
-    private RulesRepository rulesRepository = null;
-    
-    protected void setUp() throws Exception {
-        super.setUp();
-        rulesRepository = new RulesRepository(true);
-    }
-
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        rulesRepository.logout();
-    }
-
-    public void testTagItem() {
-        try {            
-            TagItem tagItem1 = rulesRepository.getTag("TestTag");
-            assertNotNull(tagItem1);
-            assertEquals("TestTag", tagItem1.getName());                        
-            
-            TagItem tagItem2 = rulesRepository.getTag("TestTag");
-            assertNotNull(tagItem2);
-            assertEquals("TestTag", tagItem2.getName());
-            assertEquals(tagItem1, tagItem2);
-        }
-        catch(Exception e) {
-            fail("Unexpected Exception caught: " + e);
-        }        
-    }    
-    
-    public void testGetChildTags() {
-        try {            
-            TagItem tagItem1 = rulesRepository.getTag("TestTag");
-            assertNotNull(tagItem1);
-            assertEquals("TestTag", tagItem1.getName());                        
-            
-            List childTags = tagItem1.getChildTags();
-            assertNotNull(childTags);
-            assertEquals(0, childTags.size());
-            
-            TagItem childTagItem1 = tagItem1.getChildTag("TestChildTag1");
-            assertNotNull(childTagItem1);
-            assertEquals("TestChildTag1", childTagItem1.getName());
-            
-            childTags = tagItem1.getChildTags();
-            assertNotNull(childTags);
-            assertEquals(1, childTags.size());
-            assertEquals("TestChildTag1", ((TagItem)childTags.get(0)).getName());
-            
-            TagItem childTagItem2 = tagItem1.getChildTag("TestChildTag2");
-            assertNotNull(childTagItem2);
-            assertEquals("TestChildTag2", childTagItem2.getName());
-            
-            childTags = tagItem1.getChildTags();
-            assertNotNull(childTags);
-            assertEquals(2, childTags.size());
-        }
-        catch(Exception e) {
-            fail("Unexpected Exception caught: " + e);
-        }
-    }
-    
-    public void testGetChildTag() {
-        try {            
-            TagItem tagItem1 = rulesRepository.getTag("TestTag");
-            assertNotNull(tagItem1);
-            assertEquals("TestTag", tagItem1.getName());                        
-            
-            //test that child is added if not already in existence
-            List childTags = tagItem1.getChildTags();
-            assertNotNull(childTags);
-            assertEquals(0, childTags.size());
-            
-            TagItem childTagItem1 = tagItem1.getChildTag("TestChildTag1");
-            assertNotNull(childTagItem1);
-            assertEquals("TestChildTag1", childTagItem1.getName());
-                        
-            //test that if already there, it is returned
-            TagItem childTagItem2 = tagItem1.getChildTag("TestChildTag1");
-            assertNotNull(childTagItem2);
-            assertEquals("TestChildTag1", childTagItem2.getName());
-            assertEquals(childTagItem1, childTagItem2);
-        }
-        catch(Exception e) {
-            fail("Unexpected Exception caught: " + e);
-        }
-    }
-    
-    public void testGetFullPath() {
-        try {            
-            TagItem tagItem1 = rulesRepository.getTag("TestTag");
-            assertNotNull(tagItem1);
-            assertEquals("TestTag", tagItem1.getFullPath());                        
-                                    
-            TagItem childTagItem1 = tagItem1.getChildTag("TestChildTag1");
-            assertNotNull(childTagItem1);
-            assertEquals("TestTag/TestChildTag1", childTagItem1.getFullPath());
-                        
-            TagItem childTagItem2 = childTagItem1.getChildTag("TestChildTag2");
-            assertNotNull(childTagItem2);
-            assertEquals("TestTag/TestChildTag1/TestChildTag2", childTagItem2.getFullPath());
-        }
-        catch(Exception e) {
-            fail("Unexpected Exception caught: " + e);
-        }
-    }
-}




More information about the jboss-svn-commits mailing list