[jboss-svn-commits] JBL Code SVN: r16399 - in labs/jbossesb/workspace/jdelong/ruleservice: IDE/JBossIDE/services/jbrules and 18 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 7 00:28:04 EST 2007
Author: jeffdelong
Date: 2007-11-07 00:28:03 -0500 (Wed, 07 Nov 2007)
New Revision: 16399
Added:
labs/jbossesb/workspace/jdelong/ruleservice/.project
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-compiler-4.0.3.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-core-4.0.3.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-decisiontables-4.0.3.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-jsr94-4.0.3.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/mvel14-1.2.10.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/xstream-1.2.2.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleBaseHelper.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleService.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceException.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceFactory.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/ListenerTagNames.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleService.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.xml
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Approve.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Customer.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Driver.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/DroolsRuleServiceUnitTest.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Order.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Policy.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Rejection.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/cache/
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/cache/http%3A%2F%2Flocalhost%3A8080%2Fdrools-jbrms%2Forg.drools.brms.JBRMS%2Fpackage%2Forg.jboss.soa.esb.services.rules%2FLATEST
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscount.drl
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountOnMultipleOrders.drl
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountOnMultipleOrders2.drl
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountWithCollections.drl
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/brmsdeployedrules.properties
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/cache/
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/cache/http%3A%2F%2Flocalhost%3A8080%2Fdrools-jbrms%2Forg.drools.brms.JBRMS%2Fpackage%2Forg.jboss.soa.esb.services.rules%2FLATEST
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/insurancepolicy.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/insurancepolicyall.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/insurancepolicyold.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/package/
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/package/org.jboss.soa.esb.services.rules.pkg
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/pricing.drl
Removed:
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-compiler-4.0.2.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-core-4.0.2.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-decisiontables-4.0.2.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-jsr94-4.0.2.jar
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/BusinessRulesProcessor.java
Modified:
labs/jbossesb/workspace/jdelong/ruleservice/IDE/JBossIDE/services/jbrules/.project
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/routing/cbr/JBRulesCounter.java
labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/ContentBasedWiretap.java
Log:
initial commit of new ruleservice, includes support for decision tables, rule agent, stateful and stateless session, and drools-4.0.3. It address JIRA tasks JBESB-643, 644, and 645
Added: labs/jbossesb/workspace/jdelong/ruleservice/.project
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/.project (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/.project 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ruleservice</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
Modified: labs/jbossesb/workspace/jdelong/ruleservice/IDE/JBossIDE/services/jbrules/.project
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/IDE/JBossIDE/services/jbrules/.project 2007-11-07 04:08:55 UTC (rev 16398)
+++ labs/jbossesb/workspace/jdelong/ruleservice/IDE/JBossIDE/services/jbrules/.project 2007-11-07 05:28:03 UTC (rev 16399)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>jbrules_dbevenius</name>
+ <name>jbrules_ruleservice</name>
<comment></comment>
<projects>
</projects>
Deleted: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-compiler-4.0.2.jar
===================================================================
(Binary files differ)
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-compiler-4.0.3.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-compiler-4.0.3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-core-4.0.2.jar
===================================================================
(Binary files differ)
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-core-4.0.3.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-core-4.0.3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-decisiontables-4.0.2.jar
===================================================================
(Binary files differ)
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-decisiontables-4.0.3.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-decisiontables-4.0.3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-jsr94-4.0.2.jar
===================================================================
(Binary files differ)
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-jsr94-4.0.3.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/drools-jsr94-4.0.3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/mvel14-1.2.10.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/mvel14-1.2.10.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/xstream-1.2.2.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/lib/ext/xstream-1.2.2.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/routing/cbr/JBRulesCounter.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/routing/cbr/JBRulesCounter.java 2007-11-07 04:08:55 UTC (rev 16398)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/routing/cbr/JBRulesCounter.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -256,7 +256,7 @@
/**
* Register this MBean with JBoss.
*/
- protected void registerMBean() {
+ public void registerMBean() {
MBeanServer mbeanServer = null;
try {
mbeanServer = MBeanServerLocator.locateJBoss();
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleBaseHelper.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleBaseHelper.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleBaseHelper.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,225 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.services.rules;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.apache.log4j.Logger;
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.agent.RuleAgent;
+import org.drools.compiler.DroolsParserException;
+import org.drools.compiler.PackageBuilder;
+import org.drools.compiler.PackageBuilderConfiguration;
+import org.drools.decisiontable.InputType;
+import org.drools.decisiontable.SpreadsheetCompiler;
+import org.drools.rule.Package;
+import org.jboss.soa.esb.util.ClassUtil;
+
+/**
+ * A helper class, it returns rulebases based on various methods of creating them
+ *
+ * @author jdelong at redhat.com
+ *
+ */
+public class DroolsRuleBaseHelper {
+
+ private static Logger logger = Logger.getLogger(DroolsRuleBaseHelper.class);
+
+ /**
+ * Creates a rulebase using rules and dsl from files. Note the dsl may be null.
+ */
+ public RuleBase createRuleBaseFromRuleFiles(String ruleFile, String dsl)
+ throws DroolsParserException, IOException, RuleServiceException {
+ // read in the rules
+ logger.debug("Going to create a rulebase from the ruleFile: "
+ + ruleFile);
+ InputStream rulesInputStream = getRulesInputStream(ruleFile);
+
+ if (rulesInputStream == null) {
+ logger.error("Could not find ruleFile: " + ruleFile);
+ return null;
+ } else {
+ Reader ruleReader = getRulesReader(rulesInputStream);
+
+ PackageBuilderConfiguration pkgBuilderCfg = new PackageBuilderConfiguration();
+ //pkgBuilderCfg.setCompiler(PackageBuilderConfiguration.JANINO);
+ PackageBuilder builder = new PackageBuilder(pkgBuilderCfg);
+ try {
+ if (dsl == null) {
+ builder.addPackageFromDrl(ruleReader);
+ } else {
+ logger.debug("Going to read the dsl: " + dsl);
+ InputStream dslInputStream = getRulesInputStream(dsl);
+ Reader dslReader = getRulesReader(dslInputStream);
+ if (dslReader == null) {
+ logger.error("Could not find dsl: " + ruleFile);
+ } else {
+ try {
+ builder.addPackageFromDrl(ruleReader, dslReader);
+ } finally {
+ safeClose(dslInputStream);
+ }
+ }
+ }
+ } finally {
+ safeClose(rulesInputStream);
+ }
+
+ // get the compiled package (which is serializable)
+ Package pkg = builder.getPackage();
+ // add the package to a rulebase
+ try {
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
+ ruleBase.addPackage(pkg);
+ return ruleBase;
+ } catch (Exception ex) {
+ throw new RuleServiceException(ex.getMessage(), ex);
+ }
+ }
+ }
+
+ /**
+ * Reading the rules and dsl from files and returning as a string
+ * to compare them for changes. Note the dsl may be null.
+ */
+ public String getRulesAsString(String ruleFile, String dsl)
+ throws IOException {
+ logger.debug("Going to hash the rule: " + ruleFile);
+ InputStream rulesInputStream = getRulesInputStream(ruleFile);
+ if (rulesInputStream == null) {
+ logger.error("Could not find ruleFile: " + ruleFile);
+ return null;
+ } else {
+ final String rules;
+ try {
+ rules = getString(rulesInputStream);
+ } finally {
+ safeClose(rulesInputStream);
+ }
+ String language = "";
+ if (dsl != null) {
+ logger.debug("Going to hash the language: " + dsl);
+ InputStream dslInputStream = getRulesInputStream(dsl);
+ if (dslInputStream == null) {
+ logger.error("Could not find language: " + dsl);
+ } else {
+ try {
+ language = getString(dslInputStream);
+ } finally {
+ safeClose(dslInputStream);
+ }
+ }
+ }
+ return rules + language;
+ }
+
+ }
+
+ private Reader getRulesReader(InputStream inputStream) {
+ return new InputStreamReader(inputStream);
+ }
+
+ private InputStream getRulesInputStream(String rulesFile) {
+ return ClassUtil.getResourceAsStream("/" + rulesFile,
+ DroolsRuleBaseHelper.class);
+ }
+
+ /**
+ * Reading the rules and dsl from files. Note the dsl may be null.
+ */
+ public RuleBase createRuleBaseFromDecisionTable(String decisionTable)
+ throws DroolsParserException, IOException, RuleServiceException {
+ logger.debug("Going to read the decisionTable: " + decisionTable);
+ String drl = getSpreadsheetRules(decisionTable);
+ PackageBuilder builder = new PackageBuilder();
+ builder.addPackageFromDrl(new StringReader(drl));
+ try {
+ //add the package to a rulebase (deploy the rule package).
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
+ ruleBase.addPackage(builder.getPackage());
+ return ruleBase;
+ } catch (Exception ex) {
+ throw new RuleServiceException(ex.getMessage(), ex);
+ }
+ }
+
+ /**
+ * Reading the decision table and creating a drl
+ */
+ public String getSpreadsheetRules(String decisionTable) {
+ logger.debug("Going to read the decisionTable: " + decisionTable);
+ String drl;
+ InputStream inputStreamDT = ClassUtil.getResourceAsStream("/"
+ + decisionTable, DroolsRuleBaseHelper.class);
+ if (inputStreamDT == null) {
+ logger.error("Could not find decisionTable: " + decisionTable);
+ return null;
+ } else {
+ SpreadsheetCompiler compiler = new SpreadsheetCompiler();
+
+ try {
+ drl = compiler.compile(inputStreamDT, InputType.XLS);
+ logger.debug("Compiled the decsionTable to a drl: " + drl);
+ } finally {
+ safeClose(inputStreamDT);
+ }
+ return drl;
+ }
+
+ }
+
+ /**
+ * This shows how rules are loaded up from a deployed package.
+ */
+ public RuleBase loadRuleBaseFromRuleAgent(String ruleAgentProperties)
+ throws IOException, Exception {
+
+ logger.debug("Going to read the ruleAgentProperties: "
+ + ruleAgentProperties);
+ RuleAgent agent = RuleAgent.newRuleAgent("/" + ruleAgentProperties);
+ RuleBase rb = agent.getRuleBase();
+
+ return rb;
+ }
+
+ private static void safeClose(final InputStream is) {
+ try {
+ is.close();
+ } catch (final Throwable th) {
+ } // ignore
+ }
+
+ private static String getString(InputStream in) throws IOException {
+ StringBuffer stringBuffer = new StringBuffer();
+ byte[] b = new byte[4096];
+ for (int i; (i = in.read(b)) != -1;) {
+ stringBuffer.append(new String(b, 0, i));
+ }
+ return stringBuffer.toString();
+ }
+
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleService.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleService.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleService.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,783 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.services.rules;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Level;
+import org.drools.RuleBase;
+import org.drools.StatefulSession;
+import org.drools.StatelessSession;
+import org.drools.compiler.DroolsParserException;
+import org.jboss.internal.soa.esb.services.routing.cbr.JBRulesCounter;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.lifecycle.LifecyclePriorities;
+import org.jboss.soa.esb.lifecycle.LifecycleResource;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceFactory;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.rules.RuleService;
+
+/**
+ * The Implementation of a rule engine interface for rules services. Here we use
+ * JBossRules (aka Drools). We keep a HashMap of stateful session working
+ * memories.
+ *
+ * @author jdelong at redhat.com
+ *
+ */
+public class DroolsRuleService implements RuleService {
+
+ /**
+ * The lifecycle resource factory.
+ */
+ private static final LifecycleResourceFactory<Map<String, RuleBase>> lifecycleRuleBaseFactory = new LifecycleRuleBaseFactory();
+ /**
+ * Lifecycle couriers.
+ */
+ private static final LifecycleResource<Map<String, RuleBase>> lifecycleRuleBases = new LifecycleResource<Map<String, RuleBase>>(
+ lifecycleRuleBaseFactory, LifecyclePriorities.RULE_BASE_PRIORITY);
+ /**
+ * The lifecycle resource factory.
+ */
+ private static final LifecycleResourceFactory<Map<String, String>> lifecycleRuleSetFactory = new LifecycleRuleSetFactory();
+ /**
+ * Lifecycle couriers.
+ */
+ private static final LifecycleResource<Map<String, String>> lifecycleRuleSets = new LifecycleResource<Map<String, String>>(
+ lifecycleRuleSetFactory, LifecyclePriorities.RULE_BASE_PRIORITY);
+
+ private static Logger logger = Logger.getLogger(DroolsRuleService.class);
+
+ private JBRulesCounter rulesCounter = null;
+
+ /**
+ * Execute rules using a certain ruleSet and domain specific language using
+ * the Stateless rule engine API
+ *
+ * @param ruleSet -
+ * String reference to a file which contains a ruleSet.
+ * @param dsl -
+ * String reference to a file which contains a custom rule
+ * language definition
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading
+ * the ruleSet.
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList -
+ * a list with additional objects (typically pulled from the
+ * message) to be inserted into working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatelessRules(String ruleSet, String dsl,
+ boolean ruleReload, Message message, List<Object> objectList)
+ throws RuleServiceException
+
+ {
+ long startTime = System.nanoTime();
+
+ try {
+ RuleBase ruleBase = getRuleBaseForFileBasedRules(ruleSet, dsl,
+ ruleReload);
+ message = executeStatelessRules(ruleBase, message, objectList);
+
+ long procTime = System.nanoTime() - startTime;
+ if (rulesCounter != null) {
+ rulesCounter.update(procTime, ruleSet,
+ JBRulesCounter.RULES_SUCCEED);
+ }
+
+ return message;
+
+ } catch (RuleServiceException ree) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleSet,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not parse the rules. "
+ + ree.getMessage(), ree);
+ }
+ }
+
+ /**
+ * Execute rules from a decision table using the Stateless rule engine API
+ *
+ * @param decisionTable -
+ * String reference to a file which contains a spreadsheet of rules
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading
+ * the ruleSet.
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatelessRulesFromDecisionTable(String decisionTable,
+ boolean ruleReload, Message message, List<Object> objectList)
+ throws RuleServiceException {
+ long startTime = System.nanoTime();
+
+ try {
+ RuleBase ruleBase = getRuleBaseForDecisionTable(decisionTable,
+ ruleReload);
+ message = executeStatelessRules(ruleBase, message, objectList);
+
+ long procTime = System.nanoTime() - startTime;
+ if (rulesCounter != null) {
+ rulesCounter.update(procTime, decisionTable,
+ JBRulesCounter.RULES_SUCCEED);
+ }
+
+ return message;
+
+ } catch (RuleServiceException ree) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, decisionTable,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not parse the rules. "
+ + ree.getMessage(), ree);
+ }
+ }
+
+ /**
+ * Execute rules using a rule package retrieved via the Rule Agent from a URL of local file system
+ * using the Stateless rule engine API
+ *
+ * @param ruleAgentProperties -
+ * String reference to a file which contains properties used by the RuleAgent to locate a rule package.
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatelessRulesFromRuleAgent(
+ String ruleAgentProperties, Message message, List<Object> objectList)
+ throws RuleServiceException {
+ long startTime = System.nanoTime();
+ try {
+ DroolsRuleBaseHelper rbHelper = new DroolsRuleBaseHelper();
+ RuleBase ruleBase = rbHelper
+ .loadRuleBaseFromRuleAgent(ruleAgentProperties);
+ final Map<String, RuleBase> ruleBases = lifecycleRuleBases
+ .getLifecycleResource();
+ if (ruleBase != null) {
+ ruleBases.put(ruleAgentProperties, ruleBase);
+
+ message = executeStatelessRules(ruleBase, message, objectList);
+
+ long procTime = System.nanoTime() - startTime;
+ if (rulesCounter != null) {
+ rulesCounter.update(procTime, ruleAgentProperties,
+ JBRulesCounter.RULES_SUCCEED);
+ }
+ }
+
+ return message;
+
+ } catch (IOException ioe) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleAgentProperties,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException(
+ "Could not read the ruleAgentProperties. "
+ + ioe.getMessage(), ioe);
+ } catch (RuleServiceException ree) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleAgentProperties,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not parse the rules. "
+ + ree.getMessage(), ree);
+ } catch (Exception e) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleAgentProperties,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException(
+ "RuleAgent could not get the RuleBase. " + e.getMessage(),
+ e);
+ }
+
+ }
+
+ /**
+ * Execute rules using a certain ruleSet and domain specific language using the Stateful rule engine API
+ *
+ * @param ruleSet -
+ * String reference to a file which contains a ruleSet.
+ * @param domainSpecificLanguage -
+ * String reference to a file which contains a custom rule
+ * language definition
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading
+ * the ruleSet.
+ * @param dispose -
+ * if set to true, working memory will be disposed after the rules are fired
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatefulRules(String ruleSet, String dsl,
+ boolean ruleReload, boolean dispose, Message message,
+ List<Object> objectList) throws RuleServiceException {
+ long startTime = System.nanoTime();
+
+ try {
+ RuleBase ruleBase = getRuleBaseForFileBasedRules(ruleSet, dsl,
+ ruleReload);
+ message = executeStatefulRules(ruleBase, dispose, message,
+ objectList);
+
+ long procTime = System.nanoTime() - startTime;
+ if (rulesCounter != null) {
+ rulesCounter.update(procTime, ruleSet,
+ JBRulesCounter.RULES_SUCCEED);
+ }
+
+ return message;
+
+ } catch (RuleServiceException ree) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleSet,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not parse the rules. "
+ + ree.getMessage(), ree);
+ }
+ }
+
+ /**
+ * Execute rules from a decision table using the Stateful rule engine API
+ *
+ * @param decisionTable -
+ * String reference to a file which contains a spreadsheet of rules
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading
+ * the ruleSet.
+ * @param dispose -
+ * if set to true, working memory will be disposed after the rules are fired
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatefulRulesFromDecisionTable(String decisionTable,
+ boolean ruleReload, boolean dispose, Message message,
+ List<Object> objectList) throws RuleServiceException {
+ long startTime = System.nanoTime();
+
+ try {
+ RuleBase ruleBase = getRuleBaseForDecisionTable(decisionTable,
+ ruleReload);
+ message = executeStatefulRules(ruleBase, dispose, message,
+ objectList);
+
+ long procTime = System.nanoTime() - startTime;
+ if (rulesCounter != null) {
+ rulesCounter.update(procTime, decisionTable,
+ JBRulesCounter.RULES_SUCCEED);
+ }
+
+ return message;
+
+ } catch (RuleServiceException ree) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, decisionTable,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not parse the rules. "
+ + ree.getMessage(), ree);
+ }
+ }
+
+ /**
+ * Execute rules using a rule package retrieved via the Rule Agent from a URL of local file system
+ * using the Stateful rule engine API
+ *
+ * @param ruleAgentProperties -
+ * String reference to a file which contains properties used by the RuleAgent to locate a rule package.
+ * @param dispose -
+ * if set to true, working memory will be disposed after the rules are fired
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatefulRulesFromRuleAgent(
+ String ruleAgentProperties, boolean dispose, Message message,
+ List<Object> objectList) throws RuleServiceException {
+ long startTime = System.nanoTime();
+ try {
+ DroolsRuleBaseHelper rbHelper = new DroolsRuleBaseHelper();
+ RuleBase ruleBase = rbHelper
+ .loadRuleBaseFromRuleAgent(ruleAgentProperties);
+
+ final Map<String, RuleBase> ruleBases = lifecycleRuleBases
+ .getLifecycleResource();
+ if (ruleBase != null) {
+ ruleBases.put(ruleAgentProperties, ruleBase);
+
+ message = executeStatefulRules(ruleBase, dispose, message,
+ objectList);
+
+ long procTime = System.nanoTime() - startTime;
+ if (rulesCounter != null) {
+ rulesCounter.update(procTime, ruleAgentProperties,
+ JBRulesCounter.RULES_SUCCEED);
+ }
+ }
+
+ return message;
+
+ } catch (IOException ioe) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleAgentProperties,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException(
+ "Could not read the ruleAgentProperties. "
+ + ioe.getMessage(), ioe);
+ } catch (RuleServiceException ree) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleAgentProperties,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not parse the rules. "
+ + ree.getMessage(), ree);
+ } catch (Exception e) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleAgentProperties,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException(
+ "RuleAgent could not get the RuleBase. " + e.getMessage(),
+ e);
+ }
+
+ }
+
+ /**
+ * Continue executing rules where the working memory already exists.
+ *
+ * @param rules -
+ * String reference to a file, either the drl file, the decision table,
+ * or the ruleAgentProperties. This is used to find the ruleBase.
+ * @param dispose -
+ * if set to true, working memory will be disposed after the rules are fired
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message continueStatefulRulesExecution(String rules,
+ boolean dispose, Message message, List<Object> objectList)
+ throws RuleServiceException {
+ long startTime = System.nanoTime();
+ try {
+ final Map<String, RuleBase> ruleBases = lifecycleRuleBases
+ .getLifecycleResource();
+
+ RuleBase ruleBase = ruleBases.get(rules);
+ StatefulSession[] workingMemories = ruleBase.getStatefulSessions();
+ // there should only be one created from this ruleBase?
+ StatefulSession workingMemory = workingMemories[0];
+ logger
+ .log(Level.DEBUG, "Executing rules with RuleBase="
+ + ruleBase);
+
+ workingMemory.setGlobal("message", message);
+
+ if (objectList != null) {
+ for (Object object : objectList) {
+ workingMemory.insert(object);
+ }
+ }
+
+ // workingMemory.insert(message);
+ logger.log(Level.DEBUG, "Fire the JBossRules Engine");
+ workingMemory.fireAllRules();
+
+ logger.log(Level.DEBUG, "Updated message: " + message);
+
+ if (dispose) {
+ workingMemory.dispose();
+ }
+
+ long procTime = System.nanoTime() - startTime;
+ if (rulesCounter != null) {
+ rulesCounter.update(procTime, rules,
+ JBRulesCounter.RULES_SUCCEED);
+ }
+
+ return message;
+
+ } catch (Exception e) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, rules,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException(
+ "Could not continue rule execution. " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Determine if file based rules need reloading and return the rulebase
+ *
+ * @param ruleSet -
+ * String reference to a file which contains a ruleSet.
+ * @param dsl -
+ * String reference to a file which contains a custom rule language
+ * definition
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading the
+ * ruleSet.
+ *
+ * @return Message with updated objects.
+ */
+ protected RuleBase getRuleBaseForFileBasedRules(String ruleSet, String dsl,
+ boolean ruleReload) throws RuleServiceException {
+ long startTime = System.nanoTime();
+ try {
+ DroolsRuleBaseHelper rbHelper = new DroolsRuleBaseHelper();
+
+ String newRuleSet = null;
+ boolean isRulesChanged = false;
+
+ final Map<String, String> ruleSets = lifecycleRuleSets
+ .getLifecycleResource();
+ if (ruleReload) {
+ String currentRuleSet = ruleSets.get(ruleSet);
+ newRuleSet = rbHelper.getRulesAsString(ruleSet, dsl);
+ if (currentRuleSet == null
+ || !currentRuleSet.equals(newRuleSet)) {
+ isRulesChanged = true;
+ }
+
+ }
+ final Map<String, RuleBase> ruleBases = lifecycleRuleBases
+ .getLifecycleResource();
+ RuleBase ruleBase = ruleBases.get(ruleSet);
+ if (ruleBase == null || isRulesChanged) {
+ logger.log(Level.DEBUG, "Reading ruleSet from file=" + ruleSet);
+ ruleBase = rbHelper.createRuleBaseFromRuleFiles(ruleSet, dsl);
+ if (ruleBase != null)
+ ruleBases.put(ruleSet, ruleBase);
+ if (newRuleSet == null) {
+ newRuleSet = rbHelper.getRulesAsString(ruleSet, dsl);
+ }
+ if (ruleSet != null)
+ ruleSets.put(ruleSet, newRuleSet);
+ }
+
+ // this should really be a RULES_COMPILED status, and processing time should be compilationTime
+ // long procTime = System.nanoTime() - startTime;
+ // if (rulesCounter != null) {
+ // rulesCounter.update(procTime, ruleSet, JBRulesCounter.RULES_SUCCEED);
+ // }
+
+ return ruleBase;
+
+ } catch (final LifecycleResourceException lre) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleSet,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not load lifecycle data. "
+ + lre.getMessage(), lre);
+ } catch (IOException ioe) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleSet,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not read the rules. "
+ + ioe.getMessage(), ioe);
+ } catch (DroolsParserException dpe) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleSet,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not parse the rules. "
+ + dpe.getMessage(), dpe);
+ } catch (RuleServiceException ree) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, ruleSet,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not parse the rules. "
+ + ree.getMessage(), ree);
+ }
+
+ }
+
+ /**
+ * Determine if decision table need reloading and return the rulebase
+ *
+ * @param ruleSet -
+ * String reference to a file which contains a ruleSet.
+ * @param dsl -
+ * String reference to a file which contains a custom rule language
+ * definition
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading the
+ * ruleSet.
+ *
+ * @return Message with updated objects.
+ */
+ protected RuleBase getRuleBaseForDecisionTable(String decisionTable,
+ boolean ruleReload) throws RuleServiceException {
+ long startTime = System.nanoTime();
+ try {
+ DroolsRuleBaseHelper rbHelper = new DroolsRuleBaseHelper();
+ RuleBase ruleBase;
+ if (ruleReload) {
+ String drl = rbHelper.getSpreadsheetRules(decisionTable);
+ ruleBase = getRuleBaseForFileBasedRules(drl, null, ruleReload);
+ } else {
+ ruleBase = rbHelper
+ .createRuleBaseFromDecisionTable(decisionTable);
+ }
+ // this should really be a RULES_COMPILED status, and processing time should be compilationTime
+ // long procTime = System.nanoTime() - startTime;
+ // if (rulesCounter != null) {
+ // rulesCounter.update(procTime, ruleSet, JBRulesCounter.RULES_SUCCEED);
+ // }
+ return ruleBase;
+
+ } catch (IOException ioe) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, decisionTable,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not read the rules. "
+ + ioe.getMessage(), ioe);
+ } catch (DroolsParserException dpe) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, decisionTable,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not parse the rules. "
+ + dpe.getMessage(), dpe);
+ } catch (RuleServiceException ree) {
+ if (rulesCounter != null) {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, decisionTable,
+ JBRulesCounter.RULES_FAILED);
+ }
+ throw new RuleServiceException("Could not parse the rules. "
+ + ree.getMessage(), ree);
+ }
+ }
+
+ /**
+ * Execute rules using using the Stateless API
+ *
+ * @param rulebase -
+ * the rulebase to use
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList -
+ * a list with additional objects (typically pulled from the message)
+ * to be inserted into working memory
+ *
+ * @return Message with updated objects.
+ */
+ @SuppressWarnings("unchecked")
+ protected Message executeStatelessRules(RuleBase ruleBase, Message message,
+ List<Object> objectList) {
+ StatelessSession workingMemory = ruleBase.newStatelessSession();
+ logger.log(Level.DEBUG, "Executing rules with RuleBase=" + ruleBase);
+
+ List<Object> facts = new ArrayList(objectList);
+ workingMemory.setGlobal("message", message);
+ logger.log(Level.DEBUG, "Fire the Drools Rules Engine");
+ workingMemory.execute(facts);
+
+ return message;
+ }
+
+ /**
+ * Execute rules using using the Stateful API
+ *
+ * @param rulebase -
+ * the rulebase to use
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList -
+ * a list with additional objects (typically pulled from the message)
+ * to be inserted into working memory
+ *
+ * @return Message with updated objects.
+ */
+ protected Message executeStatefulRules(RuleBase ruleBase, boolean dispose,
+ Message message, List<Object> objectList) {
+
+ StatefulSession workingMemory = ruleBase.newStatefulSession();
+ logger.log(Level.DEBUG, "Executing rules with RuleBase=" + ruleBase);
+
+ workingMemory.setGlobal("message", message);
+
+ if (objectList != null) {
+ for (Object object : objectList) {
+ workingMemory.insert(object);
+ }
+ }
+
+ logger.log(Level.DEBUG, "Fire the JBossRules Engine");
+ workingMemory.fireAllRules();
+
+ logger.log(Level.DEBUG, "Updated message: " + message);
+
+ if (dispose) {
+ workingMemory.dispose();
+ }
+ return message;
+ }
+
+ public void setConfigTree(ConfigTree configTree) {
+ rulesCounter = new JBRulesCounter(configTree);
+ rulesCounter.registerMBean();
+ }
+
+ /**
+ * The lifecycle resource factory for rule sets.
+ *
+ * @author kevin
+ */
+ public static class LifecycleRuleBaseFactory implements
+ LifecycleResourceFactory<Map<String, RuleBase>> {
+ /**
+ * Create a resource object which will be associated with the
+ * specified lifecycle identity.
+ *
+ * @param lifecycleIdentity
+ * The associated lifecycle identity.
+ * @return The lifecycle resource
+ * @throws LifecycleResourceException
+ * for errors during construction.
+ */
+ public Map<String, RuleBase> createLifecycleResource(
+ final String lifecycleIdentity)
+ throws LifecycleResourceException {
+ return new ConcurrentHashMap<String, RuleBase>();
+ }
+
+ /**
+ * Destroy a resource object which is associated with the specified
+ * lifecycle identity.
+ *
+ * @param resource
+ * The lifecycle resource.
+ * @param lifecycleIdentity
+ * The associated lifecycle identity.
+ * @return The lifecycle resource.
+ * @throws LifecycleResourceException
+ * for errors during destroy.
+ */
+ public void destroyLifecycleResource(
+ final Map<String, RuleBase> resource,
+ final String lifecycleIdentity)
+ throws LifecycleResourceException {
+ }
+ }
+
+ /**
+ * The lifecycle resource factory for rule sets.
+ *
+ * @author kevin
+ */
+ public static class LifecycleRuleSetFactory implements
+ LifecycleResourceFactory<Map<String, String>> {
+ /**
+ * Create a resource object which will be associated with the
+ * specified lifecycle identity.
+ *
+ * @param lifecycleIdentity
+ * The associated lifecycle identity.
+ * @return The lifecycle resource
+ * @throws LifecycleResourceException
+ * for errors during construction.
+ */
+ public Map<String, String> createLifecycleResource(
+ final String lifecycleIdentity)
+ throws LifecycleResourceException {
+ return new ConcurrentHashMap<String, String>();
+ }
+
+ /**
+ * Destroy a resource object which is associated with the specified
+ * lifecycle identity.
+ *
+ * @param resource
+ * The lifecycle resource.
+ * @param lifecycleIdentity
+ * The associated lifecycle identity.
+ * @return The lifecycle resource.
+ * @throws LifecycleResourceException
+ * for errors during destroy.
+ */
+ public void destroyLifecycleResource(
+ final Map<String, String> resource,
+ final String lifecycleIdentity)
+ throws LifecycleResourceException {
+ }
+ }
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceException.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceException.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceException.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.services.rules;
+
+/**
+ * @author jdelong at redhat.com
+ *
+ */
+public class RuleServiceException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public RuleServiceException() {
+ super();
+ }
+
+ public RuleServiceException(String msg) {
+ super(msg);
+ }
+
+ public RuleServiceException(Throwable cause) {
+ super(cause);
+ }
+
+ public RuleServiceException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceFactory.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceFactory.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceFactory.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,62 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.internal.soa.esb.services.rules;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.services.rules.RuleService;
+import org.jboss.soa.esb.util.ClassUtil;
+/**
+ * Returns an instance of the RuleService.
+ *
+ * @author jdelong at redhat.com
+ *
+ */
+public class RuleServiceFactory {
+ private static Logger logger = Logger.getLogger(RuleServiceFactory.class);
+
+ /**
+ * This factory returns a ruleService
+ *
+ * @author jdelong at redhat.com
+ *
+ */
+ public static RuleService getRuleService(String className)
+ throws RuleServiceException {
+ RuleService rs = null;
+ logger.log(Level.DEBUG, "Going to load " + className);
+ try {
+ // instruct class loader to load the RuleService Implementation
+ Class rsClass = ClassUtil.forName(className,
+ RuleServiceFactory.class);
+ // Try to get an instance of the CBR
+ rs = (RuleService) rsClass.newInstance();
+ } catch (ClassNotFoundException cnfex) {
+ throw new RuleServiceException("RuleService Implementation="
+ + className + " not found", cnfex);
+ } catch (Exception e) {
+ throw new RuleServiceException(className + " invokation problem. "
+ + e.getLocalizedMessage(), e);
+ }
+ return rs;
+ }
+}
Deleted: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/BusinessRulesProcessor.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/BusinessRulesProcessor.java 2007-11-07 04:08:55 UTC (rev 16398)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/BusinessRulesProcessor.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -1,68 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-/**
- * Routes the Message argument to a fixed list of services ([category,name])
- * @author kstam at jboss.com
- * @since Version 4.2
- */
-package org.jboss.soa.esb.actions;
-
-import java.util.List;
-
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.mapping.ObjectMappingException;
-import org.jboss.soa.esb.services.registry.RegistryException;
-import org.jboss.soa.esb.services.routing.MessageRouterException;
-
-public class BusinessRulesProcessor extends ContentBasedRouter
-{
- public BusinessRulesProcessor(ConfigTree config) throws ConfigurationException, RegistryException, MessageRouterException
- {
- super(config);
- }
- /**
- * Inspect the content of the message using a rule set
- * Router the message to one or more destinations, using the ContentBasedRouter to figure out
- * to which destinations it is going to be routed too.
- *
- * @param message
- * @return Message
- * @throws ActionProcessingException
- */
- public Message process(Message message) throws ActionProcessingException
- {
- try {
- List<Object> objectList = _mapper.createObjectList(message, _messagePathList);
- _cbr.route(_ruleSet, _ruleLanguage, _ruleReload, message, objectList);
- } catch (ObjectMappingException ome) {
- throw new ActionProcessingException(ome.getMessage(), ome);
- } catch (MessageRouterException mre) {
- throw new ActionProcessingException(mre.getMessage(), mre);
- }
- return message;
- }
-
-
-}
Modified: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/ContentBasedWiretap.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/ContentBasedWiretap.java 2007-11-07 04:08:55 UTC (rev 16398)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/ContentBasedWiretap.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -70,11 +70,11 @@
_cbr = ContentBasedRouterFactory.getRouter(_cbrClass);
_cbr.setConfigTree(config);
_mapper = new ObjectMapper(config);
- try {
- dlQueueInvoker = new ServiceInvoker(ServiceInvoker.INTERNAL_SERVICE_CATEGORY, ServiceInvoker.DEAD_LETTER_SERVICE_NAME);
- } catch (MessageDeliverException e) {
- new MessageRouterException(e);
- }
+// try {
+// dlQueueInvoker = new ServiceInvoker(ServiceInvoker.INTERNAL_SERVICE_CATEGORY, ServiceInvoker.DEAD_LETTER_SERVICE_NAME);
+// } catch (MessageDeliverException e) {
+// new MessageRouterException(e);
+// }
}
public void initialise() {
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/ListenerTagNames.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/ListenerTagNames.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/ListenerTagNames.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+/**
+ * Contains tag names as they can be used in the configuration.
+ *
+ */
+package org.jboss.soa.esb.services.rules;
+
+/**
+ * Add several tag names for the RuleService.
+ * These could be added to org.jboss.soa.esb.listeners.ListenerTagNames;
+ *
+ * @author jdelong at redhat.com
+ *
+ */
+
+public class ListenerTagNames {
+
+ /** RuleSet reference (Filename) */
+
+ // tag names, need to be moved to ListernTagNames in the org.jboss.soa.esb.listeners.ListenerTagNames;
+ public static final String RS_CLASS = "rsClass";
+ public static final String RULE_SET_TAG = "ruleSet";
+ public static final String RULE_LANGUAGE_TAG = "ruleLanguage";
+ public static final String RULE_RELOAD_TAG = "ruleReload";
+ public static final String DECISION_TABLE_TAG = "decisionTable";
+ public static final String RULE_AGENT_PROPERTIES_TAG = "ruleAgentProperties";
+ public static final String DISPOSE_TAG = "dispose";
+ public static final String CONTINUE_TAG = "continue";
+ public static final String STATEFUL_TAG = "stateful";
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleService.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleService.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleService.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.services.rules;
+
+import java.util.List;
+
+import org.jboss.internal.soa.esb.services.rules.RuleServiceException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * RulesEngine Interface. Separates implementation from the runtime, allowing
+ * the ESB to support different implementations of rule engines.
+ *
+ * @author jdelong at redhat.com
+ *
+ */
+public interface RuleService {
+ public void setConfigTree(ConfigTree configTree);
+
+ /**
+ * Execute rules using a certain ruleSet and domain specific language using the Stateless rule engine API
+ *
+ * @param ruleSet -
+ * String reference to a file which contains a ruleSet.
+ * @param dsl -
+ * String reference to a file which contains a custom rule
+ * language definition
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading
+ * the ruleSet.
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatelessRules(String ruleSet, String dsl,
+ boolean ruleReload, Message message, List<Object> objectList)
+ throws RuleServiceException;
+
+ /**
+ * Execute rules from a decision table using the Stateless rule engine API
+ *
+ * @param decisionTable -
+ * String reference to a file which contains a spreadsheet of rules
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading
+ * the ruleSet.
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatelessRulesFromDecisionTable(String decisionTable,
+ boolean ruleReload, Message message, List<Object> objectList)
+ throws RuleServiceException;
+
+ /**
+ * Execute rules using a rule package retrieved via the Rule Agent from a URL of local file system
+ * using the Stateless rule engine API
+ *
+ * @param ruleAgentProperties -
+ * String reference to a file which contains properties used by the RuleAgent to locate a rule package.
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatelessRulesFromRuleAgent(
+ String ruleAgentProperties, Message message, List<Object> objectList)
+ throws RuleServiceException;
+
+ /**
+ * Execute rules using a certain ruleSet and domain specific language using the Stateful rule engine API
+ *
+ * @param ruleSet -
+ * String reference to a file which contains a ruleSet.
+ * @param dsl -
+ * String reference to a file which contains a custom rule
+ * language definition
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading
+ * the ruleSet.
+ * @param dispose -
+ * if set to true, working memory will be disposed after the rules are fired
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatefulRules(String ruleSet, String dsl,
+ boolean ruleReload, boolean dispose, Message message,
+ List<Object> objectList) throws RuleServiceException;
+
+ /**
+ * Execute rules from a decision table using the Stateful rule engine API
+ *
+ * @param decisionTable -
+ * String reference to a file which contains a spreadsheet of rules
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading
+ * the ruleSet.
+ * @param dispose -
+ * if set to true, working memory will be disposed after the rules are fired
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatefulRulesFromDecisionTable(String decisionTable,
+ boolean ruleReload, boolean dispose, Message message,
+ List<Object> objectList) throws RuleServiceException;
+
+ /**
+ * Execute rules using a rule package retrieved via the Rule Agent from a URL of local file system
+ * using the Stateful rule engine API
+ *
+ * @param ruleAgentProperties -
+ * String reference to a file which contains properties used by the RuleAgent to locate a rule package.
+ * @param dispose -
+ * if set to true, working memory will be disposed after the rules are fired
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message)t o be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message executeStatefulRulesFromRuleAgent(
+ String ruleAgentProperties, boolean dispose, Message message,
+ List<Object> objectList) throws RuleServiceException;
+
+ /**
+ * Continue executing rules where the working memory already exists.
+ *
+ * @param rules -
+ * String reference to a file, either the drl file, the decision table,
+ * or the ruleAgentProperties. This is used to find the ruleBase.
+ * @param dispose -
+ * if set to true, working memory will be disposed after the rules are fired
+ * @param message -
+ * Message that is updated with the results.
+ * @param objectList - a list with additional objects (typically pulled from the message) to be inserted into
+ * working memory
+ *
+ * @return Message with updated objects.
+ */
+ public Message continueStatefulRulesExecution(String rules,
+ boolean dispose, Message message, List<Object> objectList)
+ throws RuleServiceException;
+
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,720 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.net.URI;
+
+import org.jboss.internal.soa.esb.couriers.MockCourier;
+import org.jboss.internal.soa.esb.couriers.MockCourierFactory;
+import org.jboss.internal.soa.esb.services.registry.MockRegistry;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.testutils.FileUtil;
+import org.jboss.soa.esb.util.ClassUtil;
+
+import org.jboss.internal.soa.esb.services.rules.RuleServiceException;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.BusinessRulesProcessor;
+import org.jboss.soa.esb.services.registry.RegistryException;
+
+import org.jboss.soa.esb.services.rules.Approve;
+import org.jboss.soa.esb.services.rules.Customer;
+import org.jboss.soa.esb.services.rules.Driver;
+import org.jboss.soa.esb.services.rules.Order;
+import org.jboss.soa.esb.services.rules.Policy;
+
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import junit.framework.JUnit4TestAdapter;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ *
+ * @author jdelong at redhat.com
+ *
+ */
+public class BusinessRulesProcessorUnitTest
+{
+ static Logger _logger = Logger.getLogger(BusinessRulesProcessorUnitTest.class);
+
+
+ // messages for the tests
+ Message message;
+ Message message1;
+ Message message2;
+ Message message3;
+ Message message4;
+ Message message5;
+ Message message6;
+ Message message7;
+
+ // facts
+ Order order;
+ Order order1;
+ Order order2;
+ Order order3;
+ Order order4;
+ Order order5;
+ Order order6;
+ Order order7;
+
+ Customer customer = new Customer( "mark", 0 );
+
+
+ List<Order> orders = new ArrayList();
+
+ Driver driver = new Driver();
+ Policy policy = new Policy();
+
+ ConfigTree confTree;
+
+
+ private static EPR epr;
+ private static EPR eprS;
+ private static EPR epr1;
+ private static EPR epr1S;
+ private static EPR epr2;
+ private static EPR epr2S;
+ private static EPR epr3;
+ private static EPR epr3S;
+ private static EPR epr4;
+ private static EPR epr4S;
+ private static EPR epr5;
+ private static EPR epr5S;
+ private static EPR epr6;
+// private static EPR epr7;
+
+ private static MockCourier courier;
+ private static MockCourier courierS;
+ private static MockCourier courier1;
+ private static MockCourier courier1S;
+ private static MockCourier courier2;
+ private static MockCourier courier2S;
+ private static MockCourier courier3;
+ private static MockCourier courier3S;
+ private static MockCourier courier4;
+ private static MockCourier courier4S;
+ private static MockCourier courier5;
+ private static MockCourier courier5S;
+ private static MockCourier courier6;
+// private static MockCourier courier7;
+
+ private static ConfigTree[] actions;
+
+
+ @BeforeClass
+ public static void setUpEPRsandCouriers() throws Exception {
+ MockCourierFactory.install();
+ MockRegistry.install();
+ // epr and courier for drl tests
+ epr = new EPR(new URI("orderDiscount"));
+ courier = new MockCourier(true);
+ MockRegistry.register("test", "OrderDiscountRuleService", epr, courier);
+ eprS = new EPR(new URI("orderDiscountStateful"));
+ courierS = new MockCourier(true);
+ MockRegistry.register("test", "OrderDiscountRuleServiceStateful", eprS, courierS);
+
+
+ // epr and courier for drl and multiple orders tests
+ epr1 = new EPR(new URI("orderDiscountMultiple"));
+ courier1 = new MockCourier(true);
+ MockRegistry.register("test", "OrderDiscountMultipleRuleService", epr1, courier1);
+ epr1S = new EPR(new URI("orderDiscountMultiple"));
+ courier1S = new MockCourier(true);
+ MockRegistry.register("test", "OrderDiscountMultipleRuleServiceStateful", epr1S, courier1S);
+
+
+ // epr and courier for drl and order collection tests
+ epr2 = new EPR(new URI("orderDiscountCollections"));
+ courier2 = new MockCourier(true);
+ MockRegistry.register("test", "OrderDiscountCollectionsRuleService", epr2, courier2);
+ epr2S = new EPR(new URI("orderDiscountCollectionsStateful"));
+ courier2S = new MockCourier(true);
+ MockRegistry.register("test", "OrderDiscountCollectionsRuleServiceStateful", epr2S, courier2S);
+
+
+ // epr and courier for decision table, dsl, and ruleAgent tests
+ epr3 = new EPR(new URI("policyPricing"));
+ courier3 = new MockCourier(true);
+ MockRegistry.register("test", "PolicyPricingRuleService", epr3, courier3);
+ epr3S = new EPR(new URI("policyPricingStateful"));
+ courier3S = new MockCourier(true);
+ MockRegistry.register("test", "PolicyPricingRuleServiceStateful", epr3S, courier3S);
+
+ epr4 = new EPR(new URI("policyApproval"));
+ courier4 = new MockCourier(true);
+ MockRegistry.register("test", "PolicyApprovalRuleService", epr4, courier4);
+ epr4S = new EPR(new URI("policyApprovalStateful"));
+ courier4S = new MockCourier(true);
+ MockRegistry.register("test", "PolicyApprovalRuleServiceStateful", epr4S, courier4S);
+
+
+ epr5 = new EPR(new URI("ruleAgentPolicy"));
+ courier5 = new MockCourier(true);
+ MockRegistry.register("test", "RuleAgenttPolicyService", epr5, courier5);
+ epr5S = new EPR(new URI("ruleAgentPolicyStateful"));
+ courier5S = new MockCourier(true);
+ MockRegistry.register("test", "RuleAgentPolicyStateful", epr5S, courier5S);
+
+
+ epr6 = new EPR(new URI("statefulContinuation"));
+ courier6 = new MockCourier(true);
+ MockRegistry.register("test", "OrderDiscountServiceStatefulContinuation", epr6, courier6);
+
+
+ InputStream in = ClassUtil.getResourceAsStream("BusinessRulesProcessorUnitTest.xml", BusinessRulesProcessorUnitTest.class);
+ String xml = FileUtil.readStream(in);
+ actions = ConfigTree.fromXml(xml).getChildren("action");
+
+
+
+ }
+
+
+ @Before
+ public void setupMessagesAndFacts() {
+
+ // message and facts for drl tests
+ message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order = new Order();
+ order.setOrderId(0);
+ order.setQuantity(20);
+ order.setUnitPrice(new Float("20.0"));
+ message.getBody().add("Order", order);
+
+ // message and facts for drl and multiple orders tests
+ message1 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order1 = new Order();
+ order1.setOrderId(1);
+ order1.setQuantity(20);
+ order1.setUnitPrice(new Float("50.0"));
+ message1.getBody().add("Order1", order1);
+ order2 = new Order();
+ order2.setOrderId(2);
+ order2.setQuantity(5);
+ order2.setUnitPrice(new Float("50.0"));
+ message1.getBody().add("Order2", order2);
+
+ // message and facts for drl and collections tests
+ message2 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order3 = new Order();
+ order3.setOrderId(3);
+ order3.setQuantity(9);
+ order3.setUnitPrice(new Float("50.0"));
+
+ order4 = new Order();
+ order4.setOrderId(4);
+ order4.setQuantity(25);
+ order4.setUnitPrice(new Float("50.0"));
+
+ orders.add(order1);
+ orders.add(order2);
+ orders.add(order3);
+ orders.add(order4);
+
+ message2.getBody().add("Orders", orders);
+
+
+ // message and facts for decision table, dsl, and ruleAgent tests
+ message3 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ driver = new Driver();
+ policy = new Policy();
+ driver.setAge(30);
+ policy.setDriver(driver);
+ message3.getBody().add("Driver", driver);
+ message3.getBody().add("Policy", policy);
+
+ // message and facts for stateful continuation tests
+ // new message with just customer
+ message4 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ message4.getBody().add("Customer", customer);
+ message4.getProperties().setProperty("dispose", false);
+
+ //new message and order
+ message5 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order5 = new Order();
+ order5.setOrderId(5);
+ order5.setQuantity(5);
+ order5.setUnitPrice(new Float("50.0"));
+ order5.setTotalPrice(order5.calculateTotalPrice());
+ order5.setCustomer(customer);
+ message5.getBody().add("Order", order5);
+ message5.getProperties().setProperty("dispose", false);
+ message5.getProperties().setProperty("continue", true);
+
+
+ message6 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order6 = new Order();
+ order6.setOrderId(6);
+ order6.setQuantity(10);
+ order6.setUnitPrice(new Float("80.0"));
+ order6.setTotalPrice(order6.calculateTotalPrice());
+ order6.setCustomer(customer);
+ message6.getBody().add("Order", order6);
+ message6.getProperties().setProperty("dispose", false);
+ message6.getProperties().setProperty("continue", true);
+
+ message7 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order7 = new Order();
+ order7.setOrderId(7);
+ order7.setQuantity(5);
+ order7.setUnitPrice(new Float("60.0"));
+ order7.setTotalPrice(order7.calculateTotalPrice());
+ order7.setCustomer(customer);
+ message7.getBody().add("Order", order7);
+
+
+ }
+
+
+ @Test
+ public void drlStateless()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[0]);
+ brp.process(message);
+
+ assertEquals(order.getDiscount(),10.0);
+ assertEquals("10%",message.getBody().get("DiscountObject0"));
+ System.out.println("test BRP drlStateless passed");
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void drlStateful()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[1]);
+ message.getProperties().setProperty("dispose", true);
+ brp.process(message);
+
+ assertEquals(order.getDiscount(),10.0);
+ assertEquals("10%",message.getBody().get("DiscountObject0"));
+ Order orderFromMessage = (Order) message.getBody().get("Order");
+ assertEquals(orderFromMessage.getDiscount(),10.0);
+ System.out.println("test BRP drlStateful passed");
+
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void drlStatelessMultipleObjects()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[2]);
+ brp.process(message1);
+
+ assertEquals(order1.getDiscount(),10.0);
+ assertEquals(order2.getDiscount(),0.0);
+ assertEquals("10%",message1.getBody().get("DiscountObject1"));
+ assertEquals("0%",message1.getBody().get("DiscountObject2"));
+ Order order1FromMessage = (Order) message1.getBody().get("Order1");
+ assertEquals(order1FromMessage.getDiscount(),10.0);
+ Order order2FromMessage = (Order) message1.getBody().get("Order2");
+ assertEquals(order2FromMessage.getDiscount(),0.0);
+ System.out.println("test BRP drlStatelessMultipleObjects passed");
+
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void drlStatefulMultipleObjects()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[3]);
+ brp.process(message1);
+
+ assertEquals(order1.getDiscount(),10.0);
+ assertEquals(order2.getDiscount(),0.0);
+ assertEquals("10%",message1.getBody().get("DiscountObject1"));
+ assertEquals("0%",message1.getBody().get("DiscountObject2"));
+ Order order1FromMessage = (Order) message1.getBody().get("Order1");
+ assertEquals(order1FromMessage.getDiscount(),10.0);
+ Order order2FromMessage = (Order) message1.getBody().get("Order2");
+ assertEquals(order2FromMessage.getDiscount(),0.0);
+ System.out.println("test BRP drlStatefulMultipleObjects passed");
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+
+ }
+
+
+ @Test
+ public void drlStatelessCollection()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[4]);
+ brp.process(message2);
+
+ assertEquals("10%",message2.getBody().get("DiscountObject1"));
+ assertEquals("0%",message2.getBody().get("DiscountObject2"));
+ assertEquals("0%",message2.getBody().get("DiscountObject3"));
+ assertEquals("10%",message2.getBody().get("DiscountObject4"));
+ // use arrays because we can control which element is where
+ // making it easy to compare in this test case
+ Order[] updatedOrders = (Order[]) message2.getBody().get("UpdatedOrders");
+ Order order1FromMessage = (Order) updatedOrders[0];
+ Order order2FromMessage = (Order) updatedOrders[1];
+ Order order3FromMessage = (Order) updatedOrders[2];
+ Order order4FromMessage = (Order) updatedOrders[3];
+
+ assertEquals(order1FromMessage.getDiscount(),10.0);
+ assertEquals(order2FromMessage.getDiscount(),0.0);
+ assertEquals(order3FromMessage.getDiscount(),0.0);
+ assertEquals(order4FromMessage.getDiscount(),10.0);
+ System.out.println("test BRP drlStatelessCollections passed");
+
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+
+ }
+
+
+ @Test
+ public void drlStatelfulCollection()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[5]);
+ brp.process(message2);
+
+ assertEquals("10%",message2.getBody().get("DiscountObject1"));
+ assertEquals("0%",message2.getBody().get("DiscountObject2"));
+ assertEquals("0%",message2.getBody().get("DiscountObject3"));
+ assertEquals("10%",message2.getBody().get("DiscountObject4"));
+ // use arrays because we can control which element is where
+ // making it easy to compare in this test case
+ Order[] updatedOrders = (Order[]) message2.getBody().get("UpdatedOrders");
+ Order order1FromMessage = (Order) updatedOrders[0];
+ Order order2FromMessage = (Order) updatedOrders[1];
+ Order order3FromMessage = (Order) updatedOrders[2];
+ Order order4FromMessage = (Order) updatedOrders[3];
+
+ assertEquals(order1FromMessage.getDiscount(),10.0);
+ assertEquals(order2FromMessage.getDiscount(),0.0);
+ assertEquals(order3FromMessage.getDiscount(),0.0);
+ assertEquals(order4FromMessage.getDiscount(),10.0);
+ System.out.println("test BRP drlStatelessCollections passed");
+
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+
+ }
+
+
+ @Test
+ public void decisionTableStateless()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[6]);
+ brp.process(message3);
+
+ Policy policyFromMessage = (Policy) message3.getBody().get("Policy");
+ assertEquals(policyFromMessage.getBasePrice(),120);
+ System.out.println("test BRP decisionTableStateless passed");
+
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void decisionTableStateful()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[7]);
+ brp.process(message3);
+
+ Policy policyFromMessage = (Policy) message3.getBody().get("Policy");
+ assertEquals(policyFromMessage.getBasePrice(),120);
+ System.out.println("test BRP decisionTableStateful passed");
+
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void dslStateless()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[8]);
+ brp.process(message3);
+
+ Approve approveFromMessage = (Approve) message3.getBody().get("Approve");
+ assertEquals(approveFromMessage.getReason(), "Driver is safe and mature.");
+ System.out.println("test BRP dslStateless passed");
+
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void dslStateful()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[9]);
+ brp.process(message3);
+
+ Approve approveFromMessage = (Approve) message3.getBody().get("Approve");
+ assertEquals(approveFromMessage.getReason(), "Driver is safe and mature.");
+ System.out.println("test BRP dslStateful passed");
+
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void ruleAgentStateless()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[10]);
+ brp.process(message3);
+
+ Policy policyFromMessage = (Policy) message3.getBody().get("Policy");
+ assertEquals(policyFromMessage.getBasePrice(),120);
+ System.out.println("test BRP ruleAgentStateless passed");
+
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void ruleAgentStateful()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[11]);
+ brp.process(message3);
+
+ Policy policyFromMessage = (Policy) message3.getBody().get("Policy");
+ assertEquals(policyFromMessage.getBasePrice(),120);
+ System.out.println("test BRP ruleAgentStateful passed");
+
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void drlStatefulOverTime()
+ {
+ try {
+ BusinessRulesProcessor brp = new BusinessRulesProcessor(actions[12]);
+ brp.process(message4);
+
+ brp.process(message5);
+ Customer customerFromMessage5 = (Customer) message5.getBody().get("Customer");
+ assertNull(customerFromMessage5);
+
+ brp.process(message6);
+ Customer customerFromMessage6 = (Customer) message6.getBody().get("Customer");
+ assertEquals(customerFromMessage6.getDiscount(), 10);
+
+ brp.process(message7);
+ Customer customerFromMessage7 = (Customer) message7.getBody().get("Customer");
+ assertEquals(customerFromMessage7.getDiscount(), 10);
+
+ System.out.println("test BRP drlStateful with continuation passed");
+
+ } catch (ConfigurationException ce) {
+ System.out.println("Caught ConfigurationException" + ce.getMessage());
+ assertTrue(false);
+ } catch (RegistryException re) {
+ System.out.println("Caught RegistryException" + re.getMessage());
+ assertTrue(false);
+ } catch (RuleServiceException rse) {
+ System.out.println("Caught RuleServiceException" + rse.getMessage());
+ assertTrue(false);
+ } catch (ActionProcessingException ape) {
+ System.out.println("Caught ActionProcessingException" + ape.getMessage());
+ assertTrue(false);
+ }
+ }
+
+
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(BusinessRulesProcessorUnitTest.class);
+ }
+
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.xml
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.xml (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.xml 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,124 @@
+<testActions>
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="OrderDiscountRuleService"
+ ruleSet="drl/OrderDiscount.drl"
+ ruleReload="false" >
+
+ <object-path esb="body.Order" />
+
+ </action>
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="OrderDiscountRuleServiceStateful"
+ ruleSet="drl/OrderDiscount.drl"
+ ruleReload="false"
+ stateful="true" >
+
+ <object-path esb="body.Order" />
+
+ </action>
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="OrderDiscountMultipleRuleService"
+ ruleSet="drl/OrderDiscount.drl"
+ ruleReload="false" >
+
+ <object-path esb="body.Order1" />
+ <object-path esb="body.Order2" />
+ </action>
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="OrderDiscountMultipleRuleServiceStateful"
+ ruleSet="drl/OrderDiscount.drl"
+ ruleReload="false"
+ stateful="true" >
+
+ <object-path esb="body.Order1" />
+ <object-path esb="body.Order2" />
+ </action>
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="OrderDiscountCollectionsRuleService"
+ ruleSet="drl/OrderDiscountWithCollections.drl"
+ ruleReload="false" >
+
+ <object-path esb="body.Orders" />
+
+ </action>
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="OrderDiscountCollectionsRuleServiceStateful"
+ ruleSet="drl/OrderDiscountWithCollections.drl"
+ ruleReload="false"
+ stateful="true" >
+
+ <object-path esb="body.Orders" />
+
+ </action>
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="PolicyPricingRuleService"
+ decisionTable="decisionTable/PolicyPricing.xls"
+ ruleReload="false" >
+
+ <object-path esb="body.Driver" />
+ <object-path esb="body.Policy" />
+
+ </action>
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="PolicyPricingRuleServiceStateful"
+ decisionTable="decisionTable/PolicyPricing.xls"
+ ruleReload="false"
+ stateful="true" >
+
+ <object-path esb="body.Driver" />
+ <object-path esb="body.Policy" />
+
+ </action>
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="PolicyApprovalRuleService"
+ ruleSet="dsl/approval.dslr"
+ ruleLanguage="dsl/acme.dsl"
+ ruleReload="false" >
+
+ <object-path esb="body.Driver" />
+ <object-path esb="body.Policy" />
+
+ </action>
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="PolicyApprovalRuleServiceStateful"
+ ruleSet="dsl/approval.dslr"
+ ruleLanguage="dsl/acme.dsl"
+ ruleReload="false"
+ stateful="true" >
+
+ <object-path esb="body.Driver" />
+ <object-path esb="body.Policy" />
+
+ </action>
+
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="RuleAgentPolicyService"
+ ruleAgentProperties="ruleAgent/brmsdeployedrules.properties"
+ stateful="true" >
+
+ <object-path esb="body.Driver" />
+ <object-path esb="body.Policy" />
+
+ </action>
+
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="RuleAgentPolicyServiceStateful"
+ ruleAgentProperties="ruleAgent/brmsdeployedrules.properties"
+ stateful="true" >
+
+ <object-path esb="body.Driver" />
+ <object-path esb="body.Policy" />
+
+ </action>
+
+
+ <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="OrderDiscountServiceStatefulContinuation"
+ ruleSet="drl/OrderDiscountOnMultipleOrders.drl"
+ ruleReload="false"
+ stateful="true" >
+
+ <object-path esb="body.Customer" />
+ <object-path esb="body.Order" />
+ </action>
+
+
+</testActions>
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Approve.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Approve.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Approve.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,28 @@
+package org.jboss.soa.esb.services.rules;
+
+import java.io.Serializable;
+
+/**
+ * This is a simple fact class to mark something as approved.
+ * @author Michael Neale
+ *
+ */
+public class Approve implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private String reason;
+
+ public Approve(String reason) {
+ this.reason = reason;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public void setReason(String reason) {
+ this.reason = reason;
+ }
+
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Customer.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Customer.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Customer.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.soa.esb.services.rules;
+
+/**
+ * @author
+ */
+public class Customer implements java.io.Serializable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private String name;
+
+ private int discount;
+
+ public Customer(String name,
+ int discount) {
+ this.name = name;
+ this.discount = discount;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getDiscount() {
+ return discount;
+ }
+
+ public void setDiscount(int discount) {
+ this.discount = discount;
+ }
+
+
+
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Driver.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Driver.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Driver.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,44 @@
+package org.jboss.soa.esb.services.rules;
+
+import java.io.Serializable;
+
+/**
+ * This represents obviously a driver who is applying for an insurance Policy.
+ * @author Michael Neale
+ *
+ */
+public class Driver implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+ private String name = "Mr Joe Blogs";
+ private Integer age = new Integer(30);
+ private Integer priorClaims = new Integer(0);
+ private String locationRiskProfile = "LOW";
+
+ public Integer getAge() {
+ return age;
+ }
+ public void setAge(Integer age) {
+ this.age = age;
+ }
+ public String getLocationRiskProfile() {
+ return locationRiskProfile;
+ }
+ public void setLocationRiskProfile(String locationRiskProfile) {
+ this.locationRiskProfile = locationRiskProfile;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public Integer getPriorClaims() {
+ return priorClaims;
+ }
+ public void setPriorClaims(Integer priorClaims) {
+ this.priorClaims = priorClaims;
+ }
+
+
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/DroolsRuleServiceUnitTest.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/DroolsRuleServiceUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/DroolsRuleServiceUnitTest.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,662 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.services.rules;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.internal.soa.esb.services.rules.DroolsRuleService;
+import org.jboss.internal.soa.esb.services.rules.RuleServiceException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.message.mapping.ObjectMapper;
+import org.jboss.soa.esb.message.mapping.ObjectMappingException;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ * @author jdelong at redhat.com
+ *
+ */
+public class DroolsRuleServiceUnitTest
+{
+
+ Message message;
+ Message message1;
+ Message message2;
+ Message message3;
+ Message message4;
+ Message message5;
+ Message message6;
+ Message message7;
+ Message message8;
+ Message message9;
+ Message message10;
+
+ Order order;
+ Order order1;
+ Order order2;
+ Order order3;
+ Order order4;
+ Order order5;
+ Order order6;
+ Order order7;
+ Order order8;
+ Order order9;
+ Order order10;
+
+ Customer customer = new Customer( "mark", 0 );
+ Customer customer1 = new Customer( "michael", 0 );
+ Customer customer2 = new Customer( "tirelli", 0 );
+
+
+ List<Order> orders = new ArrayList();
+
+ List<Object> objectList;
+ List<Object> objectList1;
+ List<Object> objectList2;
+ List<Object> objectList3;
+ List<Object> objectList4;
+ List<Object> objectList5;
+ List<Object> objectList6;
+ List<Object> objectList7;
+ List<Object> objectList8;
+ List<Object> objectList9;
+ List<Object> objectList10;
+
+ Driver driver = new Driver();
+ Policy policy = new Policy();
+
+
+ @Before
+ public void setUpSingleOrder()
+ {
+ try {
+ //new message and order
+ message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order = new Order();
+ order.setOrderId(0);
+ order.setQuantity(20);
+ order.setUnitPrice(new Float("20.0"));
+ message.getBody().add("Order", order);
+
+ // extract the order from the message, so the drools can process it
+ List<String> messagePathList = new ArrayList<String>();
+ messagePathList.add("body.Order");
+ ObjectMapper mapper = new ObjectMapper();
+ objectList = mapper.createObjectList(message, messagePathList);
+ } catch (ObjectMappingException ome) {
+ System.out.println("Caught ObjectMappingException" + ome.getMessage());
+ }
+ }
+
+
+ @Before
+ public void setUpMultipleOrders()
+ {
+ try {
+ //new message and orders
+ message1 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order1 = new Order();
+ order1.setOrderId(1);
+ order1.setQuantity(20);
+ order1.setUnitPrice(new Float("50.0"));
+ message1.getBody().add("Order1", order1);
+
+ order2 = new Order();
+ order2.setOrderId(2);
+ order2.setQuantity(5);
+ order2.setUnitPrice(new Float("50.0"));
+ message1.getBody().add("Order2", order2);
+
+ // extract the order from the message, so drools can process it
+ List<String> messagePathList = new ArrayList<String>();
+ messagePathList.add("body.Order1");
+ messagePathList.add("body.Order2");
+ ObjectMapper mapper = new ObjectMapper();
+ objectList1 = mapper.createObjectList(message1, messagePathList);
+ //System.out.println("objectList1 has " + objectList1.size() + " elements: " + objectList1.toString());
+ } catch (ObjectMappingException ome) {
+ System.out.println("Caught ObjectMappingException" + ome.getMessage());
+ }
+ }
+
+
+ @Before
+ public void setUpOrderCollection()
+ {
+ try {
+ //new messages
+ message2 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order1 = new Order();
+ order1.setOrderId(1);
+ order1.setQuantity(20);
+ order1.setUnitPrice(new Float("50.0"));
+
+ order2 = new Order();
+ order2.setOrderId(2);
+ order2.setQuantity(5);
+ order2.setUnitPrice(new Float("50.0"));
+
+ order3 = new Order();
+ order3.setOrderId(3);
+ order3.setQuantity(9);
+ order3.setUnitPrice(new Float("50.0"));
+
+ order4 = new Order();
+ order4.setOrderId(4);
+ order4.setQuantity(25);
+ order4.setUnitPrice(new Float("50.0"));
+
+ orders.add(order1);
+ orders.add(order2);
+ orders.add(order3);
+ orders.add(order4);
+
+ message2.getBody().add("Orders", orders);
+
+
+ // extract the order from the message, so the drools can process it
+ List<String> messagePathList = new ArrayList<String>();
+ messagePathList.add("body.Orders");
+ ObjectMapper mapper = new ObjectMapper();
+ objectList2 = mapper.createObjectList(message2, messagePathList);
+ // System.out.println("objectList2 has " + objectList2.size() + " elements: " + objectList2.toString());
+ } catch (ObjectMappingException ome) {
+ System.out.println("Caught ObjectMappingException" + ome.getMessage());
+ }
+
+ }
+
+
+ @Test
+ public void drlStateless() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatelessRules("drl/OrderDiscount.drl", null, false, message, objectList);
+ assertEquals(order.getDiscount(),10.0);
+ assertEquals("10%",message.getBody().get("DiscountObject0"));
+ System.out.println("test drlStateless passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void drlStateful() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatefulRules("drl/OrderDiscount.drl", null, false, true, message, objectList);
+ assertEquals(order.getDiscount(),10.0);
+ assertEquals("10%",message.getBody().get("DiscountObject0"));
+ Order orderFromMessage = (Order) message.getBody().get("Order");
+ assertEquals(orderFromMessage.getDiscount(),10.0);
+ System.out.println("test drlStateful passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void drlStatelessMultipleObjects() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatelessRules("drl/OrderDiscount.drl", null, false, message1, objectList1);
+ assertEquals(order1.getDiscount(),10.0);
+ assertEquals(order2.getDiscount(),0.0);
+ assertEquals("10%",message1.getBody().get("DiscountObject1"));
+ assertEquals("0%",message1.getBody().get("DiscountObject2"));
+ Order order1FromMessage = (Order) message1.getBody().get("Order1");
+ assertEquals(order1FromMessage.getDiscount(),10.0);
+ Order order2FromMessage = (Order) message1.getBody().get("Order2");
+ assertEquals(order2FromMessage.getDiscount(),0.0);
+ System.out.println("test drlStatelessMultipleObjects passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void drlStatefulMultipleObjects() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatefulRules("drl/OrderDiscount.drl", null, false, true, message1, objectList1);
+ assertEquals(order1.getDiscount(),10.0);
+ assertEquals(order2.getDiscount(),0.0);
+ assertEquals("10%",message1.getBody().get("DiscountObject1"));
+ assertEquals("0%",message1.getBody().get("DiscountObject2"));
+ Order order1FromMessage = (Order) message1.getBody().get("Order1");
+ assertEquals(order1FromMessage.getDiscount(),10.0);
+ Order order2FromMessage = (Order) message1.getBody().get("Order2");
+ assertEquals(order2FromMessage.getDiscount(),0.0);
+ System.out.println("test drlStatefulMultipleObjects passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void drlStatelfulCollection() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatefulRules("drl/OrderDiscountWithCollections.drl", null, false, true, message2, objectList2);
+ assertEquals("10%",message2.getBody().get("DiscountObject1"));
+ assertEquals("0%",message2.getBody().get("DiscountObject2"));
+ assertEquals("0%",message2.getBody().get("DiscountObject3"));
+ assertEquals("10%",message2.getBody().get("DiscountObject4"));
+ // use arrays because we can control which element is where
+ // making it easy to compare in this test case
+ Order[] updatedOrders = (Order[]) message2.getBody().get("UpdatedOrders");
+ Order order1FromMessage = (Order) updatedOrders[0];
+ Order order2FromMessage = (Order) updatedOrders[1];
+ Order order3FromMessage = (Order) updatedOrders[2];
+ Order order4FromMessage = (Order) updatedOrders[3];
+
+ assertEquals(order1FromMessage.getDiscount(),10.0);
+ assertEquals(order2FromMessage.getDiscount(),0.0);
+ assertEquals(order3FromMessage.getDiscount(),0.0);
+ assertEquals(order4FromMessage.getDiscount(),10.0);
+ System.out.println("test drlStatefulCollections passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Before
+ public void setUpInsurance()
+ {
+ try {
+ //new messages
+ message3 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ driver = new Driver();
+ policy = new Policy();
+ driver.setAge(30);
+ policy.setDriver(driver);
+ message3.getBody().add("Driver", driver);
+ message3.getBody().add("Policy", policy);
+
+ // extract the order from the message, so the drools can process it
+ List<String> messagePathList = new ArrayList<String>();
+ messagePathList.add("body.Driver");
+ messagePathList.add("body.Policy");
+ ObjectMapper mapper = new ObjectMapper();
+ objectList3 = mapper.createObjectList(message3, messagePathList);
+ } catch (ObjectMappingException ome) {
+ System.out.println("Caught ObjectMappingException" + ome.getMessage());
+ }
+ }
+
+
+ @Test
+ public void decisionTableStateless() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatelessRulesFromDecisionTable("decisionTable/PolicyPricing.xls",false, message3, objectList3);
+ Policy policyFromMessage = (Policy) message3.getBody().get("Policy");
+ assertEquals(policyFromMessage.getBasePrice(),120);
+ System.out.println("test decisionTableStateless passed");
+
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void decisionTableStateful() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatefulRulesFromDecisionTable("decisionTable/PolicyPricing.xls",false, true, message3, objectList3);
+ Policy policyFromMessage = (Policy) message3.getBody().get("Policy");
+ assertEquals(policyFromMessage.getBasePrice(),120);
+ System.out.println("test decisionTableStateful passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void dslStateless() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatelessRules("dsl/approval.dslr", "dsl/acme.dsl", false, message3, objectList3);
+ //Rejection rejectionFromMessage = (Rejection) message3.getBody().get("Rejection");
+ Approve approveFromMessage = (Approve) message3.getBody().get("Approve");
+ assertEquals(approveFromMessage.getReason(), "Driver is safe and mature.");
+ System.out.println("test dslStateless passed");
+
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void dslStateful() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatefulRules("dsl/approval.dslr", "dsl/acme.dsl", false, true, message3, objectList3);
+ // Rejection rejectionFromMessage = (Rejection) message3.getBody().get("Rejection");
+ Approve approveFromMessage = (Approve) message3.getBody().get("Approve");
+ assertEquals(approveFromMessage.getReason(), "Driver is safe and mature.");
+ System.out.println("test dslStateful passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void ruleAgentStateless() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatelessRulesFromRuleAgent("ruleAgent/brmsdeployedrules.properties", message3, objectList3);
+ Policy policyFromMessage = (Policy) message3.getBody().get("Policy");
+ assertEquals(policyFromMessage.getBasePrice(),120);
+ System.out.println("test ruleAgentStateful passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Test
+ public void ruleAgentStateful() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatefulRulesFromRuleAgent("ruleAgent/brmsdeployedrules.properties", true, message3, objectList3);
+ Policy policyFromMessage = (Policy) message3.getBody().get("Policy");
+ assertEquals(policyFromMessage.getBasePrice(),120);
+ System.out.println("test ruleAgentStateful passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ @Before
+ public void setUpMultipleOrdersForStatefulOverTime()
+ {
+ try {
+ //new message with just customer
+ message4 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ message4.getBody().add("Customer", customer);
+
+ // extract the customer from the message, so drools can process it
+ List<String> messagePathList4 = new ArrayList<String>();
+ messagePathList4.add("body.Customer");
+ ObjectMapper mapper4 = new ObjectMapper();
+ objectList4 = mapper4.createObjectList(message4, messagePathList4);
+ //System.out.println("objectList4 has " + objectList4.size() + " elements: " + objectList4.toString());
+
+
+ //new message and orders
+ message5 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order5 = new Order();
+ order5.setOrderId(5);
+ order5.setQuantity(5);
+ order5.setUnitPrice(new Float("50.0"));
+ order5.setTotalPrice(order5.calculateTotalPrice());
+ order5.setCustomer(customer);
+ message5.getBody().add("Order", order5);
+
+ // extract the order from the message, so drools can process it
+ List<String> messagePathList5 = new ArrayList<String>();
+ messagePathList5.add("body.Order");
+ messagePathList5.add("body.Customer");
+ ObjectMapper mapper5 = new ObjectMapper();
+ objectList5 = mapper5.createObjectList(message5, messagePathList5);
+ //System.out.println("objectList5 has " + objectList5.size() + " elements: " + objectList5.toString());
+
+ message6 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order6 = new Order();
+ order6.setOrderId(6);
+ order6.setQuantity(10);
+ order6.setUnitPrice(new Float("80.0"));
+ order6.setTotalPrice(order6.calculateTotalPrice());
+ order6.setCustomer(customer);
+ message6.getBody().add("Order", order6);
+
+ // extract the order from the message, so drools can process it
+ List<String> messagePathList6 = new ArrayList<String>();
+ messagePathList6.add("body.Order");
+ ObjectMapper mapper6 = new ObjectMapper();
+ objectList6 = mapper6.createObjectList(message6, messagePathList6);
+ //System.out.println("objectList6 has " + objectList6.size() + " elements: " + objectList6.toString());
+
+ message7 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order7 = new Order();
+ order7.setOrderId(7);
+ order7.setQuantity(5);
+ order7.setUnitPrice(new Float("60.0"));
+ order7.setTotalPrice(order7.calculateTotalPrice());
+ order7.setCustomer(customer1);
+ message7.getBody().add("Order", order7);
+ message7.getBody().add("Customer", customer1);
+
+ // extract the order from the message, so drools can process it
+ List<String> messagePathList7 = new ArrayList<String>();
+ messagePathList7.add("body.Order");
+ messagePathList7.add("body.Customer");
+ ObjectMapper mapper7 = new ObjectMapper();
+ objectList7 = mapper7.createObjectList(message7, messagePathList7);
+ //System.out.println("objectList7 has " + objectList7.size() + " elements: " + objectList7.toString());
+
+ message8 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order8 = new Order();
+ order8.setOrderId(8);
+ order8.setQuantity(5);
+ order8.setUnitPrice(new Float("60.0"));
+ order8.setTotalPrice(order8.calculateTotalPrice());
+ order8.setCustomer(customer);
+ message8.getBody().add("Order", order8);
+
+ // extract the order from the message, so drools can process it
+ List<String> messagePathList8 = new ArrayList<String>();
+ messagePathList8.add("body.Order");
+ ObjectMapper mapper8 = new ObjectMapper();
+ objectList8 = mapper8.createObjectList(message8, messagePathList8);
+ //System.out.println("objectList8 has " + objectList8.size() + " elements: " + objectList8.toString());
+
+ message9 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order9 = new Order();
+ order9.setOrderId(9);
+ order9.setQuantity(20);
+ order9.setUnitPrice(new Float("60.0"));
+ order9.setTotalPrice(order9.calculateTotalPrice());
+ order9.setCustomer(customer1);
+ message9.getBody().add("Order", order9);
+
+ // extract the order from the message, so drools can process it
+ List<String> messagePathList9 = new ArrayList<String>();
+ messagePathList9.add("body.Order");
+ ObjectMapper mapper9 = new ObjectMapper();
+ objectList9 = mapper9.createObjectList(message9, messagePathList9);
+ //System.out.println("objectList9 has " + objectList9.size() + " elements: " + objectList9.toString());
+
+ message10 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ order10 = new Order();
+ order10.setOrderId(10);
+ order10.setQuantity(30);
+ order10.setUnitPrice(new Float("60.0"));
+ order10.setTotalPrice(order10.calculateTotalPrice());
+ order10.setCustomer(customer2);
+ message10.getBody().add("Order", order10);
+ message10.getBody().add("Customer", customer2);
+
+ // extract the order from the message, so drools can process it
+ List<String> messagePathList10 = new ArrayList<String>();
+ messagePathList10.add("body.Order");
+ messagePathList10.add("body.Customer");
+ ObjectMapper mapper10 = new ObjectMapper();
+ objectList10 = mapper10.createObjectList(message10, messagePathList10);
+ //System.out.println("objectList10 has " + objectList10.size() + " elements: " + objectList10.toString());
+
+ } catch (ObjectMappingException ome) {
+ System.out.println("Caught ObjectMappingException" + ome.getMessage());
+ }
+ }
+
+ @Test
+ public void drlStatefulOverTime() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatefulRules("drl/OrderDiscountOnMultipleOrders.drl", null, false, false, message4, objectList4);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders.drl", false, message5, objectList5);
+ Customer customerFromMessage5 = (Customer) message5.getBody().get("Customer");
+ assertNull(customerFromMessage5);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders.drl", false, message6, objectList6);
+ Customer customerFromMessage6 = (Customer) message6.getBody().get("Customer");
+ assertEquals(customerFromMessage6.getDiscount(), 10);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders.drl", false, message7, objectList7);
+ Customer customerFromMessage7 = (Customer) message7.getBody().get("Customer");
+ assertEquals(customerFromMessage7.getDiscount(), 0);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders.drl", false, message8, objectList8);
+ Customer customerFromMessage8 = (Customer) message8.getBody().get("Customer");
+ assertEquals(customerFromMessage8.getDiscount(), 10);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders.drl", false, message9, objectList9);
+ Customer customerFromMessage9 = (Customer) message9.getBody().get("Customer");
+ assertEquals(customerFromMessage9.getDiscount(), 10);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders.drl", true, message10, objectList10);
+ Customer customerFromMessage10 = (Customer) message10.getBody().get("Customer");
+ assertEquals(customerFromMessage10.getDiscount(), 10);
+
+ System.out.println("test drlStateful with continuation passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void drlStatefulOverTime2() throws ObjectMappingException
+ {
+ DroolsRuleService droolsRuleService = new DroolsRuleService();
+ try {
+ droolsRuleService.executeStatefulRules("drl/OrderDiscountOnMultipleOrders2.drl", null, false, false, message4, objectList4);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders2.drl", false, message5, objectList5);
+ Customer customerFromMessage5 = (Customer) message5.getBody().get("Customer");
+ assertNull(customerFromMessage5);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders2.drl", false, message6, objectList6);
+ Order orderFromMessage6 = (Order) message6.getBody().get("Order");
+ assertEquals(orderFromMessage6.getDiscount(), 10.0);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders2.drl", false, message7, objectList7);
+ Order orderFromMessage7 = (Order) message7.getBody().get("Order");
+ assertEquals(orderFromMessage7.getDiscount(), -10.0);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders2.drl", false, message8, objectList8);
+ Order orderFromMessage8 = (Order) message8.getBody().get("Order");
+ assertEquals(orderFromMessage8.getDiscount(), 10.0);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders2.drl", false, message9, objectList9);
+ Order orderFromMessage9 = (Order) message9.getBody().get("Order");
+ assertEquals(orderFromMessage9.getDiscount(), 10.0);
+
+ droolsRuleService.continueStatefulRulesExecution("drl/OrderDiscountOnMultipleOrders2.drl", true, message10, objectList10);
+ Order orderFromMessage10 = (Order) message10.getBody().get("Order");
+ assertEquals(orderFromMessage10.getDiscount(), 10.0);
+
+ System.out.println("test drlStateful with continuation passed");
+
+ } catch (RuleServiceException rse) {
+ System.out.println("Exception was thrown.");
+ rse.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(DroolsRuleServiceUnitTest.class);
+ }
+
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Order.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Order.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Order.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2007
+ */
+package org.jboss.soa.esb.services.rules;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * @author kstam
+ *
+ */
+public class Order implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+ private int orderId;
+ private int quantity;
+ private Float unitPrice;
+ private double discount;
+ private Float totalPrice;
+ private Customer customer;
+
+ public double getDiscount() {
+ return discount;
+ }
+ public void setDiscount(double discount) {
+ this.discount = discount;
+ }
+ public int getQuantity() {
+ return quantity;
+ }
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+ public Float getTotalPrice() {
+ this.totalPrice = calculateTotalPrice();
+ return totalPrice;
+ }
+ public void setTotalPrice(Float totalPrice) {
+ this.totalPrice = totalPrice;
+ }
+ public Float getUnitPrice() {
+ return unitPrice;
+ }
+ public void setUnitPrice(Float unitPrice) {
+ this.unitPrice = unitPrice;
+ }
+ public int getOrderId() {
+ return orderId;
+ }
+ public void setOrderId(int orderId) {
+ this.orderId = orderId;
+ }
+ public Customer getCustomer() {
+ return customer;
+ }
+ public void setCustomer(Customer customer) {
+ this.customer = customer;
+ }
+
+ public Float calculateTotalPrice() {
+ return quantity * unitPrice;
+ }
+
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Policy.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Policy.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Policy.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,59 @@
+package org.jboss.soa.esb.services.rules;
+
+import java.io.Serializable;
+
+/**
+ * This represents a policy that a driver is applying for.
+ *
+ * Obviously in the real world, there are actuaries to mess things up, but lets just pretend there is
+ * some simple base price and discount that we can calculate with relatively simple rules !
+ *
+ * @author Michael Neale
+ */
+public class Policy implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+ private String type = "COMPREHENSIVE";
+ private boolean approved = false;
+ private int discountPercent = 0;
+ private int basePrice;
+ private Driver driver;
+
+ public boolean isApproved() {
+ return approved;
+ }
+ public void setApproved(boolean approved) {
+ this.approved = approved;
+ }
+ public int getDiscountPercent() {
+ return discountPercent;
+ }
+ public void setDiscountPercent(int discountPercent) {
+ this.discountPercent = discountPercent;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public void applyDiscount(int discount) {
+ discountPercent += discount;
+ }
+ public int getBasePrice() {
+ return basePrice;
+ }
+ public void setBasePrice(int basePrice) {
+ this.basePrice = basePrice;
+ }
+ public Driver getDriver() {
+ return driver;
+ }
+ public void setDriver(Driver driver) {
+ this.driver = driver;
+ }
+
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Rejection.java
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Rejection.java (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/rules/Rejection.java 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,27 @@
+package org.jboss.soa.esb.services.rules;
+
+import java.io.Serializable;
+
+/**
+ *
+ * @author Michael Neale
+ */
+public class Rejection implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private String reason;
+
+ public Rejection(String reason) {
+ this.reason = reason;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public void setReason(String reason) {
+ this.reason = reason;
+ }
+
+}
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/cache/http%3A%2F%2Flocalhost%3A8080%2Fdrools-jbrms%2Forg.drools.brms.JBRMS%2Fpackage%2Forg.jboss.soa.esb.services.rules%2FLATEST
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/cache/http%3A%2F%2Flocalhost%3A8080%2Fdrools-jbrms%2Forg.drools.brms.JBRMS%2Fpackage%2Forg.jboss.soa.esb.services.rules%2FLATEST
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscount.drl
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscount.drl (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscount.drl 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,33 @@
+#created on: Oct 23, 2007
+package org.jboss.soa.esb.services.rules
+
+#list any import classes here.
+import org.jboss.soa.esb.services.rules.Order;
+
+#declare any global variables here
+global org.jboss.soa.esb.message.Message message;
+
+
+rule "Pricing Rule - low quantity"
+
+ when
+ order : Order( quantity < 10)
+ then
+ System.out.println("low volume");
+ #we can modify the object
+ order.setDiscount(0);
+ #demonstrate that we can add a new object to the message
+ message.getBody().add("DiscountObject"+ order.getOrderId(),"0%");
+end
+
+rule "Prioing Rule - high quantity"
+
+ when
+ order : Order( quantity >= 10)
+ then
+ System.out.println("high volume");
+ #we can modify the object
+ order.setDiscount(10);
+ #demonstrate that we can add a new object to the message
+ message.getBody().add("DiscountObject"+order.getOrderId(),"10%");
+end
\ No newline at end of file
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountOnMultipleOrders.drl
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountOnMultipleOrders.drl (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountOnMultipleOrders.drl 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,28 @@
+#created on: Oct 22, 2007
+package org.jboss.soa.esb.services.rules
+
+#list any import classes here.
+import org.jboss.soa.esb.services.rules.Order;
+import org.jboss.soa.esb.services.rules.Customer;
+
+import java.util.Arrays;
+
+#declare any global variables here
+global org.jboss.soa.esb.message.Message message;
+
+
+
+rule "Apply 10% discount if totalPrice of all orders is over 100"
+ no-loop true
+ dialect "java"
+ when
+ $c : Customer()
+ $i : Number(intValue >= 1000) from accumulate ( Order( customer == $c, $totalPrice : totalPrice),
+ sum( $totalPrice ) );
+ then
+ $c.setDiscount( 10 );
+ System.out.println( "Customer " + $c.getName() + " now has a shopping total of " + $i );
+ message.getBody().add("Customer", $c);
+ System.out.println( "Message has a Customer " + message.getBody().get("Customer").toString() );
+end
+
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountOnMultipleOrders2.drl
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountOnMultipleOrders2.drl (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountOnMultipleOrders2.drl 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,69 @@
+#created on: Oct 22, 2007
+package org.jboss.soa.esb.services.rules
+
+#list any import classes here.
+import org.jboss.soa.esb.services.rules.Order;
+import org.jboss.soa.esb.services.rules.Customer;
+
+import java.util.Arrays;
+
+#declare any global variables here
+global org.jboss.soa.esb.message.Message message;
+
+
+
+rule "Apply 10% discount if totalPrice of all orders is over 1000"
+ no-loop true
+ dialect "java"
+ when
+ $c : Customer(discount == 0)
+ $o : Order(customer == $c, discount == 0)
+ $i : Number(intValue >= 1000) from accumulate ( Order( customer == $c, $totalPrice : totalPrice),
+ sum( $totalPrice ) );
+
+
+ then
+ #$c.setDiscount(10);
+ $o.setDiscount(10);
+ System.out.println("set discount on order " + $o.getOrderId());
+ System.out.println( "Customer " + $c.getName() + " now has a shopping total of " + $i + " and a discount" );
+ #message.getBody().add("Customer", $c);
+ #System.out.println( "Message has a Customer " + message.getBody().get("Customer").toString() );
+ # System.out.println( "Message has a Customer " + message.getBody().get("CustomerWithDiscount").toString() );
+ #update ($c);
+end
+
+rule "Apply -10% discount if totalPrice of all orders is less than 1000"
+ no-loop true
+ dialect "java"
+ when
+ $c : Customer(discount == 0)
+ $o : Order(customer == $c, discount == 0)
+ $i : Number(intValue < 1000) from accumulate ( Order( customer == $c, $totalPrice : totalPrice),
+ sum( $totalPrice ) );
+
+
+ then
+ #System.out.println("The totalOrder value for order: " + $o.getOrderId() + " is: " + $o.getTotalPrice());
+ $o.setDiscount(-10);
+ #$c.setDiscount(10);
+ System.out.println("set negative discount on order " + $o.getOrderId());
+ System.out.println( "Customer " + $c.getName() + " now has a shopping total of " + $i + " and no discount" );
+ # message.getBody().add("CustomerWithDiscount", $c);
+ # message.getBody().add("Customer", $c);
+ #System.out.println( "Message has a Customer " + message.getBody().get("Customer").toString() );
+ # System.out.println( "Message has a Customer " + message.getBody().get("CustomerWithDiscount").toString() );
+ # update ($o);
+end
+
+#rule "apply discount to order"
+# no-loop true
+# when
+# $c : Customer(discount > 0)
+# $o : Order(discount == 0)
+# then
+# $o.setDiscount($c.getDiscount());
+# System.out.println("set discount on order " + $o.getOrderId());
+# update ($o);
+#end
+
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountWithCollections.drl
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountWithCollections.drl (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/drl/OrderDiscountWithCollections.drl 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,62 @@
+#created on: Oct 22, 2007
+package org.jboss.soa.esb.services.rules
+
+#list any import classes here.
+import org.jboss.soa.esb.services.rules.Order;
+
+import java.util.Arrays;
+
+#declare any global variables here
+global org.jboss.soa.esb.message.Message message;
+
+
+rule "Pricing Rule - create array for results"
+ # we use an array because it make the JUnit test easier to implement
+ # since we can control which order is in which position of the array
+ # for comparison purposes.
+ salience 20
+ when
+ orderCount : Integer() from accumulate( Order(),
+ init( int x = 0; ),
+ action( x++; ),
+ result( new Integer(x) ) );
+ then
+ System.out.println("the number of inserted orders is: " + orderCount);
+ insert (new Order[orderCount]);
+end
+
+rule "Pricing Rule - low quantity"
+
+ when
+ updatedOrders : Order[]()
+ order : Order( quantity < 10)
+ then
+ System.out.println("low volume");
+ # we can modify the object
+ order.setDiscount(0);
+ # we can add a new object to the message
+ message.getBody().add("DiscountObject"+ order.getOrderId(),"0%");
+ updatedOrders[order.getOrderId() - 1] = order;
+end
+
+rule "Prioing Rule - high quantity"
+
+ when
+ updatedOrders : Order[]()
+ order : Order( quantity >= 10)
+ then
+ System.out.println("high volume");
+ # we can modify the object
+ order.setDiscount(10);
+ # we can add a new object to the message
+ message.getBody().add("DiscountObject"+order.getOrderId(),"10%");
+ updatedOrders[order.getOrderId() - 1] = order;
+end
+
+rule "Pricing Rule - add array to message"
+ salience -20
+ when
+ updatedOrders : Order[]()
+ then
+ message.getBody().add("UpdatedOrders", updatedOrders);
+end
\ No newline at end of file
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/brmsdeployedrules.properties
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/brmsdeployedrules.properties (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/brmsdeployedrules.properties 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,11 @@
+newInstance=true
+
+#file=org.jboss.soa.esb.services.rules
+dir=/home/jdelong/workspace/ESBRuleService/jbrules/src/test/resources/ruleAgent/package
+
+
+#url=http://localhost:8080/drools-jbrms/org.drools.brms.JBRMS/package/org.jboss.soa.esb.services.rules/LATEST
+#localCacheDir=/home/jdelong/workspace/ESBRuleService/jbrules/src/test/resources/ruleAgent/cache
+poll=30
+
+name=insuranceconfig
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/cache/http%3A%2F%2Flocalhost%3A8080%2Fdrools-jbrms%2Forg.drools.brms.JBRMS%2Fpackage%2Forg.jboss.soa.esb.services.rules%2FLATEST
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/cache/http%3A%2F%2Flocalhost%3A8080%2Fdrools-jbrms%2Forg.drools.brms.JBRMS%2Fpackage%2Forg.jboss.soa.esb.services.rules%2FLATEST
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/insurancepolicy.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/insurancepolicy.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/insurancepolicyall.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/insurancepolicyall.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/insurancepolicyold.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/insurancepolicyold.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/package/org.jboss.soa.esb.services.rules.pkg
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/package/org.jboss.soa.esb.services.rules.pkg
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/pricing.drl
===================================================================
--- labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/pricing.drl (rev 0)
+++ labs/jbossesb/workspace/jdelong/ruleservice/product/services/jbrules/src/test/resources/ruleAgent/pricing.drl 2007-11-07 05:28:03 UTC (rev 16399)
@@ -0,0 +1,63 @@
+#created on: Aug 23, 2006
+package org.jboss.soa.esb.services.rules
+
+#list any import classes here.
+import org.jboss.soa.esb.services.rules.Driver;
+import org.jboss.soa.esb.services.rules.Policy;
+
+
+#declare any global variables here
+global org.jboss.soa.esb.message.Message message;
+
+
+rule "Safe Youth"
+
+ when
+ #conditions
+ Driver(age >= 18, age <= 24, locationRiskProfile == "LOW", priorClaims == 0)
+ policy: Policy(type == "COMPREHENSIVE")
+ then
+ #actions
+ policy.setBasePrice(450);
+ System.out.println("Safe Youth - pay 450");
+
+end
+
+rule "Risky Youth"
+
+ when
+ #conditions
+ Driver(age >= 18, age <= 24, locationRiskProfile == "LOW", priorClaims >= 1)
+ policy : Policy(type == "COMPREHENSIVE")
+ then
+ #actions
+ policy.setBasePrice(700);
+ System.out.println("Risky Youth - pay 700");
+
+end
+
+rule "Safe Adult"
+
+ when
+ #conditions
+ Driver(age > 24, locationRiskProfile == "LOW", priorClaims == 0)
+ policy: Policy(type == "COMPREHENSIVE")
+ then
+ #actions
+ policy.setBasePrice(120);
+ System.out.println("Safe adult - pay 120");
+
+end
+
+rule "Risky Adult"
+
+ when
+ #conditions
+ Driver(age > 24, locationRiskProfile == "LOW", priorClaims >= 1)
+ policy: Policy(type == "COMPREHENSIVE")
+ then
+ #actions
+ policy.setBasePrice(300);
+ System.out.println("Risky adult - pay 300");
+
+end
\ No newline at end of file
More information about the jboss-svn-commits
mailing list