[jboss-svn-commits] JBL Code SVN: r11895 - in labs/jbossrules/trunk/experimental/drools-testing: src/org/drools/testing/core/engine and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed May 16 09:16:22 EDT 2007
Author: mshaw
Date: 2007-05-16 09:16:21 -0400 (Wed, 16 May 2007)
New Revision: 11895
Modified:
labs/jbossrules/trunk/experimental/drools-testing/pom.xml
labs/jbossrules/trunk/experimental/drools-testing/src/org/drools/testing/core/engine/TestRunner.java
Log:
Modified: labs/jbossrules/trunk/experimental/drools-testing/pom.xml
===================================================================
--- labs/jbossrules/trunk/experimental/drools-testing/pom.xml 2007-05-16 13:03:21 UTC (rev 11894)
+++ labs/jbossrules/trunk/experimental/drools-testing/pom.xml 2007-05-16 13:16:21 UTC (rev 11895)
@@ -118,5 +118,10 @@
<artifactId>eclipse</artifactId>
<version>3.2.0.666</version>
</dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.7.0</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: labs/jbossrules/trunk/experimental/drools-testing/src/org/drools/testing/core/engine/TestRunner.java
===================================================================
--- labs/jbossrules/trunk/experimental/drools-testing/src/org/drools/testing/core/engine/TestRunner.java 2007-05-16 13:03:21 UTC (rev 11894)
+++ labs/jbossrules/trunk/experimental/drools-testing/src/org/drools/testing/core/engine/TestRunner.java 2007-05-16 13:16:21 UTC (rev 11895)
@@ -1,6 +1,6 @@
package org.drools.testing.core.engine;
-import org.codehaus.plexus.util.PropertyUtils;
+import org.apache.commons.beanutils.PropertyUtils;
import org.drools.WorkingMemory;
import org.drools.rule.Package;
import org.drools.testing.core.exception.RuleTestLanguageException;
@@ -78,10 +78,23 @@
// create the working memory
WorkingMemory wm = RuleBaseWrapper.getInstance().getRuleBase().newWorkingMemory(true);
+ parseFacts(scenario.getFacts(), wm);
- // assert the facts
- for (int i=0; i<scenario.getFacts().length; i++) {
- Fact factDefn = scenario.getFacts()[i];
+ }
+
+ /**
+ * iterator over the array of facts assigning required fields
+ * then assert them into the working memory
+ *
+ * @param facts
+ * @param wm
+ * @throws RuleTestLanguageException
+ */
+ private void parseFacts (Fact[] facts, WorkingMemory wm) throws RuleTestLanguageException {
+
+ // iterating over the facts
+ for (int i=0; i<facts.length; i++) {
+ Fact factDefn = facts[i];
Class classDefn = ObjectUtils.getClassDefn(factDefn.getType(), pkg.getImports(),null);
Object fact;
try {
@@ -95,8 +108,14 @@
for (int j=0; j<fields.length; j++) {
Field field = fields[j];
// set the property on our newly instantiated fact bean
-
+ try {
+ PropertyUtils.setProperty(fact, field.getName(), field.getValue());
+ }catch (Exception e) {
+ throw new RuleTestServiceUnavailableException("Exception ocurred",e);
+ }
}
+ // assert the fact into working memory
+ wm.assertObject(fact);
}
}
}
More information about the jboss-svn-commits
mailing list