[jboss-svn-commits] JBL Code SVN: r16807 - in labs/jbossrules/trunk/drools-repository/src: test/java/org/drools/repository and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Nov 26 01:56:18 EST 2007


Author: michael.neale at jboss.com
Date: 2007-11-26 01:56:18 -0500 (Mon, 26 Nov 2007)
New Revision: 16807

Modified:
   labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/PackageItem.java
   labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/PackageItemTest.java
Log:
JBRULES-1271 scenario persistence

Modified: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/PackageItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/PackageItem.java	2007-11-26 06:30:09 UTC (rev 16806)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/PackageItem.java	2007-11-26 06:56:18 UTC (rev 16807)
@@ -22,12 +22,12 @@
 
 /**
  * A PackageItem object aggregates a set of assets (for example, rules). This is advantageous for systems using the JBoss Rules
- * engine where the application might make use of many related rules.  
+ * engine where the application might make use of many related rules.
  * <p>
  * A PackageItem refers to rule nodes within the RulesRepository.  It contains the "master copy" of assets (which may be linked
  * into other packages or other types of containers).
  * This is a container "node".
- * 
+ *
  * @author btruitt
  */
 public class PackageItem extends VersionableItem {
@@ -38,7 +38,7 @@
      * for this package.
      */
     public static final String ASSET_FOLDER_NAME                = "assets";
-    
+
     /**
      * The dublin core format attribute.
      */
@@ -49,7 +49,7 @@
      */
     public static final String RULE_PACKAGE_TYPE_NAME           = "drools:packageNodeType";
 
-    
+
     public static final String HEADER_PROPERTY_NAME             = "drools:header";
     public static final String EXTERNAL_URI_PROPERTY_NAME             = "drools:externalURI";
 
@@ -59,7 +59,7 @@
      * Constructs an object of type RulePackageItem corresponding the specified node
      * @param rulesRepository the rulesRepository that instantiated this object
      * @param node the node to which this object corresponds
-     * @throws RulesRepositoryException 
+     * @throws RulesRepositoryException
      */
     public PackageItem(RulesRepository rulesRepository,
                            Node node) throws RulesRepositoryException {
@@ -67,7 +67,7 @@
                node );
 
         try {
-            //make sure this node is a rule package node       
+            //make sure this node is a rule package node
             if ( !(this.node.getPrimaryNodeType().getName().equals( RULE_PACKAGE_TYPE_NAME ) ||
                     isHistoricalVersion())) {
                 String message = this.node.getName() + " is not a node of type " + RULE_PACKAGE_TYPE_NAME + ". It is a node of type: " + this.node.getPrimaryNodeType().getName();
@@ -79,15 +79,15 @@
             throw new RulesRepositoryException( e );
         }
     }
-    
+
     PackageItem() {
         super(null, null);
     }
 
 
-    
+
     /**
-     * Return the name of the package. 
+     * Return the name of the package.
      */
     public String getName() {
         try {
@@ -101,7 +101,7 @@
             throw new RulesRepositoryException( e );
         }
     }
-    
+
     /**
      * @return true if this package is actually a snapshot.
      */
@@ -112,8 +112,40 @@
             throw new IllegalStateException(e);
         }
     }
-    
+
+
+
     /**
+     * Set this to indicate if the binary is up to date, or not.
+     */
+    public void updateBinaryUpToDate(boolean status) {
+    	try {
+    		checkIsUpdateable();
+    		node.checkout();
+			node.setProperty("drools:binaryUpToDate", status);
+		} catch (RepositoryException e) {
+			log.error(e);
+		}
+    }
+
+    /**
+     * Return true if the binary is "up to date".
+     * @return
+     */
+    public boolean isBinaryUpToDate() {
+		try {
+			if (this.node.hasProperty("drools:binaryUpToDate")) {
+				return node.getProperty("drools:binaryUpToDate").getBoolean();
+			} else {
+				return false;
+			}
+		} catch (RepositoryException e) {
+			log.error(e);
+			throw new RulesRepositoryException(e);
+		}
+    }
+
+    /**
      * returns the name of the snapshot, if this package is really a snapshot.
      * If it is not, it will just return the name of the package, so use wisely !
      */
@@ -129,13 +161,13 @@
     public AssetItem addAsset(String assetName, String description) {
         return addAsset(assetName, description, null, null);
     }
-    
 
+
     /**
      * This adds a rule to the current physical package (you can move it later).
      * With the given category.
-     * 
-     * This will NOT check the asset in, just create the basic record. 
+     *
+     * This will NOT check the asset in, just create the basic record.
      * @param assetName The name of the asset (the file name minus the extension)
      * @param description A description of the asset.
      * @param initialCategory The initial category the asset is placed in (can belong to multiple ones later).
@@ -161,26 +193,26 @@
                 ruleNode.setProperty( AssetItem.FORMAT_PROPERTY_NAME,
                                       AssetItem.DEFAULT_CONTENT_FORMAT );
             }
-            
 
+
             ruleNode.setProperty( VersionableItem.CHECKIN_COMMENT,
                                   "Initial" );
 
             Calendar lastModified = Calendar.getInstance();
-            
-            ruleNode.setProperty( AssetItem.LAST_MODIFIED_PROPERTY_NAME, lastModified );            
+
+            ruleNode.setProperty( AssetItem.LAST_MODIFIED_PROPERTY_NAME, lastModified );
             ruleNode.setProperty( AssetItem.PACKAGE_NAME_PROPERTY, this.getName() );
             ruleNode.setProperty( CREATOR_PROPERTY_NAME, this.node.getSession().getUserID() );
 
-            
+
             AssetItem rule = new AssetItem( this.rulesRepository, ruleNode );
-                        
+
             rule.updateState( StateItem.DRAFT_STATE_NAME );
-            
+
             if (initialCategory != null) {
                 rule.addCategory( initialCategory );
             }
-            
+
             return rule;
 
         } catch ( RepositoryException e ) {
@@ -194,45 +226,45 @@
 
     }
 
-    /** 
-     * Remove an asset by name 
-     * After doing this, you will need to check in the package 
+    /**
+     * Remove an asset by name
+     * After doing this, you will need to check in the package
      * as removing an item effects the parent package.
      */
     public void removeAsset(String name) {
         try {
-            this.node.getNode( ASSET_FOLDER_NAME + "/" + name ).remove();            
+            this.node.getNode( ASSET_FOLDER_NAME + "/" + name ).remove();
         } catch ( RepositoryException e ) {
             throw new RulesRepositoryException( e );
         }
     }
 
