[jboss-svn-commits] JBL Code SVN: r15075 - in labs/jbossrules/trunk/drools-compiler/src/test: java/org/drools/integrationtests and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Sep 13 02:07:14 EDT 2007


Author: michael.neale at jboss.com
Date: 2007-09-13 02:07:14 -0400 (Thu, 13 Sep 2007)
New Revision: 15075

Modified:
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Cheese.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_mvel.drl
Log:
JBRULES-1189

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Cheese.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Cheese.java	2007-09-13 06:06:37 UTC (rev 15074)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/Cheese.java	2007-09-13 06:07:14 UTC (rev 15075)
@@ -1,16 +1,17 @@
 package org.drools;
 
 import java.io.Serializable;
+import java.util.Date;
 
 /*
  * Copyright 2005 JBoss Inc
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,16 +22,17 @@
 public class Cheese
     implements
     Serializable {
-    
+
     public static final String STILTON = "stilton";
-    
+
     /**
-     * 
+     *
      */
     private static final long serialVersionUID = 400L;
     private String            type;
     private int               price;
     private int               oldPrice;
+    private Date              usedBy;
 
     public Cheese() {
 
@@ -99,7 +101,15 @@
     public void setOldPrice(int oldPrice) {
         this.oldPrice = oldPrice;
     }
-    
-    
 
+    public Date getUsedBy() {
+        return usedBy;
+    }
+
+    public void setUsedBy(Date usedBy) {
+        this.usedBy = usedBy;
+    }
+
+
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java	2007-09-13 06:06:37 UTC (rev 15074)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/MVELTest.java	2007-09-13 06:07:14 UTC (rev 15075)
@@ -8,6 +8,7 @@
 import java.io.Reader;
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 
@@ -18,6 +19,7 @@
 import org.drools.RuleBase;
 import org.drools.RuleBaseFactory;
 import org.drools.WorkingMemory;
+import org.drools.base.evaluators.DateFactory;
 import org.drools.common.DroolsObjectInputStream;
 import org.drools.compiler.DrlParser;
 import org.drools.compiler.DroolsParserException;
@@ -27,48 +29,54 @@
 import org.mvel.MVEL;
 
 public class MVELTest extends TestCase {
-    public void testHelloWorld() throws Exception {                   
+    public void testHelloWorld() throws Exception {
         // read in the source
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_mvel.drl" ) );
         RuleBase ruleBase = loadRuleBase( reader );
-                
+
         // Bellow lines are a way to make sure serialization is fine
         // start of serialization block
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         ObjectOutputStream obj = new ObjectOutputStream( out );
         obj.writeObject( ruleBase );
         obj.close();
-        
+
         byte[] buf = out.toByteArray();
-        
+
         DroolsObjectInputStream in = new DroolsObjectInputStream( new ByteArrayInputStream( buf ) );
         ruleBase = (RuleBase) in.readObject();
-        // end of serialization block        
+        // end of serialization block
 
         final WorkingMemory workingMemory = ruleBase.newStatefulSession();
 
         final List list = new ArrayList();
         workingMemory.setGlobal( "list",
                                  list );
-        
+
         final List list2 = new ArrayList();
         workingMemory.setGlobal( "list2",
-                                 list2 );        
+                                 list2 );
 
-        workingMemory.insert( new Cheese("stilton", 10) );
+
+        Cheese c = new Cheese("stilton", 10) ;
+        workingMemory.insert( c);
         workingMemory.fireAllRules();
         assertEquals( 2, list.size() );
         assertEquals( new Integer(30), list.get(0));
         assertEquals( new Integer(22), list.get(1));
-        
-        assertEquals( "hello world", list2.get(0));        
-        
+
+        assertEquals( "hello world", list2.get(0));
+
+        Date dt = DateFactory.parseDate( "10-Jul-1974" );
+        assertEquals(dt, c.getUsedBy());
+
+
     }
-    
+
     public Object compiledExecute(String ex) {
         Serializable compiled = MVEL.compileExpression(ex);
         return MVEL.executeExpression(compiled, new Object(), new HashMap());
-    }    
+    }
 
     private RuleBase loadRuleBase(final Reader reader) throws IOException,
                                                       DroolsParserException,
@@ -81,9 +89,9 @@
         // pre build the package
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackage( packageDescr );
-        
+
         System.out.println( builder.getErrors() );
-        
+
         final Package pkg = builder.getPackage();
 
         // add the package to a rulebase

Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_mvel.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_mvel.drl	2007-09-13 06:06:37 UTC (rev 15074)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_mvel.drl	2007-09-13 06:07:14 UTC (rev 15075)
@@ -19,10 +19,10 @@
 
         a = new java.math.BigInteger( "10" );
         b = new java.math.BigInteger( "10" );
-        c = a + b; 
+        c = a + b;
         list.add( c + $c.price);
-        
-        modify ( $c ) { price = c }      
+
+        modify ( $c ) { price = c }
 end
 
 
@@ -31,6 +31,7 @@
     when
         $c : Cheese(type == "stilton", price == 20 )
     then
-        list.add( $c.price + 2);   
+        list.add( $c.price + 2);
         list2.add( someFunction() );
+        $c.usedBy = "10-Jul-1974"
 end
\ No newline at end of file




More information about the jboss-svn-commits mailing list