[jboss-svn-commits] JBL Code SVN: r33291 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools/util and 7 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jun 1 16:58:07 EDT 2010
Author: tirelli
Date: 2010-06-01 16:58:06 -0400 (Tue, 01 Jun 2010)
New Revision: 33291
Added:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/util/IsTuple.java
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_BeforeOperator.drl
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_MetByOperator.drl
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/IsTuple.java
Modified:
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/time/TemporalDependencyMatrix.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/builder/BuildUtilsTest.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java
Log:
JBRULES-2531: fixed event expiration calculation
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 2010-06-01 20:00:00 UTC (rev 33290)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/CepEspTest.java 2010-06-01 20:58:06 UTC (rev 33291)
@@ -1,5 +1,11 @@
package org.drools.integrationtests;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -7,11 +13,9 @@
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
-import junit.framework.Assert;
import junit.framework.TestCase;
import org.drools.ClockType;
@@ -41,6 +45,9 @@
import org.drools.core.util.DroolsStreamUtils;
import org.drools.definition.KnowledgePackage;
import org.drools.definitions.impl.KnowledgePackageImp;
+import org.drools.event.rule.ActivationCreatedEvent;
+import org.drools.event.rule.AfterActivationFiredEvent;
+import org.drools.event.rule.AgendaEventListener;
import org.drools.impl.StatefulKnowledgeSessionImpl;
import org.drools.io.ResourceFactory;
import org.drools.lang.descr.PackageDescr;
@@ -49,10 +56,12 @@
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.conf.ClockTypeOption;
+import org.drools.runtime.rule.Activation;
import org.drools.runtime.rule.FactHandle;
import org.drools.time.SessionPseudoClock;
import org.drools.time.impl.DurationTimer;
import org.drools.time.impl.PseudoClockScheduler;
+import org.mockito.ArgumentCaptor;
public class CepEspTest extends TestCase {
protected RuleBase getRuleBase() throws Exception {
@@ -83,7 +92,7 @@
final PackageDescr packageDescr = parser.parse( reader );
if ( parser.hasErrors() ) {
System.out.println( parser.getErrors() );
- Assert.fail( "Error messages in parser, need to sort this our (or else collect error messages)" );
+ fail( "Error messages in parser, need to sort this our (or else collect error messages)" );
}
// pre build the package
builder.addPackage( packageDescr );
@@ -97,6 +106,22 @@
return ruleBase;
}
+ private KnowledgeBase loadKnowledgeBase(final Reader reader,
+ final KnowledgeBaseConfiguration conf) throws IOException,
+ ClassNotFoundException {
+ final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
+ kbuilder.add( ResourceFactory.newReaderResource( reader ),
+ ResourceType.DRL );
+ assertFalse( kbuilder.getErrors().toString(),
+ kbuilder.hasErrors() );
+
+ // add the packages to a rulebase
+ KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( conf );
+ kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+ kbase = SerializationHelper.serializeObject( kbase );
+ return kbase;
+ }
+
public void testEventAssertion() throws Exception {
// read in the source
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
@@ -602,6 +627,185 @@
}
+ public void testBeforeOperator() throws Exception {
+ // read in the source
+ final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_CEP_BeforeOperator.drl" ) );
+ final KnowledgeBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( EventProcessingOption.STREAM );
+ final KnowledgeBase kbase = loadKnowledgeBase( reader,
+ kconf );
+
+ KnowledgeSessionConfiguration sconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
+ sconf.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) );
+ StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession( sconf,
+ null );
+
+ final PseudoClockScheduler clock = (PseudoClockScheduler) ksession.getSessionClock();
+ clock.setStartupTime( 1000 );
+
+ AgendaEventListener ael = mock( AgendaEventListener.class );
+ ksession.addEventListener( ael );
+
+ StockTick tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ System.currentTimeMillis(),
+ 3 );
+ StockTick tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTick tick3 = new StockTick( 3,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTick tick4 = new StockTick( 4,
+ "DROO",
+ 50,
+ System.currentTimeMillis(),
+ 5 );
+ StockTick tick5 = new StockTick( 5,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 5 );
+ StockTick tick6 = new StockTick( 6,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTick tick7 = new StockTick( 7,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 5 );
+ StockTick tick8 = new StockTick( 8,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+
+ ksession.insert( tick1 );
+ clock.advanceTime( 4,
+ TimeUnit.MILLISECONDS );
+ ksession.insert( tick2 );
+ clock.advanceTime( 4,
+ TimeUnit.MILLISECONDS );
+ ksession.insert( tick3 );
+ clock.advanceTime( 4,
+ TimeUnit.MILLISECONDS );
+ ksession.insert( tick4 );
+ ksession.insert( tick5 );
+ clock.advanceTime( 1,
+ TimeUnit.MILLISECONDS );
+ ksession.insert( tick6 );
+ ksession.insert( tick7 );
+ clock.advanceTime( 2,
+ TimeUnit.MILLISECONDS );
+ ksession.insert( tick8 );
+
+ ArgumentCaptor<ActivationCreatedEvent> arg = ArgumentCaptor.forClass( ActivationCreatedEvent.class );
+ verify( ael ).activationCreated( arg.capture() );
+ assertThat( arg.getValue().getActivation().getRule().getName(), is( "before" ) );
+
+ ksession.fireAllRules();
+
+ verify( ael ).afterActivationFired( any( AfterActivationFiredEvent.class ) );
+ }
+
+ public void testMetByOperator() throws Exception {
+ // read in the source
+ final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_CEP_MetByOperator.drl" ) );
+ final KnowledgeBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kconf.setOption( EventProcessingOption.STREAM );
+ final KnowledgeBase kbase = loadKnowledgeBase( reader,
+ kconf );
+
+ KnowledgeSessionConfiguration sconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
+ sconf.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) );
+ StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession( sconf,
+ null );
+
+ final PseudoClockScheduler clock = (PseudoClockScheduler) ksession.getSessionClock();
+ clock.setStartupTime( 1000 );
+
+ AgendaEventListener ael = mock( AgendaEventListener.class );
+ ksession.addEventListener( ael );
+
+ StockTick tick1 = new StockTick( 1,
+ "DROO",
+ 50,
+ System.currentTimeMillis(),
+ 3 );
+ StockTick tick2 = new StockTick( 2,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTick tick3 = new StockTick( 3,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTick tick4 = new StockTick( 4,
+ "DROO",
+ 50,
+ System.currentTimeMillis(),
+ 5 );
+ StockTick tick5 = new StockTick( 5,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 5 );
+ StockTick tick6 = new StockTick( 6,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+ StockTick tick7 = new StockTick( 7,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 5 );
+ StockTick tick8 = new StockTick( 8,
+ "ACME",
+ 10,
+ System.currentTimeMillis(),
+ 3 );
+
+ InternalFactHandle fh1 = (InternalFactHandle) ksession.insert( tick1 );
+ clock.advanceTime( 4,
+ TimeUnit.MILLISECONDS );
+ InternalFactHandle fh2 = (InternalFactHandle) ksession.insert( tick2 );
+ clock.advanceTime( 4,
+ TimeUnit.MILLISECONDS );
+ ksession.insert( tick3 );
+ clock.advanceTime( 4,
+ TimeUnit.MILLISECONDS );
+ ksession.insert( tick4 );
+ ksession.insert( tick5 );
+ clock.advanceTime( 1,
+ TimeUnit.MILLISECONDS );
+ ksession.insert( tick6 );
+ ksession.insert( tick7 );
+ clock.advanceTime( 2,
+ TimeUnit.MILLISECONDS );
+ ksession.insert( tick8 );
+
+ ArgumentCaptor<ActivationCreatedEvent> arg = ArgumentCaptor.forClass( ActivationCreatedEvent.class );
+ verify( ael ).activationCreated( arg.capture() );
+ Activation activation = arg.getValue().getActivation();
+ assertThat( activation.getRule().getName(), is( "metby" ) );
+
+ ksession.fireAllRules();
+
+ ArgumentCaptor<AfterActivationFiredEvent> aaf = ArgumentCaptor.forClass( AfterActivationFiredEvent.class );
+ verify( ael ).afterActivationFired( aaf.capture() );
+ assertThat( (InternalFactHandle) aaf.getValue().getActivation().getFactHandles().toArray()[0], is( fh2 ));
+ }
+
public void testAfterOnArbitraryDates() throws Exception {
// read in the source
final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_CEP_AfterOperatorDates.drl" ) );
@@ -1004,11 +1208,13 @@
clock.advanceTime( 10,
TimeUnit.SECONDS );
+
+ StockTick st1O = new StockTick( 1,
+ "DROO",
+ 100,
+ clock.getCurrentTime() );
- EventFactHandle st1 = (EventFactHandle) wm.insert( new StockTick( 1,
- "DROO",
- 100,
- clock.getCurrentTime() ) );
+ EventFactHandle st1 = (EventFactHandle) wm.insert( st1O );
wm.fireAllRules();
@@ -1041,7 +1247,7 @@
assertEquals( 1,
results.size() );
- assertEquals( st1.getObject(),
+ assertEquals( st1O,
results.get( 0 ) );
}
@@ -1416,11 +1622,11 @@
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase( config );
knowledgeBase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession( sessionConfig,
- KnowledgeBaseFactory.newEnvironment() );
+ KnowledgeBaseFactory.newEnvironment() );
PseudoClockScheduler pseudoClock = ksession.getSessionClock();
-
- FactHandle h = ksession.insert(new A());
- ksession.retract(h);
+
+ FactHandle h = ksession.insert( new A() );
+ ksession.retract( h );
}
public static class A
Added: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/util/IsTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/util/IsTuple.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/util/IsTuple.java 2010-06-01 20:58:06 UTC (rev 33291)
@@ -0,0 +1,51 @@
+/**
+ *
+ */
+package org.drools.util;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.drools.common.InternalFactHandle;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Factory;
+import org.hamcrest.Matcher;
+
+public class IsTuple extends BaseMatcher<List<InternalFactHandle>> {
+ private final InternalFactHandle[] expected;
+
+ public IsTuple(List<InternalFactHandle> tupleAsList) {
+ expected = tupleAsList.toArray( new InternalFactHandle[tupleAsList.size()] );
+ }
+
+ public IsTuple(InternalFactHandle[] tuple) {
+ expected = tuple;
+ }
+
+ public boolean matches(Object arg) {
+ if( arg == null || ! ( arg.getClass().isArray() && InternalFactHandle.class.isAssignableFrom( arg.getClass().getComponentType() ) ) ) {
+ return false;
+ }
+ InternalFactHandle[] actual = (InternalFactHandle[]) arg;
+ return Arrays.equals( expected, actual );
+ }
+
+ public void describeTo(Description description) {
+ description.appendValue(expected);
+ }
+
+ /**
+ * Is the value equal to another value, as tested by the
+ * {@link java.lang.Object#equals} invokedMethod?
+ */
+ @Factory
+ public static Matcher<List<InternalFactHandle>> isTuple(List<InternalFactHandle> operand) {
+ return new IsTuple(operand);
+ }
+
+ public static Matcher<? super List<InternalFactHandle>> isTuple(InternalFactHandle... operands) {
+ return new IsTuple(operands);
+ }
+
+}
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/util/IsTuple.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_BeforeOperator.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_BeforeOperator.drl (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_BeforeOperator.drl 2010-06-01 20:58:06 UTC (rev 33291)
@@ -0,0 +1,15 @@
+package org.drools;
+
+declare StockTick
+ @role( event )
+ @duration( duration )
+end
+
+rule "before"
+when
+ $a : StockTick( company == "DROO" )
+ $b : StockTick( company == "ACME", this before[5,8] $a )
+then
+ // no-op
+end
+
Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_MetByOperator.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_MetByOperator.drl (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_CEP_MetByOperator.drl 2010-06-01 20:58:06 UTC (rev 33291)
@@ -0,0 +1,15 @@
+package org.drools;
+
+declare StockTick
+ @role( event )
+ @duration( duration )
+end
+
+rule "metby"
+when
+ $a : StockTick( company == "DROO" )
+ $b : StockTick( company == "ACME", this metby[1] $a )
+then
+ // no-op
+end
+
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2010-06-01 20:00:00 UTC (rev 33290)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2010-06-01 20:58:06 UTC (rev 33291)
@@ -193,7 +193,7 @@
workingMemory );
}
- if ( this.expirationOffset >= 0 ) {
+ if ( this.expirationOffset >= 0 && this.expirationOffset != Long.MAX_VALUE ) {
// schedule expiration
WorkingMemoryReteExpireAction expire = new WorkingMemoryReteExpireAction( factHandle,
this );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java 2010-06-01 20:00:00 UTC (rev 33290)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildUtils.java 2010-06-01 20:58:06 UTC (rev 33291)
@@ -303,10 +303,10 @@
for ( Map.Entry<Declaration, Interval> entry : temporal.entrySet() ) {
int targetIndex = declarations.indexOf( entry.getKey() );
Interval interval = entry.getValue();
- // FIXME: should it always be intersection or sometimes it would be union?????
source[targetIndex][eventIndex].intersect( interval );
- source[eventIndex][targetIndex].intersect( new Interval( -interval.getUpperBound(),
- -interval.getLowerBound() ) );
+ Interval reverse = new Interval( interval.getUpperBound() == Long.MAX_VALUE ? Long.MIN_VALUE : -interval.getUpperBound(),
+ interval.getLowerBound() == Long.MIN_VALUE ? Long.MAX_VALUE : -interval.getLowerBound() );
+ source[eventIndex][targetIndex].intersect( reverse );
}
eventIndex++;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java 2010-06-01 20:00:00 UTC (rev 33290)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java 2010-06-01 20:58:06 UTC (rev 33291)
@@ -269,7 +269,11 @@
expirationOffset );
}
}
- return expirationOffset;
+ // if none of the type declarations have an @expires annotation
+ // we return -1 (no-expiration) value, otherwise we return the
+ // set expiration value+1 to enable the fact to match events with
+ // the same timestamp
+ return expirationOffset == -1 ? -1 : expirationOffset+1;
}
public void attachAlphaNodes(final BuildContext context,
@@ -313,9 +317,12 @@
}
}
long distance = context.getTemporalDistance().getExpirationOffset( pattern );
- if( distance == Long.MAX_VALUE ) {
- // it means the rules have no closed temporal constraints,
- // so use whatever is set for the OTN or on temporal behaviors
+ if( distance == -1 ) {
+ // it means the rules have no temporal constraints, or
+ // the constraints require events to be hold forever. In this
+ // case, we allow type declarations to override the implicit
+ // expiration offset by defining an expiration policy with the
+ // @expires tag
otn.setExpirationOffset( expirationOffset );
} else {
otn.setExpirationOffset( Math.max( distance, expirationOffset ) );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java 2010-06-01 20:00:00 UTC (rev 33290)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/TypeDeclaration.java 2010-06-01 20:58:06 UTC (rev 33291)
@@ -97,7 +97,7 @@
private boolean dynamic;
private transient ObjectType objectType;
- private long expirationOffset;
+ private long expirationOffset = -1;
public TypeDeclaration() {
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/time/TemporalDependencyMatrix.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/time/TemporalDependencyMatrix.java 2010-06-01 20:00:00 UTC (rev 33290)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/time/TemporalDependencyMatrix.java 2010-06-01 20:58:06 UTC (rev 33291)
@@ -60,6 +60,14 @@
for( Interval interval : matrix[index] ) {
expiration = Math.max( expiration, interval.getUpperBound() );
}
+ if( expiration == 0 ) {
+ // no useful info based on the temporal distance calculation, so return -1
+ expiration = -1;
+ } else if( expiration != Long.MAX_VALUE ) {
+ // else, account for the actual expiration by adding one to whatever interval upper bound was found
+ expiration += 1;
+ } // otherwise, it means we must keep the infinite expiration offset
+
return expiration;
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/builder/BuildUtilsTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/builder/BuildUtilsTest.java 2010-06-01 20:00:00 UTC (rev 33290)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/builder/BuildUtilsTest.java 2010-06-01 20:58:06 UTC (rev 33291)
@@ -113,9 +113,9 @@
//printMatrix( matrix.getMatrix() );
assertEqualsMatrix( expected, matrix.getMatrix() );
- assertEquals( 14, matrix.getExpirationOffset( a ) );
- assertEquals( 10, matrix.getExpirationOffset( d ) );
- assertEquals( 0, matrix.getExpirationOffset( e ) );
+ assertEquals( 15, matrix.getExpirationOffset( a ) );
+ assertEquals( 11, matrix.getExpirationOffset( d ) );
+ assertEquals( -1, matrix.getExpirationOffset( e ) );
}
Added: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/IsTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/IsTuple.java (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/IsTuple.java 2010-06-01 20:58:06 UTC (rev 33291)
@@ -0,0 +1,51 @@
+/**
+ *
+ */
+package org.drools.reteoo.test.dsl;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.drools.common.InternalFactHandle;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Factory;
+import org.hamcrest.Matcher;
+
+public class IsTuple extends BaseMatcher<List<InternalFactHandle>> {
+ private final InternalFactHandle[] expected;
+
+ public IsTuple(List<InternalFactHandle> tupleAsList) {
+ expected = tupleAsList.toArray( new InternalFactHandle[tupleAsList.size()] );
+ }
+
+ public IsTuple(InternalFactHandle[] tuple) {
+ expected = tuple;
+ }
+
+ public boolean matches(Object arg) {
+ if( arg == null || ! ( arg.getClass().isArray() && InternalFactHandle.class.isAssignableFrom( arg.getClass().getComponentType() ) ) ) {
+ return false;
+ }
+ InternalFactHandle[] actual = (InternalFactHandle[]) arg;
+ return Arrays.equals( expected, actual );
+ }
+
+ public void describeTo(Description description) {
+ description.appendValue(expected);
+ }
+
+ /**
+ * Is the value equal to another value, as tested by the
+ * {@link java.lang.Object#equals} invokedMethod?
+ */
+ @Factory
+ public static Matcher<List<InternalFactHandle>> isTuple(List<InternalFactHandle> operand) {
+ return new IsTuple(operand);
+ }
+
+ public static Matcher<? super List<InternalFactHandle>> isTuple(InternalFactHandle... operands) {
+ return new IsTuple(operands);
+ }
+
+}
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/IsTuple.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java 2010-06-01 20:00:00 UTC (rev 33290)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/test/dsl/MockitoHelper.java 2010-06-01 20:58:06 UTC (rev 33291)
@@ -24,11 +24,7 @@
import org.drools.reteoo.RightTupleSink;
import org.drools.reteoo.Sink;
import org.drools.spi.PropagationContext;
-import org.hamcrest.BaseMatcher;
import org.hamcrest.CoreMatchers;
-import org.hamcrest.Description;
-import org.hamcrest.Factory;
-import org.hamcrest.Matcher;
import org.junit.Assert;
import org.junit.matchers.JUnitMatchers;
import org.mockito.ArgumentCaptor;
@@ -318,35 +314,5 @@
}
}
}
-
- public static class IsTuple extends BaseMatcher<List<InternalFactHandle>> {
- private final InternalFactHandle[] expected;
- public IsTuple(List<InternalFactHandle> tupleAsList) {
- expected = tupleAsList.toArray( new InternalFactHandle[tupleAsList.size()] );
- }
-
- public boolean matches(Object arg) {
- if( arg == null || ! ( arg.getClass().isArray() && InternalFactHandle.class.isAssignableFrom( arg.getClass().getComponentType() ) ) ) {
- return false;
- }
- InternalFactHandle[] actual = (InternalFactHandle[]) arg;
- return Arrays.equals( expected, actual );
- }
-
- public void describeTo(Description description) {
- description.appendValue(expected);
- }
-
- /**
- * Is the value equal to another value, as tested by the
- * {@link java.lang.Object#equals} invokedMethod?
- */
- @Factory
- public static Matcher<List<InternalFactHandle>> isTuple(List<InternalFactHandle> operand) {
- return new IsTuple(operand);
- }
-
- }
-
}
More information about the jboss-svn-commits
mailing list