-    
-    
-    // The following should be kept for reference on how to add a reference that 
+
+
+    // The following should be kept for reference on how to add a reference that
     //is either locked to a version or follows head - FOR SHARING ASSETS
     //    /**
     //     * Adds a rule to the rule package node this object represents.  The reference to the rule
-    //     * will optionally follow the head version of the specified rule's node or the specific 
+    //     * will optionally follow the head version of the specified rule's node or the specific
     //     * current version.
-    //     * 
-    //     * @param ruleItem the ruleItem corresponding to the node to add to the rule package this 
+    //     *
+    //     * @param ruleItem the ruleItem corresponding to the node to add to the rule package this
     //     *                 object represents
-    //     * @param followRuleHead if true, the reference to the rule node will follow the head version 
-    //     *                       of the node, even if new versions are added. If false, will refer 
+    //     * @param followRuleHead if true, the reference to the rule node will follow the head version
+    //     *                       of the node, even if new versions are added. If false, will refer
     //     *                       specifically to the current version.
     //     * @throws RulesRepositoryException
     //     */
-    //    public void addRuleReference(RuleItem ruleItem, boolean followRuleHead) throws RulesRepositoryException {        
+    //    public void addRuleReference(RuleItem ruleItem, boolean followRuleHead) throws RulesRepositoryException {
     //        try {
     //            ValueFactory factory = this.node.getSession().getValueFactory();
     //            int i = 0;
     //            Value[] newValueArray = null;
-    //            
+    //
     //            try {
     //                Value[] oldValueArray = this.node.getProperty(RULE_REFERENCE_PROPERTY_NAME).getValues();
-    //                newValueArray = new Value[oldValueArray.length + 1];                
-    //                
+    //                newValueArray = new Value[oldValueArray.length + 1];
+    //
     //                for(i=0; i<oldValueArray.length; i++) {
     //                    newValueArray[i] = oldValueArray[i];
     //                }
@@ -243,7 +275,7 @@
     //            }
     //            finally {
     //                if(newValueArray != null) { //just here to make the compiler happy
-    //                    if(followRuleHead) {                    
+    //                    if(followRuleHead) {
     //                        newValueArray[i] = factory.createValue(ruleItem.getNode());
     //                    }
     //                    else {
@@ -251,14 +283,14 @@
     //                        newValueArray[i] = factory.createValue(ruleItem.getNode().getBaseVersion());
     //                    }
     //                    this.node.checkout();
-    //                    this.node.setProperty(RULE_REFERENCE_PROPERTY_NAME, newValueArray);                
+    //                    this.node.setProperty(RULE_REFERENCE_PROPERTY_NAME, newValueArray);
     //                    this.node.getSession().save();
     //                    this.node.checkin();
     //                }
     //                else {
     //                    throw new RulesRepositoryException("Unexpected null pointer for newValueArray");
     //                }
-    //            }                    
+    //            }
     //        }
     //        catch(UnsupportedRepositoryOperationException e) {
     //            String message = "";
@@ -281,11 +313,11 @@
 
 
 //MN: The following should be kept as a reference on how to remove a version tracking reference
-//as a compliment to the above method (which is also commented out !).     
+//as a compliment to the above method (which is also commented out !).
 //    /**
-//     * Removes the specified rule from the rule package node this object represents.  
-//     * 
-//     * @param ruleItem the ruleItem corresponding to the node to remove from the rule package 
+//     * Removes the specified rule from the rule package node this object represents.
+//     *
+//     * @param ruleItem the ruleItem corresponding to the node to remove from the rule package
 //     *                 this object represents
 //     * @throws RulesRepositoryException
 //     */
@@ -319,7 +351,7 @@
 //                this.node.checkin();
 //            }
 //        } catch ( PathNotFoundException e ) {
-//            //the property has not been created yet. 
+//            //the property has not been created yet.
 //            return;
 //        } catch ( Exception e ) {
 //            log.error( "Caught exception",
@@ -329,18 +361,18 @@
 //    }
 
 
-    //MN: This should be kept as a reference for 
+    //MN: This should be kept as a reference for
     //    /**
     //     * Gets a list of RuleItem objects for each rule node in this rule package
-    //     * 
+    //     *
     //     * @return the List object holding the RuleItem objects in this rule package
-    //     * @throws RulesRepositoryException 
+    //     * @throws RulesRepositoryException
     //     */
     //    public List getRules() throws RulesRepositoryException {
-    //        try {                       
+    //        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));
@@ -348,14 +380,14 @@
     //            return returnList;
     //        }
     //        catch(PathNotFoundException e) {
-    //            //the property has not been created yet. 
+    //            //the property has not been created yet.
     //            return new ArrayList();
-    //        }                                       
+    //        }
     //        catch(Exception e) {
     //            log.error("Caught exception: " + e);
     //            throw new RulesRepositoryException(e);
     //        }
