[jboss-svn-commits] JBL Code SVN: r23928 - in labs/jbossrules/trunk/drools-compiler/src: test/java/org/drools/guvnor/modeldriven and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 18 12:15:22 EST 2008
Author: jamesdeanturner
Date: 2008-11-18 12:15:21 -0500 (Tue, 18 Nov 2008)
New Revision: 23928
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/modeldriven/RuleModelTest.java
Log:
added new utility methods for metaData manipulation to RuleModel
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java 2008-11-18 17:12:54 UTC (rev 23927)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java 2008-11-18 17:15:21 UTC (rev 23928)
@@ -182,7 +182,6 @@
final RuleAttribute[] newList = new RuleAttribute[this.attributes.length - 1];
int newIdx = 0;
for ( int i = 0; i < this.attributes.length; i++ ) {
-
if ( i != idx ) {
newList[newIdx] = this.attributes[i];
newIdx++;
@@ -190,21 +189,22 @@
}
this.attributes = newList;
-
}
+ /**
+ * Add metaData
+ * @param metadata
+ */
public void addMetadata(final RuleMetadata metadata) {
- final RuleMetadata[] list = this.metadataList;
- final RuleMetadata[] newList = new RuleMetadata[list.length + 1];
+ final RuleMetadata[] newList = new RuleMetadata[this.metadataList.length + 1];
- for ( int i = 0; i < list.length; i++ ) {
- newList[i] = list[i];
+ for ( int i = 0; i < this.metadataList.length; i++ ) {
+ newList[i] = this.metadataList[i];
}
- newList[list.length] = metadata;
+ newList[this.metadataList.length] = metadata;
this.metadataList = newList;
-
}
public void removeMetadata(final int idx) {
@@ -221,7 +221,45 @@
this.metadataList = newList;
}
+
+ /**
+ * Locate metadata element
+ * @param attributeName - value to look for
+ * @return null if not found
+ */
+ public RuleMetadata getMetaData(String attributeName){
+
+ if (metadataList != null && attributeName != null){
+ for (int i = 0; i < metadataList.length; i++) {
+ if (attributeName.equals(metadataList[i].attributeName)){
+ return metadataList[i];
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Update metaData element if it exists or add it otherwise
+ * @param metadata
+ * @return
+ * true on update of existing element
+ * false on added of element
+ *
+ */
+ public boolean updateMetadata(final RuleMetadata target) {
+ RuleMetadata metaData = getMetaData(target.attributeName);
+ if (metaData != null) {
+ metaData.value = target.value;
+ return true;
+ }
+
+ addMetadata(target);
+ return false;
+ }
+
+
/**
* This uses a deceptively simple algorithm to determine
* what bound variables are in scope for a given constraint (including connectives).
@@ -330,4 +368,5 @@
return false;
}
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/modeldriven/RuleModelTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/modeldriven/RuleModelTest.java 2008-11-18 17:12:54 UTC (rev 23927)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/modeldriven/RuleModelTest.java 2008-11-18 17:15:21 UTC (rev 23928)
@@ -23,391 +23,360 @@
public class RuleModelTest extends TestCase {
- public void testBoundFactFinder() {
- final RuleModel model = new RuleModel();
+ public void testAddItemLhs() {
+ final RuleModel model = new RuleModel();
+ final FactPattern x = new FactPattern();
+ model.addLhsItem(x);
+ assertEquals(1, model.lhs.length);
- assertNull( model.getBoundFact( "x" ) );
- model.lhs = new IPattern[3];
+ final FactPattern y = new FactPattern();
+ model.addLhsItem(y);
- final FactPattern x = new FactPattern( "Car" );
- model.lhs[0] = x;
- x.boundName = "x";
+ assertEquals(2, model.lhs.length);
+ assertEquals(x, model.lhs[0]);
+ assertEquals(y, model.lhs[1]);
- assertNotNull( model.getBoundFact( "x" ) );
- assertEquals( x,
- model.getBoundFact( "x" ) );
+ }
- final FactPattern y = new FactPattern( "Car" );
- model.lhs[1] = y;
- y.boundName = "y";
+ public void testAddItemRhs() {
+ final RuleModel model = new RuleModel();
+ final IAction a0 = new ActionSetField();
+ final IAction a1 = new ActionSetField();
- final FactPattern other = new FactPattern( "House" );
- model.lhs[2] = other;
+ model.addRhsItem(a0);
- assertEquals( y,
- model.getBoundFact( "y" ) );
- assertEquals( x,
- model.getBoundFact( "x" ) );
+ assertEquals(1, model.rhs.length);
+ model.addRhsItem(a1);
- model.rhs = new IAction[1];
- final ActionSetField set = new ActionSetField();
- set.variable = "x";
- model.rhs[0] = set;
+ assertEquals(2, model.rhs.length);
- assertTrue( model.isBoundFactUsed( "x" ) );
- assertFalse( model.isBoundFactUsed( "y" ) );
+ assertEquals(a0, model.rhs[0]);
+ assertEquals(a1, model.rhs[1]);
+ }
- assertEquals( 3,
- model.lhs.length );
- assertFalse( model.removeLhsItem( 0 ) );
- assertEquals( 3,
- model.lhs.length );
+ public void testAllVariableBindings() {
+ final RuleModel model = new RuleModel();
+ model.lhs = new IPattern[2];
+ final FactPattern x = new FactPattern("Car");
+ model.lhs[0] = x;
+ x.boundName = "boundFact";
- final ActionRetractFact fact = new ActionRetractFact( "q" );
- model.rhs[0] = fact;
- assertTrue( model.isBoundFactUsed( "q" ) );
- assertFalse( model.isBoundFactUsed( "x" ) );
+ SingleFieldConstraint sfc = new SingleFieldConstraint("q");
+ x.addConstraint(sfc);
+ sfc.fieldBinding = "field1";
- final XStream xt = new XStream();
- xt.alias( "rule",
- RuleModel.class );
- xt.alias( "fact",
- FactPattern.class );
- xt.alias( "retract",
- ActionRetractFact.class );
+ SingleFieldConstraint sfc2 = new SingleFieldConstraint("q");
+ x.addConstraint(sfc2);
+ sfc2.fieldBinding = "field2";
- final String brl = xt.toXML( model );
+ model.lhs[1] = new CompositeFactPattern();
- System.out.println( brl );
- }
+ List vars = model.getAllVariables();
+ assertEquals(3, vars.size());
+ assertEquals("boundFact", vars.get(0));
+ assertEquals("field1", vars.get(1));
+ assertEquals("field2", vars.get(2));
- public void testScopedVariables() {
+ assertTrue(model.isVariableNameUsed("field2"));
- //setup the data...
+ }
- final RuleModel model = new RuleModel();
- model.lhs = new IPattern[3];
- final FactPattern x = new FactPattern( "Car" );
- model.lhs[0] = x;
- x.boundName = "x";
+ public void testAttributes() {
+ final RuleModel m = new RuleModel();
+ final RuleAttribute at = new RuleAttribute("salience", "42");
+ m.addAttribute(at);
+ assertEquals(1, m.attributes.length);
+ assertEquals(at, m.attributes[0]);
- final FactPattern y = new FactPattern( "Car" );
- model.lhs[1] = y;
- y.boundName = "y";
- final SingleFieldConstraint[] cons = new SingleFieldConstraint[2];
- y.constraintList = new CompositeFieldConstraint();
- y.constraintList.constraints = cons;
- cons[0] = new SingleFieldConstraint( "age" );
- cons[1] = new SingleFieldConstraint( "make" );
- cons[0].fieldBinding = "qbc";
- cons[0].connectives = new ConnectiveConstraint[1];
- cons[0].connectives[0] = new ConnectiveConstraint( "&",
- "x" );
- cons[0].connectives[0].constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+ final RuleAttribute at2 = new RuleAttribute("agenda-group", "x");
+ m.addAttribute(at2);
+ assertEquals(2, m.attributes.length);
+ assertEquals(at2, m.attributes[1]);
- final FactPattern other = new FactPattern( "House" );
- model.lhs[2] = other;
- other.boundName = "q";
- final SingleFieldConstraint[] cons2 = new SingleFieldConstraint[1];
- cons2[0] = new SingleFieldConstraint();
- other.constraintList = new CompositeFieldConstraint();
- other.constraintList.constraints = cons2;
+ m.removeAttribute(0);
+ assertEquals(1, m.attributes.length);
+ assertEquals(at2, m.attributes[0]);
+ }
- //check the results for correct scope
- List vars = model.getBoundVariablesInScope( cons[0] );
- assertEquals( 1,
- vars.size() );
- assertEquals( "x",
- vars.get( 0 ) );
+ public void testBindingList() {
+ final RuleModel model = new RuleModel();
- vars = model.getBoundVariablesInScope( cons[0].connectives[0] );
- assertEquals( 1,
- vars.size() );
- assertEquals( "x",
- vars.get( 0 ) );
+ model.lhs = new IPattern[3];
+ final FactPattern x = new FactPattern("Car");
+ model.lhs[0] = x;
+ x.boundName = "x";
- vars = model.getBoundVariablesInScope( cons[1] );
- assertEquals( 2,
- vars.size() );
- assertEquals( "x",
- vars.get( 0 ) );
- assertEquals( "qbc",
- vars.get( 1 ) );
+ final FactPattern y = new FactPattern("Car");
+ model.lhs[1] = y;
+ y.boundName = "y";
- vars = model.getBoundVariablesInScope( cons[0] );
- assertEquals( 1,
- vars.size() );
- assertEquals( "x",
- vars.get( 0 ) );
+ final FactPattern other = new FactPattern("House");
+ model.lhs[2] = other;
- vars = model.getBoundVariablesInScope( cons2[0] );
- assertEquals( 3,
- vars.size() );
- assertEquals( "x",
- vars.get( 0 ) );
- assertEquals( "qbc",
- vars.get( 1 ) );
- assertEquals( "y",
- vars.get( 2 ) );
- }
-
- public void testScopedVariablesWithCompositeFact() {
- RuleModel m = new RuleModel();
- FactPattern p = new FactPattern();
- CompositeFieldConstraint cf = new CompositeFieldConstraint();
- cf.addConstraint( new SingleFieldConstraint("x") );
- p.addConstraint( cf );
- SingleFieldConstraint sf = new SingleFieldConstraint("q");
- sf.fieldBinding = "abc";
+ final List b = model.getBoundFacts();
+ assertEquals(2, b.size());
- p.addConstraint( sf );
- SingleFieldConstraint sf2 = new SingleFieldConstraint("q");
- sf2.fieldBinding = "qed";
- cf.addConstraint( sf2 );
- m.addLhsItem( p );
+ assertEquals("x", b.get(0));
+ assertEquals("y", b.get(1));
- List vars = m.getAllVariables();
- assertEquals(1, vars.size());
- assertEquals("abc", vars.get( 0 ));
- }
+ }
- public void testBindingList() {
- final RuleModel model = new RuleModel();
+ public void testBoundFactFinder() {
+ final RuleModel model = new RuleModel();
- model.lhs = new IPattern[3];
- final FactPattern x = new FactPattern( "Car" );
- model.lhs[0] = x;
- x.boundName = "x";
+ assertNull(model.getBoundFact("x"));
+ model.lhs = new IPattern[3];
- final FactPattern y = new FactPattern( "Car" );
- model.lhs[1] = y;
- y.boundName = "y";
+ final FactPattern x = new FactPattern("Car");
+ model.lhs[0] = x;
+ x.boundName = "x";
- final FactPattern other = new FactPattern( "House" );
- model.lhs[2] = other;
+ assertNotNull(model.getBoundFact("x"));
+ assertEquals(x, model.getBoundFact("x"));
- final List b = model.getBoundFacts();
- assertEquals( 2,
- b.size() );
+ final FactPattern y = new FactPattern("Car");
+ model.lhs[1] = y;
+ y.boundName = "y";
- assertEquals( "x",
- b.get( 0 ) );
- assertEquals( "y",
- b.get( 1 ) );
+ final FactPattern other = new FactPattern("House");
+ model.lhs[2] = other;
- }
-
- public void testAllVariableBindings() {
- final RuleModel model = new RuleModel();
- model.lhs = new IPattern[2];
- final FactPattern x = new FactPattern( "Car" );
- model.lhs[0] = x;
- x.boundName = "boundFact";
-
- SingleFieldConstraint sfc = new SingleFieldConstraint("q");
- x.addConstraint( sfc );
- sfc.fieldBinding = "field1";
-
- SingleFieldConstraint sfc2 = new SingleFieldConstraint("q");
- x.addConstraint( sfc2 );
- sfc2.fieldBinding = "field2";
-
-
- model.lhs[1] = new CompositeFactPattern();
-
- List vars = model.getAllVariables();
- assertEquals(3, vars.size());
- assertEquals("boundFact", vars.get( 0 ));
- assertEquals("field1", vars.get( 1 ));
- assertEquals("field2", vars.get( 2 ));
-
- assertTrue(model.isVariableNameUsed( "field2" ));
-
- }
-
- public void testGetVariableNameForRHS() {
- RuleModel m = new RuleModel();
- m.name = "blah";
-
- FactPattern pat = new FactPattern();
- pat.boundName = "pat";
- pat.factType = "Person";
-
- m.addLhsItem( pat );
-
- List l = m.getAllVariables();
- assertEquals( 1, l.size() );
- assertEquals("pat", l.get( 0 ));
-
- }
+ assertEquals(y, model.getBoundFact("y"));
+ assertEquals(x, model.getBoundFact("x"));
- public void testRemoveItemLhs() {
- final RuleModel model = new RuleModel();
+ model.rhs = new IAction[1];
+ final ActionSetField set = new ActionSetField();
+ set.variable = "x";
+ model.rhs[0] = set;
- model.lhs = new IPattern[3];
- final FactPattern x = new FactPattern( "Car" );
- model.lhs[0] = x;
- x.boundName = "x";
+ assertTrue(model.isBoundFactUsed("x"));
+ assertFalse(model.isBoundFactUsed("y"));
- final FactPattern y = new FactPattern( "Car" );
- model.lhs[1] = y;
- y.boundName = "y";
+ assertEquals(3, model.lhs.length);
+ assertFalse(model.removeLhsItem(0));
+ assertEquals(3, model.lhs.length);
- final FactPattern other = new FactPattern( "House" );
- model.lhs[2] = other;
+ final ActionRetractFact fact = new ActionRetractFact("q");
+ model.rhs[0] = fact;
+ assertTrue(model.isBoundFactUsed("q"));
+ assertFalse(model.isBoundFactUsed("x"));
- assertEquals( 3,
- model.lhs.length );
- assertEquals( x,
- model.lhs[0] );
+ final XStream xt = new XStream();
+ xt.alias("rule", RuleModel.class);
+ xt.alias("fact", FactPattern.class);
+ xt.alias("retract", ActionRetractFact.class);
- model.removeLhsItem( 0 );
+ final String brl = xt.toXML(model);
- assertEquals( 2,
- model.lhs.length );
- assertEquals( y,
- model.lhs[0] );
- }
+ System.out.println(brl);
+ }
- public void testRemoveItemRhs() {
- final RuleModel model = new RuleModel();
+ public void testGetVariableNameForRHS() {
+ RuleModel m = new RuleModel();
+ m.name = "blah";
- model.rhs = new IAction[3];
- final ActionRetractFact r0 = new ActionRetractFact( "x" );
- final ActionRetractFact r1 = new ActionRetractFact( "y" );
- final ActionRetractFact r2 = new ActionRetractFact( "z" );
+ FactPattern pat = new FactPattern();
+ pat.boundName = "pat";
+ pat.factType = "Person";
- model.rhs[0] = r0;
- model.rhs[1] = r1;
- model.rhs[2] = r2;
+ m.addLhsItem(pat);
- model.removeRhsItem( 1 );
+ List l = m.getAllVariables();
+ assertEquals(1, l.size());
+ assertEquals("pat", l.get(0));
- assertEquals( 2,
- model.rhs.length );
- assertEquals( r0,
- model.rhs[0] );
- assertEquals( r2,
- model.rhs[1] );
- }
+ }
- public void testAddItemLhs() {
- final RuleModel model = new RuleModel();
- final FactPattern x = new FactPattern();
- model.addLhsItem( x );
- assertEquals( 1,
- model.lhs.length );
+ public void testIsDSLEnhanced() throws Exception {
+ RuleModel m = new RuleModel();
- final FactPattern y = new FactPattern();
- model.addLhsItem( y );
+ assertFalse(m.hasDSLSentences());
- assertEquals( 2,
- model.lhs.length );
- assertEquals( x,
- model.lhs[0] );
- assertEquals( y,
- model.lhs[1] );
+ m.addLhsItem(new FactPattern());
+ assertFalse(m.hasDSLSentences());
- }
+ m.addRhsItem(new ActionSetField("q"));
- public void testAddItemRhs() {
- final RuleModel model = new RuleModel();
- final IAction a0 = new ActionSetField();
- final IAction a1 = new ActionSetField();
+ assertFalse(m.hasDSLSentences());
- model.addRhsItem( a0 );
+ m.addLhsItem(new DSLSentence());
+ assertTrue(m.hasDSLSentences());
- assertEquals( 1,
- model.rhs.length );
- model.addRhsItem( a1 );
+ m.addRhsItem(new DSLSentence());
+ assertTrue(m.hasDSLSentences());
- assertEquals( 2,
- model.rhs.length );
+ m = new RuleModel();
- assertEquals( a0,
- model.rhs[0] );
- assertEquals( a1,
- model.rhs[1] );
- }
+ m.addLhsItem(new DSLSentence());
+ assertTrue(m.hasDSLSentences());
- public void testAttributes() {
- final RuleModel m = new RuleModel();
- final RuleAttribute at = new RuleAttribute( "salience",
- "42" );
- m.addAttribute( at );
- assertEquals( 1,
- m.attributes.length );
- assertEquals( at,
- m.attributes[0] );
+ m = new RuleModel();
+ m.addRhsItem(new DSLSentence());
+ assertTrue(m.hasDSLSentences());
- final RuleAttribute at2 = new RuleAttribute( "agenda-group",
- "x" );
- m.addAttribute( at2 );
- assertEquals( 2,
- m.attributes.length );
- assertEquals( at2,
- m.attributes[1] );
+ }
- m.removeAttribute( 0 );
- assertEquals( 1,
- m.attributes.length );
- assertEquals( at2,
- m.attributes[0] );
- }
- public void testMetaData() {
- final RuleModel m = new RuleModel();
- final RuleMetadata rm = new RuleMetadata("foo", "bar");
-
- m.addMetadata(rm);
- assertEquals( 1,
- m.metadataList.length );
- assertEquals( rm ,
- m.metadataList[0] );
-
- final RuleMetadata rm2 = new RuleMetadata("foo2", "bar2");
- m.addMetadata(rm2);
- assertEquals( 2,
- m.metadataList.length );
- assertEquals( rm2 ,
- m.metadataList[1] );
-
- assertEquals("@foo(bar)", rm.toString());
-
- m.removeMetadata( 0 );
- assertEquals( 1,
- m.metadataList.length );
- assertEquals( rm2,
- m.metadataList[0] );
-
- assertEquals("@foo2(bar2)", (m.metadataList[0]).toString());
- }
- public void testIsDSLEnhanced() throws Exception {
- RuleModel m = new RuleModel();
-
- assertFalse(m.hasDSLSentences());
-
- m.addLhsItem( new FactPattern() );
- assertFalse(m.hasDSLSentences());
-
- m.addRhsItem( new ActionSetField("q") );
-
- assertFalse(m.hasDSLSentences());
-
- m.addLhsItem( new DSLSentence() );
- assertTrue(m.hasDSLSentences());
-
- m.addRhsItem( new DSLSentence() );
- assertTrue(m.hasDSLSentences());
-
- m = new RuleModel();
-
- m.addLhsItem( new DSLSentence() );
- assertTrue(m.hasDSLSentences());
-
- m = new RuleModel();
- m.addRhsItem( new DSLSentence() );
- assertTrue(m.hasDSLSentences());
-
- }
+ public void testMetaData() {
+ final RuleModel m = new RuleModel();
+ final RuleMetadata rm = new RuleMetadata("foo", "bar");
+
+ // test add
+ m.addMetadata(rm);
+ assertEquals(1, m.metadataList.length);
+ assertEquals(rm, m.metadataList[0]);
+
+ // should be able to find it
+ RuleMetadata gm = m.getMetaData("foo");
+ assertNotNull(gm);
+
+ // test add and remove
+ final RuleMetadata rm2 = new RuleMetadata("foo2", "bar2");
+ m.addMetadata(rm2);
+ assertEquals(2, m.metadataList.length);
+ assertEquals(rm2, m.metadataList[1]);
+ assertEquals("@foo(bar)", rm.toString());
+
+ m.removeMetadata(0);
+ assertEquals(1, m.metadataList.length);
+ assertEquals(rm2, m.metadataList[0]);
+ assertEquals("@foo2(bar2)", (m.metadataList[0]).toString());
+
+ // should be able to find it now that it was removed
+ gm = m.getMetaData("foo");
+ assertNull(gm);
+
+ // test add via update method
+ m.updateMetadata(rm);
+ gm = m.getMetaData("foo");
+ assertNotNull(gm);
+
+ // test update of existing element
+ rm.value = "bar2";
+ m.updateMetadata(rm);
+ gm = m.getMetaData("foo");
+ assertNotNull(gm);
+ assertEquals("bar2", gm.value);
+
+ }
+
+ public void testRemoveItemLhs() {
+ final RuleModel model = new RuleModel();
+
+ model.lhs = new IPattern[3];
+ final FactPattern x = new FactPattern("Car");
+ model.lhs[0] = x;
+ x.boundName = "x";
+
+ final FactPattern y = new FactPattern("Car");
+ model.lhs[1] = y;
+ y.boundName = "y";
+
+ final FactPattern other = new FactPattern("House");
+ model.lhs[2] = other;
+
+ assertEquals(3, model.lhs.length);
+ assertEquals(x, model.lhs[0]);
+
+ model.removeLhsItem(0);
+
+ assertEquals(2, model.lhs.length);
+ assertEquals(y, model.lhs[0]);
+ }
+
+ public void testRemoveItemRhs() {
+ final RuleModel model = new RuleModel();
+
+ model.rhs = new IAction[3];
+ final ActionRetractFact r0 = new ActionRetractFact("x");
+ final ActionRetractFact r1 = new ActionRetractFact("y");
+ final ActionRetractFact r2 = new ActionRetractFact("z");
+
+ model.rhs[0] = r0;
+ model.rhs[1] = r1;
+ model.rhs[2] = r2;
+
+ model.removeRhsItem(1);
+
+ assertEquals(2, model.rhs.length);
+ assertEquals(r0, model.rhs[0]);
+ assertEquals(r2, model.rhs[1]);
+ }
+
+ public void testScopedVariables() {
+
+ // setup the data...
+
+ final RuleModel model = new RuleModel();
+ model.lhs = new IPattern[3];
+ final FactPattern x = new FactPattern("Car");
+ model.lhs[0] = x;
+ x.boundName = "x";
+
+ final FactPattern y = new FactPattern("Car");
+ model.lhs[1] = y;
+ y.boundName = "y";
+ final SingleFieldConstraint[] cons = new SingleFieldConstraint[2];
+ y.constraintList = new CompositeFieldConstraint();
+ y.constraintList.constraints = cons;
+ cons[0] = new SingleFieldConstraint("age");
+ cons[1] = new SingleFieldConstraint("make");
+ cons[0].fieldBinding = "qbc";
+ cons[0].connectives = new ConnectiveConstraint[1];
+ cons[0].connectives[0] = new ConnectiveConstraint("&", "x");
+ cons[0].connectives[0].constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+
+ final FactPattern other = new FactPattern("House");
+ model.lhs[2] = other;
+ other.boundName = "q";
+ final SingleFieldConstraint[] cons2 = new SingleFieldConstraint[1];
+ cons2[0] = new SingleFieldConstraint();
+ other.constraintList = new CompositeFieldConstraint();
+ other.constraintList.constraints = cons2;
+
+ // check the results for correct scope
+ List vars = model.getBoundVariablesInScope(cons[0]);
+ assertEquals(1, vars.size());
+ assertEquals("x", vars.get(0));
+
+ vars = model.getBoundVariablesInScope(cons[0].connectives[0]);
+ assertEquals(1, vars.size());
+ assertEquals("x", vars.get(0));
+
+ vars = model.getBoundVariablesInScope(cons[1]);
+ assertEquals(2, vars.size());
+ assertEquals("x", vars.get(0));
+ assertEquals("qbc", vars.get(1));
+
+ vars = model.getBoundVariablesInScope(cons[0]);
+ assertEquals(1, vars.size());
+ assertEquals("x", vars.get(0));
+
+ vars = model.getBoundVariablesInScope(cons2[0]);
+ assertEquals(3, vars.size());
+ assertEquals("x", vars.get(0));
+ assertEquals("qbc", vars.get(1));
+ assertEquals("y", vars.get(2));
+ }
+
+ public void testScopedVariablesWithCompositeFact() {
+ RuleModel m = new RuleModel();
+ FactPattern p = new FactPattern();
+ CompositeFieldConstraint cf = new CompositeFieldConstraint();
+ cf.addConstraint(new SingleFieldConstraint("x"));
+ p.addConstraint(cf);
+ SingleFieldConstraint sf = new SingleFieldConstraint("q");
+ sf.fieldBinding = "abc";
+
+ p.addConstraint(sf);
+ SingleFieldConstraint sf2 = new SingleFieldConstraint("q");
+ sf2.fieldBinding = "qed";
+ cf.addConstraint(sf2);
+ m.addLhsItem(p);
+
+ List vars = m.getAllVariables();
+ assertEquals(1, vars.size());
+ assertEquals("abc", vars.get(0));
+ }
+
}
More information about the jboss-svn-commits
mailing list