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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Nov 18 16:07:40 EST 2008


Author: tirelli
Date: 2008-11-18 16:07:40 -0500 (Tue, 18 Nov 2008)
New Revision: 23929

Added:
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_SimpleEventAssertionWithDateTimestamp.drl
Modified:
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTick.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/extractors/BaseObjectClassFieldReader.java
Log:
JBRULES-1853: fixing timestamp extraction when field is a java.util.Date field

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTick.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTick.java	2008-11-18 17:15:21 UTC (rev 23928)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/StockTick.java	2008-11-18 21:07:40 UTC (rev 23929)
@@ -1,6 +1,7 @@
 package org.drools;
 
 import java.io.Serializable;
+import java.util.Date;
 
 public class StockTick implements Serializable {
     private long seq;
@@ -78,5 +79,10 @@
     public void setDuration(long duration) {
         this.duration = duration;
     }
+    
+    public Date getDateTimestamp() {
+        return new Date( this.time );
+    }
+    
 
 }

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java	2008-11-18 17:15:21 UTC (rev 23928)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java	2008-11-18 21:07:40 UTC (rev 23929)
@@ -207,6 +207,77 @@
 
     }
 
+    public void testEventAssertionWithDateTimestamp() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_CEP_SimpleEventAssertionWithDateTimestamp.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        SessionConfiguration conf = new SessionConfiguration();
+        conf.setClockType( ClockType.PSEUDO_CLOCK );
+        StatefulSession wm = ruleBase.newStatefulSession( conf );
+
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        StockTick tick1 = new StockTick( 1,
+                                         "DROO",
+                                         50,
+                                         10000,
+                                         5 );
+        StockTick tick2 = new StockTick( 2,
+                                         "ACME",
+                                         10,
+                                         11000,
+                                         10 );
+        StockTick tick3 = new StockTick( 3,
+                                         "ACME",
+                                         10,
+                                         12000,
+                                         8 );
+        StockTick tick4 = new StockTick( 4,
+                                         "DROO",
+                                         50,
+                                         13000,
+                                         7 );
+
+        InternalFactHandle handle1 = (InternalFactHandle) wm.insert( tick1 );
+        InternalFactHandle handle2 = (InternalFactHandle) wm.insert( tick2 );
+        InternalFactHandle handle3 = (InternalFactHandle) wm.insert( tick3 );
+        InternalFactHandle handle4 = (InternalFactHandle) wm.insert( tick4 );
+
+        assertNotNull( handle1 );
+        assertNotNull( handle2 );
+        assertNotNull( handle3 );
+        assertNotNull( handle4 );
+
+        assertTrue( handle1.isEvent() );
+        assertTrue( handle2.isEvent() );
+        assertTrue( handle3.isEvent() );
+        assertTrue( handle4.isEvent() );
+
+        EventFactHandle eh1 = (EventFactHandle) handle1;
+        EventFactHandle eh2 = (EventFactHandle) handle2;
+        EventFactHandle eh3 = (EventFactHandle) handle3;
+        EventFactHandle eh4 = (EventFactHandle) handle4;
+
+        assertEquals( tick1.getTime(),
+                      eh1.getStartTimestamp() );
+        assertEquals( tick2.getTime(),
+                      eh2.getStartTimestamp() );
+        assertEquals( tick3.getTime(),
+                      eh3.getStartTimestamp() );
+        assertEquals( tick4.getTime(),
+                      eh4.getStartTimestamp() );
+
+        wm.fireAllRules();
+
+        assertEquals( 2,
+                      results.size() );
+
+    }
+
     public void testTimeRelationalOperators() throws Exception {
         // read in the source
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_CEP_TimeRelationalOperators.drl" ) );

Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_SimpleEventAssertionWithDateTimestamp.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_SimpleEventAssertionWithDateTimestamp.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_SimpleEventAssertionWithDateTimestamp.drl	2008-11-18 21:07:40 UTC (rev 23929)
@@ -0,0 +1,17 @@
+package org.drools;
+
+import org.drools.StockTick;
+
+global java.util.List results;
+
+declare StockTick 
+    @role( event )
+    @timestamp( dateTimestamp )
+end
+
+rule "Check event"
+when
+    $st : StockTick( company == "ACME" )
+then
+    results.add( $st );
+end

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/extractors/BaseObjectClassFieldReader.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/extractors/BaseObjectClassFieldReader.java	2008-11-18 17:15:21 UTC (rev 23928)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/extractors/BaseObjectClassFieldReader.java	2008-11-18 21:07:40 UTC (rev 23929)
@@ -1,6 +1,7 @@
 package org.drools.base.extractors;
 
 import java.lang.reflect.Method;
+import java.util.Date;
 
 import org.drools.RuntimeDroolsException;
 import org.drools.base.BaseClassFieldReader;
@@ -49,6 +50,8 @@
 
         if ( value instanceof Number ) {
             return ((Number) value).byteValue();
+        } else if( value instanceof Date ) {
+            return (byte) ((Date) value).getTime();
         }
         throw new RuntimeDroolsException( "Conversion to byte not supported from " + value.getClass().getName() );
     }
@@ -73,6 +76,8 @@
 
         if ( value instanceof Number ) {
             return ((Number) value).doubleValue();
+        } else if( value instanceof Date ) {
+            return (double) ((Date) value).getTime();
         }
         throw new RuntimeDroolsException( "Conversion to double not supported from " + value.getClass().getName() );
     }
@@ -84,6 +89,8 @@
 
         if ( value instanceof Number ) {
             return ((Number) value).floatValue();
+        } else if( value instanceof Date ) {
+            return (float) ((Date) value).getTime();
         }
         throw new RuntimeDroolsException( "Conversion to float not supported from " + value.getClass().getName() );
     }
@@ -95,6 +102,8 @@
 
         if ( value instanceof Number ) {
             return ((Number) value).intValue();
+        } else if( value instanceof Date ) {
+            return (int) ((Date) value).getTime();
         }
         throw new RuntimeDroolsException( "Conversion to int not supported from " + value.getClass().getName() );
     }
@@ -106,6 +115,8 @@
 
         if ( value instanceof Number ) {
             return ((Number) value).longValue();
+        } else if( value instanceof Date ) {
+            return ((Date) value).getTime();
         }
         throw new RuntimeDroolsException( "Conversion to long not supported from " + value.getClass().getName() );
     }
@@ -117,6 +128,8 @@
 
         if ( value instanceof Number ) {
             return ((Number) value).shortValue();
+        } else if( value instanceof Date ) {
+            return (short) ((Date) value).getTime();
         }
         throw new RuntimeDroolsException( "Conversion to short not supported from " + value.getClass().getName() );
     }




More information about the jboss-svn-commits mailing list