-    //    }   
+    //    }
 
     /** Return an iterator for the rules in this package */
     public Iterator getAssets() {
@@ -363,51 +395,51 @@
             Node content = getVersionContentNode();
             AssetItemIterator it = new AssetItemIterator( content.getNode( ASSET_FOLDER_NAME ).getNodes(),
                                                         this.rulesRepository );
-            return it;        
+            return it;
         } catch ( RepositoryException e ) {
             throw new RulesRepositoryException( e );
         }
 
     }
-    
+
     /**
      * This will query any assets stored under this package.
-     * For example, you can pass in <code>"drools:format = 'drl'"</code> to get a list of 
+     * For example, you can pass in <code>"drools:format = 'drl'"</code> to get a list of
      * only a certain type of asset.
-     * 
+     *
      * @param fieldPredicates A predicate string (SQL style).
-     * @return A list of matches. 
+     * @return A list of matches.
      */
     public AssetItemIterator queryAssets(String fieldPredicates, boolean seekArchived) {
         try {
 
             String sql = "SELECT * FROM " + AssetItem.RULE_NODE_TYPE_NAME;
             sql += " WHERE jcr:path LIKE '" + getVersionContentNode().getPath() + "/" + ASSET_FOLDER_NAME + "[%]/%'";
-            if ( fieldPredicates.length() > 0 ) { 
+            if ( fieldPredicates.length() > 0 ) {
                 sql += " and " + fieldPredicates;
             }
-            
+
             if ( seekArchived == false ) {
                 sql += " AND " + AssetItem.CONTENT_PROPERTY_ARCHIVE_FLAG + " = 'false'";
             }
-            
+
             Query q = node.getSession().getWorkspace().getQueryManager().createQuery( sql, Query.SQL );
-            QueryResult res = q.execute();            
-            return new AssetItemIterator(res.getNodes(), this.rulesRepository);        
+            QueryResult res = q.execute();
+            return new AssetItemIterator(res.getNodes(), this.rulesRepository);
         } catch ( RepositoryException e ) {
             throw new RulesRepositoryException(e);
         }
     }
-    
+
     public AssetItemIterator queryAssets(String fieldPredicates){
         return queryAssets( fieldPredicates, false );
     }
-    
-    
+
+
     public AssetItemIterator listArchivedAssets () {
         return queryAssets( AssetItem.CONTENT_PROPERTY_ARCHIVE_FLAG + " = 'true'" , true );
     }
-    
+
     /**
      * This will load an iterator for assets of the given format type.
      */
@@ -424,7 +456,7 @@
             return queryAssets( predicate );
         }
     }
-    
+
     /**
      * Load a specific rule asset by name.
      */
@@ -433,14 +465,14 @@
         try {
             Node content = getVersionContentNode();
             return new AssetItem(
-                        this.rulesRepository, 
+                        this.rulesRepository,
                         content.getNode( ASSET_FOLDER_NAME ).getNode( name ));
         } catch ( RepositoryException e ) {
              throw new RulesRepositoryException(e);
        }
     }
-    
-    
+
+
     /**
      * Returns true if this package item contains an asset of the given name.
      */
@@ -449,14 +481,14 @@
         try {
             content = getVersionContentNode();
             return content.getNode( ASSET_FOLDER_NAME ).hasNode( name );
-        }         
+        }
         catch ( RepositoryException e ) {
             throw new RulesRepositoryException(e);
         }
     }
 
     /**
-     * Nicely formats the information contained by the node that this object encapsulates    
+     * Nicely formats the information contained by the node that this object encapsulates
      */
     public String toString() {
         try {
@@ -507,35 +539,35 @@
             throw new RulesRepositoryException( e );
         }
     }
-    
+
     /**
      * This will return a list of assets for a given state.
-     * It works through the assets that belong to this package, and 
+     * It works through the assets that belong to this package, and
      * if they are not in the correct state, walks backwards until it finds one
-     * in the correct state. 
-     * 
-     * If it walks all the way back up the versions looking for the "latest" 
-     * version with the appropriate state, and can't find one, 
+     * in the correct state.
+     *
+     * If it walks all the way back up the versions looking for the "latest"
+     * version with the appropriate state, and can't find one,
      * that asset is not included in the result.
-     * 
+     *
      * This will exclude any items that have the "ignoreState" set
      * (so for example, retired items, invalid items etc).
-     * 
+     *
      *  @param state The state of assets to retrieve.
      *  @param ignoreState The statuses to not include in the results (it will look
      *  at the status of the latest one).
      */
     public Iterator getAssetsWithStatus(final StateItem state, final StateItem ignoreState) {
         final Iterator rules = getAssets();
-        
+
         List result = new ArrayList();
         while(rules.hasNext()) {
             AssetItem head = (AssetItem) rules.next();
             if (head.sameState( state )) {
                 result.add( head );
-            } else if (head.sameState( ignoreState )) { 
+            } else if (head.sameState( ignoreState )) {
                 //ignore this one
-            } 
+            }
             else {
                 List fullHistory = new ArrayList();
                 for ( Iterator iter = head.getHistory(); iter.hasNext(); ) {
@@ -544,10 +576,10 @@
                         fullHistory.add( element );
                     }
                 }
-                
+
                 sortHistoryByVersionNumber( fullHistory );
-                
-                
+
+
                 Iterator prev = fullHistory.iterator();
                 while (prev.hasNext()) {
                     AssetItem prevRule = (AssetItem) prev.next();
@@ -574,59 +606,59 @@
                 if (la1 == la2) return 0;
                 else if (la1 < la2) return 1;
                 else return -1;
-                
+
             }
-            
+
         });
     }
-    
+
     /**
      * This will return a list of assets for a given state.
-     * It works through the assets that belong to this package, and 
+     * It works through the assets that belong to this package, and
      * if they are not in the correct state, walks backwards until it finds one
-     * in the correct state. 
-     * 
-     * If it walks all the way back up the versions looking for the "latest" 
-     * version with the appropriate state, and can't find one, 
+     * in the correct state.
+     *
+     * If it walks all the way back up the versions looking for the "latest"
+     * version with the appropriate state, and can't find one,
      * that asset is not included in the result.
-     */    
+     */
     public Iterator getAssetsWithStatus(final StateItem state) {
         return getAssetsWithStatus( state, null );
     }
