[jboss-svn-commits] JBL Code SVN: r14965 - labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Sep 9 10:20:33 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-09-09 10:20:33 -0400 (Sun, 09 Sep 2007)
New Revision: 14965
Modified:
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
Log:
JBRULES-1153 Accumulate/Collect can't be used in queries
-Added test for isAllowedMemoryOverride.
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java 2007-09-09 14:17:49 UTC (rev 14964)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java 2007-09-09 14:20:33 UTC (rev 14965)
@@ -143,7 +143,69 @@
assertTrue( "Should contain 'cheddar handle'",
memory.contains( f0 ) );
}
+
+ public void testIsMemoryAllowedOverride() throws Exception {
+ RuleBaseConfiguration config = new RuleBaseConfiguration();
+ config.setAlphaMemory( true );
+ ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase( config );
+ BuildContext buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+ ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+
+ final Rule rule = new Rule( "test-rule" );
+ final PropagationContext context = new PropagationContextImpl( 0,
+ PropagationContext.ASSERTION,
+ null,
+ null );
+ final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
+
+ final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
+ "type",
+ getClass().getClassLoader() );
+
+ final FieldValue field = FieldFactory.getFieldValue( "cheddar" );
+
+ final Evaluator evaluator = ValueType.OBJECT_TYPE.getEvaluator( Operator.EQUAL );
+ final LiteralConstraint constraint = new LiteralConstraint( extractor,
+ evaluator,
+ field );
+
+ // With Memory
+ buildContext.setAlphaNodeMemoryAllowed( false );
+ final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
+ constraint,
+ source,
+ buildContext ); // has memory
+
+ final MockObjectSink sink = new MockObjectSink();
+ alphaNode.addObjectSink( sink );
+
+ final Cheese cheddar = new Cheese( "cheddar",
+ 5 );
+ final DefaultFactHandle f0 = (DefaultFactHandle) workingMemory.insert( cheddar );
+
+ // check sink is empty
+ assertLength( 0,
+ sink.getAsserted() );
+
+ // check alpha memory is empty
+ final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( alphaNode );
+
+ assertEquals( 0,
+ memory.size() );
+
+ // object should assert as it passes text
+ alphaNode.assertObject( f0,
+ context,
+ workingMemory );
+
+ assertEquals( 1,
+ sink.getAsserted().size() );
+ // memory should be one, as even though isAlphaMemory is on for the configuration, the build never allows memory
+ assertEquals( 0,
+ memory.size() );
+ }
+
public void testLiteralConstraintAssertObjectWithoutMemory() throws Exception {
RuleBaseConfiguration config = new RuleBaseConfiguration();
config.setAlphaMemory( false );
More information about the jboss-svn-commits
mailing list