-    
+
     /**
      * @return The header contents as pertains to a package of rule assets.
      */
     public String getHeader() {
         return this.getStringProperty( HEADER_PROPERTY_NAME );
     }
-    
+
     /**
      * @return The external URI which will be used to sync this package to an external resource.
      * Generally this will resolve to a directory in (for example) Subversion - with each asset
-     * being a file (with the format property as the file extension). 
+     * being a file (with the format property as the file extension).
      */
     public String getExternalURI() {
         return this.getStringProperty( EXTERNAL_URI_PROPERTY_NAME );
     }
-    
+
     public void updateHeader(String header) {
         updateStringProperty( header, HEADER_PROPERTY_NAME );
     }
-    
+
     public void updateExternalURI(String uri) {
         updateStringProperty( uri, EXTERNAL_URI_PROPERTY_NAME );
     }
-    
+
     /**
-     * Update the checkin comment. 
+     * Update the checkin comment.
      */
     public void updateCheckinComment(String comment) {
         updateStringProperty(comment, VersionableItem.CHECKIN_COMMENT);
-    }    
+    }
 
     /**
-     * This will change the status of this package, and all the contained assets. 
+     * This will change the status of this package, and all the contained assets.
      * No new versions are created of anything.
      * @param newState The status tag to change it to.
      */
@@ -638,7 +670,7 @@
             element.updateState( stateItem );
         }
     }
-    
+
     /**
      * If the asset is a binary asset, then use this to update the content
      * (do NOT use text).
@@ -654,22 +686,22 @@
             log.error( "Unable to update the assets binary content", e );
             throw new RulesRepositoryException( e );
         }
-    }    
-    
+    }
+
     /**
      * This is a convenience method for returning the binary data as a byte array.
      */
     public byte[] getCompiledPackageBytes() {
-        
+
         try {
             Node ruleNode = getVersionContentNode();
             if ( ruleNode.hasProperty(  COMPILED_PACKAGE_PROPERTY_NAME ) ) {
                 Property data = ruleNode.getProperty( COMPILED_PACKAGE_PROPERTY_NAME );
                 InputStream in = data.getStream();
-                
+
                 // Create the byte array to hold the data
                 byte[] bytes = new byte[(int) data.getLength()];
-            
+
                 // Read in the bytes
                 int offset = 0;
                 int numRead = 0;
@@ -677,14 +709,14 @@
                        && (numRead=in.read(bytes, offset, bytes.length-offset)) >= 0) {
                     offset += numRead;
                 }
-            
+
                 // Ensure all the bytes have been read in
                 if (offset < bytes.length) {
                     throw new RulesRepositoryException("Could not completely read binary package for "+ getName());
                 }
-            
+
                 // Close the input stream and return bytes
-                in.close();   
+                in.close();
                 return bytes;
             } else {
                 return null;
@@ -693,10 +725,10 @@
             log.error( e );
             if (e instanceof RuntimeException) throw (RuntimeException) e;
             throw new RulesRepositoryException( e );
-        }  
-    }    
-    
-    
+        }
+    }
 
 
+
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/PackageItemTest.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/PackageItemTest.java	2007-11-26 06:30:09 UTC (rev 16806)
+++ labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/PackageItemTest.java	2007-11-26 06:56:18 UTC (rev 16807)
@@ -11,32 +11,32 @@
     public void testListPackages() throws Exception {
         RulesRepository repo = getRepo();
         PackageItem item = repo.createPackage( "testListPackages1", "lalalala" );
-        
+
         assertNotNull(item.getCreator());
-        
+
         item.updateStringProperty( "goo", "whee" );
         assertEquals("goo", item.getStringProperty( "whee" ));
         assertFalse(item.getCreator().equals( "" ));
-        
+
         List list = iteratorToList( repo.listPackages() );
         int prevSize = list.size();
         repo.createPackage( "testListPackages2", "abc" );
-        
+
         list = iteratorToList( repo.listPackages() );
-        
-        
-        
+
+
+
         assertEquals(prevSize + 1, list.size());
     }
-    
+
     public void testRulePackageItem() throws Exception {
         RulesRepository repo = getRepo();
-            
+
         //calls constructor
         PackageItem rulePackageItem1 = repo.createPackage("testRulePackage", "desc");
         assertNotNull(rulePackageItem1);
         assertEquals("testRulePackage", rulePackageItem1.getName());
-        
+
         Iterator it = getRepo().listPackages();
         assertTrue(it.hasNext());
 
@@ -48,38 +48,38 @@
         }
         fail("should have picked up the testRulePackage but didnt.");
 
-        
+
     }
-    
 
 
-    
+
+
     /**
      * This is showing how to copy a package with standard JCR
      */
     public void testPackageCopy() throws Exception {
         RulesRepository repo = getRepo();
-        
+
         PackageItem pkg = repo.createPackage( "testPackageCopy", "this is something" );
-        
+
         AssetItem it1 = pkg.addAsset( "testPackageCopy1", "la" );
         AssetItem it2 = pkg.addAsset( "testPackageCopy2", "la" );
-        
+
         it1.updateContent( "new content" );
         it2.updateContent( "more content" );
         it1.checkin( "c" );
         it2.checkin( "c" );
-        
+
         it1 = pkg.loadAsset( "testPackageCopy1" );
         List hist1 = iteratorToList( it1.getHistory() );
         System.out.println(hist1.size());
-        
-        
+
+
         repo.getSession().getWorkspace().copy( pkg.getNode().getPath(), pkg.getNode().getPath() + "_");
-        
+
         PackageItem pkg2 = repo.loadPackage( "testPackageCopy_" );
         assertNotNull(pkg2);
-        
+
         assertEquals(2, iteratorToList( pkg2.getAssets() ).size() );
         AssetItem it1_ = pkg2.loadAsset( "testPackageCopy1" );
 
@@ -89,28 +89,28 @@
         assertEquals("new content", it1_.getContent());
 
     }
-    
+
     public void testPackageSnapshot() throws Exception {
         RulesRepository repo = getRepo();
-        
+
         PackageItem pkg = repo.createPackage( "testPackageSnapshot", "this is something" );
         assertFalse(pkg.isSnapshot());
-        
-        
+
+
         AssetItem it1 = pkg.addAsset( "testPackageCopy1", "la" );
         AssetItem it2 = pkg.addAsset( "testPackageCopy2", "la" );
-        
+
         it1.updateContent( "new content" );
         it1.updateFormat( "drl" );
         it2.updateContent( "more content" );
         it2.updateFormat( "drl" );
         it1.checkin( "c" );
         it2.checkin( "c" );
-        
+
         long ver1 = it1.getVersionNumber();
         long ver2 = it2.getVersionNumber();
         assertFalse( ver1 == 0 );
-        
+
         assertEquals(2, iteratorToList(pkg.listAssetsByFormat( new String[] {"drl"} )).size());
         repo.createPackageSnapshot( "testPackageSnapshot", "PROD 2.0" );
 
@@ -128,7 +128,7 @@
         List loadedAssets = iteratorToList( pkgLoaded.getAssets() );
         List _loadedAssets = iteratorToList( _pkgLoaded.getAssets() );
         assertEquals(loadedAssets.size(), _loadedAssets.size());
-        
+
         //now make some changes on the main line
         it1.updateContent( "XXX" );
         it1.checkin( "X" );
@@ -137,9 +137,9 @@
         it3.updateFormat( "drl" );
         it3.checkin( "a" );
         assertEquals(3, iteratorToList( pkg.listAssetsByFormat( new String[] {"drl"} )).size());
-        
-        
-        
+
+
+
         PackageItem pkg2 = repo.loadPackageSnapshot( "testPackageSnapshot", "PROD 2.0" );
         assertNotNull(pkg2);
         List snapAssets = iteratorToList( pkg2.getAssets() );
@@ -147,26 +147,26 @@
         assertFalse(pkg2.getUUID().equals( pkg.getUUID() ));
         assertTrue(snapAssets.get( 0 ) instanceof AssetItem);
         assertTrue(snapAssets.get( 1 ) instanceof AssetItem);
-        
+
         AssetItem sn1 = (AssetItem) snapAssets.get( 0 );
         AssetItem sn2 = (AssetItem) snapAssets.get( 1 );
         assertEquals("la", sn1.getDescription());
         assertEquals("la", sn2.getDescription());
         assertEquals(ver1, sn1.getVersionNumber());
         assertEquals(ver2, sn2.getVersionNumber());
-        
 
+
         assertEquals(2, iteratorToList(pkg2.listAssetsByFormat( new String[] {"drl"} )).size());
-        
+
         //now check we can list the snappies
         String[] res = repo.listPackageSnapshots("testPackageSnapshot");
-        
+
         assertEquals(1, res.length);
         assertEquals("PROD 2.0", res[0]);
-        
+
         res = repo.listPackageSnapshots( "does not exist" );
         assertEquals(0, res.length);
-        
+
         repo.removePackageSnapshot( "testPackageSnapshot", "XX" );
         //does nothing... but should not barf...
         try {
@@ -175,24 +175,24 @@
         } catch (RulesRepositoryException e) {
             assertNotNull(e.getMessage());
         }
-        
+
         repo.removePackageSnapshot( "testPackageSnapshot", "PROD 2.0" );
         repo.save();
-        
+
         res = repo.listPackageSnapshots( "testPackageSnapshot" );
         assertEquals(0, res.length);
-        
+
         repo.createPackageSnapshot( "testPackageSnapshot", "BOO" );
         res = repo.listPackageSnapshots( "testPackageSnapshot" );
         assertEquals(1, res.length);
         repo.copyPackageSnapshot( "testPackageSnapshot", "BOO", "BOO2" );
         res = repo.listPackageSnapshots( "testPackageSnapshot" );
         assertEquals(2, res.length);
-        
+
         assertEquals("BOO", res[0]);
         assertEquals("BOO2", res[1]);
-        
-        
+
+
     }
 
     private RulesRepository getRepo() {
@@ -206,10 +206,10 @@
         rulePackageItem = getRepo().loadPackage("testLoadRuleRuleItem");
         assertNotNull(rulePackageItem);
         assertEquals("testLoadRuleRuleItem", rulePackageItem.getName());
-        
+
         assertEquals("desc", rulePackageItem.getDescription());
         assertEquals(PackageItem.PACKAGE_FORMAT, rulePackageItem.getFormat());
-        // try loading rule package that was not created 
+        // try loading rule package that was not created
         try {
             rulePackageItem = getRepo().loadPackage("anotherRuleRuleItem");
             fail("Exception not thrown loading rule package that was not created.");
@@ -217,128 +217,128 @@
             // that is OK!
             assertNotNull(e.getMessage());
         }
-    }    
-    
+    }
+
     /**
      * This will test getting rules of specific versions out of a package.
      */
     public void testPackageRuleVersionExtraction() throws Exception {
         PackageItem pack = getRepo().createPackage( "package extractor", "foo" );
-        
+
         AssetItem rule1 = pack.addAsset( "rule number 1", "yeah man" );
         rule1.checkin( "version0" );
-        
+
         AssetItem rule2 = pack.addAsset( "rule number 2", "no way" );
         rule2.checkin( "version0" );
-        
+
         AssetItem rule3 = pack.addAsset( "rule number 3", "yes way" );
         rule3.checkin( "version0" );
-        
+
         getRepo().save();
-        
+
         pack = getRepo().loadPackage( "package extractor" );
         List rules = iteratorToList( pack.getAssets() );
         assertEquals(3, rules.size());
-        
+
         getRepo().createState( "foobar" );
-        
+
         StateItem state = getRepo().getState( "foobar" );
-        
+
         rule1.updateState( "foobar" );
         rule1.checkin( "yeah" );
-        
+
         pack = getRepo().loadPackage( "package extractor" );
-        
+
         rules = iteratorToList( pack.getAssetsWithStatus(state) );
-        
+
         assertEquals(1, rules.size());
-        
+
         //now lets try an invalid state tag
         getRepo().createState( "whee" );
         rules = iteratorToList( pack.getAssetsWithStatus( getRepo().getState( "whee" ) ) );
         assertEquals(0, rules.size());
-        
+
         //and Draft, as we start with Draft, should be able to get all three back
         //although an older version of one of them
         rules = iteratorToList( pack.getAssetsWithStatus(getRepo().getState( StateItem.DRAFT_STATE_NAME )) );
         assertEquals(3, rules.size());
-        
+
         //now do an update, and pull it out via state
         rule1.updateContent( "new content" );
         getRepo().createState( "extractorState" );
         rule1.updateState( "extractorState" );
         rule1.checkin( "latest" );
-        
+
         rules = iteratorToList( pack.getAssetsWithStatus(getRepo().getState( "extractorState" )) );
         assertEquals(1, rules.size());
         AssetItem rule = (AssetItem) rules.get( 0 );
         assertEquals("new content", rule.getContent());
-        
+
         //get the previous one via state
-        
+
         getRepo().createState( "foobar" );
         rules = iteratorToList( pack.getAssetsWithStatus(getRepo().getState( "foobar" )) );
         assertEquals(1, rules.size());
         AssetItem prior = (AssetItem) rules.get( 0 );
-        
+
         assertFalse("new content".equals( prior.getContent() ));
-        
+
     }
-    
+
     public void testIgnoreState() throws Exception {
         PackageItem pack = getRepo().createPackage( "package testIgnoreState", "foo" );
-        
+
         getRepo().createState( "x" );
         AssetItem rule1 = pack.addAsset( "rule number 1", "yeah man" );
         rule1.updateState( "x" );
         rule1.checkin( "version0" );
-        
-        
+
+
         AssetItem rule2 = pack.addAsset( "rule number 2", "no way" );
         rule2.updateState( "x" );
         rule2.checkin( "version0" );
-        
+
         AssetItem rule3 = pack.addAsset( "rule number 3", "yes way" );
         getRepo().createState( "disabled" );
-        
+
         rule3.updateState( "disabled" );
         rule3.checkin( "version0" );
-        
+
         getRepo().save();
-        
-        
+
+
         Iterator result = pack.getAssetsWithStatus( getRepo().getState( "x" ), getRepo().getState( "disabled" ) );
         List l = iteratorToList( result );
         assertEquals(2, l.size());
     }
-    
+
     public void testDuplicatePackageName() throws Exception {
-        PackageItem pack = getRepo().createPackage( "dupePackageTest", "testing for dupe" );        
+        PackageItem pack = getRepo().createPackage( "dupePackageTest", "testing for dupe" );
         assertNotNull(pack.getName());
-        
+
         try {
             getRepo().createPackage( "dupePackageTest", "this should fail" );
             fail("Should not be able to add a package of the same name.");
         } catch (RulesRepositoryException e) {
             assertNotNull(e.getMessage());
         }
-        
+
     }
-    
+
     public void testPackageInstanceWrongNodeType() throws Exception {
-        PackageItem pack = getRepo().loadDefaultPackage();        
+        PackageItem pack = getRepo().loadDefaultPackage();
         AssetItem rule = pack.addAsset( "packageInstanceWrongNodeType", "" );
-        
+
         try {
             new PackageItem(this.getRepo(), rule.getNode());
             fail("Can't create a package from a rule node.");
         } catch (RulesRepositoryException e) {
             assertNotNull(e.getMessage());
         }
-        
+
     }
-    
-    
+
+
     public void testLoadRulePackageItemByUUID() throws Exception {
 
         PackageItem rulePackageItem = getRepo().createPackage("testLoadRuleRuleItemByUUID", "desc");
@@ -350,8 +350,8 @@
         rulePackageItem = getRepo().loadPackageByUUID(uuid);
         assertNotNull(rulePackageItem);
         assertEquals("testLoadRuleRuleItemByUUID", rulePackageItem.getName());
-        
-        // try loading rule package that was not created 
+
+        // try loading rule package that was not created
         try {
             rulePackageItem = getRepo().loadPackageByUUID("01010101-0101-0101-0101-010101010101");
             fail("Exception not thrown loading rule package that was not created.");
@@ -359,42 +359,42 @@
             // that is OK!
             assertNotNull(e.getMessage());
         }
-    }    
-    
+    }
+
     public void testAddRuleRuleItem() {
             PackageItem rulePackageItem1 = getRepo().createPackage("testAddRuleRuleItem","desc");
 
-            
+
             AssetItem ruleItem1 = rulePackageItem1.addAsset("testAddRuleRuleItem", "test description");
             ruleItem1.updateContent( "test content" );
             ruleItem1.checkin( "updated the rule content" );
-            
+
             Iterator rulesIt = rulePackageItem1.getAssets();
             assertNotNull(rulesIt);
             AssetItem first = (AssetItem) rulesIt.next();
             assertFalse(rulesIt.hasNext());
             assertEquals("testAddRuleRuleItem", first.getName());
-            
-            //test that it is following the head revision                        
+
+            //test that it is following the head revision
             ruleItem1.updateContent("new lhs");
             ruleItem1.checkin( "updated again" );
             rulesIt = rulePackageItem1.getAssets();
             assertNotNull(rulesIt);
-            
+
             List rules = iteratorToList( rulesIt );
             assertEquals(1, rules.size());
             assertEquals("testAddRuleRuleItem", ((AssetItem)rules.get(0)).getName());
             assertEquals("new lhs", ((AssetItem)rules.get(0)).getContent());
-                        
+
             AssetItem ruleItem2 = rulePackageItem1.addAsset("testAddRuleRuleItem2", "test content");
-            
+
             rules = iteratorToList(rulePackageItem1.getAssets());
             assertNotNull(rules);
-            assertEquals(2, rules.size());  
+            assertEquals(2, rules.size());
 
     }
 
-    
+
     List iteratorToList(Iterator it) {
         List list = new ArrayList();
         while(it.hasNext()) {
@@ -408,81 +408,81 @@
 
 
 
-    
+
     public void testGetRules() {
             PackageItem rulePackageItem1 = getRepo().createPackage("testGetRules", "desc");
-                        
+
             AssetItem ruleItem1 = rulePackageItem1.addAsset("testGetRules", "desc" );
             ruleItem1.updateContent( "test lhs content" );
 
-            
+
             assertTrue(rulePackageItem1.containsAsset( "testGetRules" ));
             assertFalse(rulePackageItem1.containsAsset( "XXXXYYYYZZZZ" ));
-            
-            
+
+
             List rules = iteratorToList(rulePackageItem1.getAssets());
             assertNotNull(rules);
             assertEquals(1, rules.size());
             assertEquals("testGetRules", ((AssetItem)rules.get(0)).getName());
-                                  
+
             AssetItem ruleItem2 = rulePackageItem1.addAsset("testGetRules2", "desc" );
             ruleItem2.updateContent( "test lhs content" );
-            
+
             rules = iteratorToList(rulePackageItem1.getAssets());
             assertNotNull(rules);
-            assertEquals(2, rules.size());            
+            assertEquals(2, rules.size());
 
             //now lets test loading rule
             AssetItem loaded = rulePackageItem1.loadAsset( "testGetRules" );
             assertNotNull(loaded);
             assertEquals("testGetRules", loaded.getName());
             assertEquals("desc", loaded.getDescription());
-           
-            
+
+
     }
 
     public void testToString() {
             PackageItem rulePackageItem1 = getRepo().createPackage("testToStringPackage", "desc");
-            
+
             AssetItem ruleItem1 = rulePackageItem1.addAsset("testToStringPackage", "test lhs content" );
             ruleItem1.updateContent( "test lhs content" );
-            
-            assertNotNull(rulePackageItem1.toString());                        
 
+            assertNotNull(rulePackageItem1.toString());
+
     }
-    
+
     public void testRemoveRule() {
             PackageItem rulePackageItem1 = getRepo().createPackage("testRemoveRule", "desc");
-            
+
             AssetItem ruleItem1 = rulePackageItem1.addAsset("testRemoveRule", "test lhs content" );
-            ruleItem1.updateContent( "test lhs content" ); 
-            
-            
-            
+            ruleItem1.updateContent( "test lhs content" );
+
+
+
             Iterator rulesIt = rulePackageItem1.getAssets();
             AssetItem next = (AssetItem) rulesIt.next();
-            
+
             assertFalse(rulesIt.hasNext());
             assertEquals("testRemoveRule", next.getName());
-                               
-            
-            
+
+
+
             ruleItem1.updateContent("new lhs");
             List rules = iteratorToList(rulePackageItem1.getAssets());
             assertNotNull(rules);
             assertEquals(1, rules.size());
             assertEquals("testRemoveRule", ((AssetItem)rules.get(0)).getName());
             assertEquals("new lhs", ((AssetItem)rules.get(0)).getContent());
-                        
+
             AssetItem ruleItem2 = rulePackageItem1.addAsset("testRemoveRule2", "test lhs content");
-            
+
             //remove the rule, make sure the other rule in the pacakge stays around
             rulePackageItem1.removeAsset(ruleItem1.getName());
             rulePackageItem1.rulesRepository.save();
             rules = iteratorToList(rulePackageItem1.getAssets());
             assertEquals(1, rules.size());
             assertEquals("testRemoveRule2", ((AssetItem)rules.get(0)).getName());
-            
+
             //remove the rule that is following the head revision, make sure the pacakge is now empty
             rulePackageItem1.removeAsset(ruleItem2.getName());
             rules = iteratorToList(rulePackageItem1.getAssets());
@@ -490,53 +490,53 @@
             assertEquals(0, rules.size());
 
     }
-        
+
     public void testSearchByFormat() throws Exception {
         PackageItem pkg = getRepo().createPackage( "searchByFormat", "" );
         getRepo().save();
-        
-        
+
+
         AssetItem item = pkg.addAsset( "searchByFormatAsset1", "" );
         item.updateFormat( "xyz" );
         item.checkin( "la" );
-        
+
         item = pkg.addAsset( "searchByFormatAsset2", "wee" );
         item.updateFormat( "xyz" );
         item.checkin( "la" );
-        
+
         item = pkg.addAsset( "searchByFormatAsset3", "wee" );
         item.updateFormat( "ABC" );
         item.checkin( "la" );
-        
+
         Thread.sleep( 150 );
-        
-        AssetItemIterator it = pkg.queryAssets( "drools:format='xyz'" );        
+
+        AssetItemIterator it = pkg.queryAssets( "drools:format='xyz'" );
         List list = iteratorToList( it );
         assertEquals(2, list.size());
         assertTrue(list.get( 0 ) instanceof AssetItem);
         assertTrue(list.get( 1 ) instanceof AssetItem);
 
-        
+
         AssetItemIterator it2 = pkg.listAssetsByFormat( new String[] {"xyz"} );
         List list2 = iteratorToList( it2 );
         assertEquals(2, list2.size());
         assertTrue(list2.get( 0 ) instanceof AssetItem);
         assertTrue(list2.get( 1 ) instanceof AssetItem);
-        
+
         it2 = pkg.listAssetsByFormat( new String[] {"xyz", "ABC"} );
         list2 = iteratorToList( it2 );
         assertEquals(3, list2.size());
         assertTrue(list2.get( 0 ) instanceof AssetItem);
         assertTrue(list2.get( 1 ) instanceof AssetItem);
         assertTrue(list2.get( 2 ) instanceof AssetItem);
-        
+
     }
-    
+
     public void testListArchivedAssets() throws Exception {
         PackageItem pkg = getRepo().createPackage( "org.drools.archivedtest", "" );
         getRepo().save();
-        
-        
+
+
         AssetItem item = pkg.addAsset( "archivedItem1", "" );
         item.archiveItem( true );
         item.checkin( "la" );
@@ -544,55 +544,55 @@
         item = pkg.addAsset( "archivedItem2", "wee" );
         item.archiveItem( true );
         item.checkin( "la" );
-        
+
         item = pkg.addAsset( "archivedItem3", "wee" );
         item.archiveItem( true );
         item.checkin( "la" );
-        
+
         item = pkg.addAsset( "NOTarchivedItem", "wee" );
         item.checkin( "la" );
-        
-        
+
+
         Thread.sleep( 150 );
-        
-        AssetItemIterator it = pkg.listArchivedAssets(); 
-        
+
+        AssetItemIterator it = pkg.listArchivedAssets();
+
         List list = iteratorToList( it );
         assertEquals(3, list.size());
         assertTrue(list.get( 0 ) instanceof AssetItem);
         assertTrue(list.get( 1 ) instanceof AssetItem);
         assertTrue(list.get( 2 ) instanceof AssetItem);
-        
-        
-        it = pkg.queryAssets( "", true ); 
-        
+
+
+        it = pkg.queryAssets( "", true );
+
         list = iteratorToList( it );
         assertEquals(4, list.size());
- 
-        
-    }    
-    
+
+
+    }
+
     public void testSortHistoryByVersionNumber() {
         PackageItem item = new PackageItem();
         List l = new ArrayList();
-        
+
         AssetItem i1 = new MockAssetItem(42);
         AssetItem i2 = new MockAssetItem(1);
-        
+
         l.add( i2 );
         l.add( i1 );
-        
+
         assertEquals(i2, l.iterator().next());
-        
+
         item.sortHistoryByVersionNumber( l );
-        
+
         assertEquals(i1, l.iterator().next());
     }
 
-    
+
     public void testMiscProperties() {
         PackageItem item = getRepo().createPackage( "testHeader", "ya" );
-        
+
         item.updateHeader( "new header" );
         item.updateExternalURI( "boo" );
         getRepo().save();
@@ -600,65 +600,69 @@
         item = getRepo().loadPackage("testHeader");
         assertEquals("new header", item.getHeader());
         assertEquals("boo", item.getExternalURI());
-        
-        
+
+
     }
-    
-    public void testGetFormat() {        
+
+    public void testGetFormatAndUpToDate() {
             PackageItem rulePackageItem1 = getRepo().createPackage("testGetFormat", "woot");
             assertNotNull(rulePackageItem1);
-            assertEquals(PackageItem.PACKAGE_FORMAT, rulePackageItem1.getFormat());    
+            assertEquals(PackageItem.PACKAGE_FORMAT, rulePackageItem1.getFormat());
+            assertFalse(rulePackageItem1.isBinaryUpToDate());
+            rulePackageItem1.updateBinaryUpToDate(true);
+            assertTrue(rulePackageItem1.isBinaryUpToDate());
+            rulePackageItem1.updateBinaryUpToDate(false);
+            assertFalse(rulePackageItem1.isBinaryUpToDate());
+    }
 
-    }
-    
     public void testPackageCheckinConfig() {
         PackageItem item = getRepo().createPackage( "testPackageCheckinConfig", "description" );
-        
+
         AssetItem rule = item.addAsset( "testPackageCheckinConfig", "w" );
         rule.checkin( "goo" );
-        
+
         assertEquals(1, iteratorToList( item.getAssets() ).size());
         item.updateHeader( "la" );
         item.checkin( "woot" );
-        
+
         item.updateHeader( "we" );
         item.checkin( "gah" );
-        
-        
-        
-        
-        
+
+
+
+
+
         PackageItem pre = (PackageItem) item.getPrecedingVersion();
-        assertNotNull(pre);        
+        assertNotNull(pre);
         assertEquals("la", pre.getHeader());
-        
+
         AssetItem rule_ = getRepo().loadAssetByUUID( rule.getUUID() );
         assertEquals(rule.getVersionNumber(), rule_.getVersionNumber());
-        
+
         item = getRepo().loadPackage( "testPackageCheckinConfig");
         long v = item.getVersionNumber();
         item.updateCheckinComment( "x" );
         getRepo().save();
-        
+
         assertEquals(v, item.getVersionNumber());
-        
+
     }
-    
+
     static class MockAssetItem extends AssetItem {
         private long version;
 
         MockAssetItem(long ver) {
-            this.version = ver ; 
+            this.version = ver ;
         }
-        
+
         public long getVersionNumber() {
             return this.version;
         }
-        
+
         public boolean equals(Object in) {
-            return in == this;        
+            return in == this;
         }
-        
+
         public String toString() {
             return Long.toString( this.version );
         }




More information about the jboss-svn-commits mailing list