[jboss-svn-commits] JBL Code SVN: r20571 - in labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src: main/java/org/jboss/soa/esb/actions and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jun 18 05:08:59 EDT 2008
Author: beve
Date: 2008-06-18 05:08:59 -0400 (Wed, 18 Jun 2008)
New Revision: 20571
Modified:
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleBaseHelper.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleService.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceBuilderException.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceCallHelper.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceException.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceFactory.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/BusinessRulesProcessor.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleService.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleServicePropertiesNames.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleServiceUnitTest.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/CBRConfigTreeBuilder.java
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/resources/JBossESBPricingRulesStateful.drl
labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/resources/JBossESBRules.drl
Log:
Updates to RuleService interface.
Added more test.
Added javadocs
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleBaseHelper.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleBaseHelper.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleBaseHelper.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -19,6 +19,7 @@
* 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;
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleService.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleService.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleService.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -23,6 +23,8 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -53,6 +55,10 @@
*
*/
public class DroolsRuleService implements RuleService {
+
+ private List<String> decisionTableSuffixes = Collections.unmodifiableList( new ArrayList<String>(Arrays.asList( new String[] { ".xls", ".csv" } ) ) );
+ private List<String> ruleAgentSuffixes = Collections.unmodifiableList( new ArrayList<String>(Arrays.asList( new String[] { ".properties" } ) ) );
+ private List<String> ruleFileSuffixes = Collections.unmodifiableList( new ArrayList<String>(Arrays.asList( new String[] { ".drl" } ) ) );
/**
* The lifecycle resource factory for RuleBases.
@@ -112,18 +118,19 @@
final long startTime = System.nanoTime();
- try {
+ try
+ {
RuleBase ruleBase = getRuleBaseForFileBasedRules(ruleSet, dsl, ruleReload);
message = executeStatelessRules(ruleBase, message, globals, objectList);
updateJBRulesCounter( startTime, ruleSet, JBRulesCounter.RULES_SUCCEED );
-
- return message;
-
- } catch (RuleServiceException ree) {
+ }
+ catch (RuleServiceException ree)
+ {
updateJBRulesCounter( startTime, ruleSet, JBRulesCounter.RULES_FAILED );
throw new RuleServiceException("Could not parse the rules. " + ree.getMessage(), ree);
}
+ return message;
}
/**
@@ -209,15 +216,15 @@
return message;
}
- catch (IOException ioe)
+ catch (IOException e)
{
updateJBRulesCounter( startTime, ruleAgentProperties, JBRulesCounter.RULES_FAILED );
- throw new RuleServiceException( "Could not read the ruleAgentProperties. " + ioe.getMessage(), ioe);
+ throw new RuleServiceException( "Could not read the ruleAgentProperties. " + e.getMessage(), e);
}
- catch (RuleServiceException ree)
+ catch (RuleServiceException e)
{
updateJBRulesCounter( startTime, ruleAgentProperties, JBRulesCounter.RULES_FAILED );
- throw new RuleServiceException("Could not parse the rules. " + ree.getMessage(), ree);
+ throw new RuleServiceException("Could not parse the rules. " + e.getMessage(), e);
}
catch (Exception e)
{
@@ -237,8 +244,6 @@
* @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 globals -
@@ -252,7 +257,6 @@
final String ruleSet,
final String dsl,
final boolean ruleReload,
- final boolean dispose,
Message message,
final Map<String,Object> globals,
final List<Object> objectList) throws RuleServiceException
@@ -264,18 +268,16 @@
try
{
RuleBase ruleBase = getRuleBaseForFileBasedRules(ruleSet, dsl, ruleReload);
- message = executeStatefulRules(ruleBase, dispose, message, globals, objectList);
+ message = executeStatefulRules(ruleBase, false, message, globals, objectList);
updateJBRulesCounter( startTime, ruleSet, JBRulesCounter.RULES_SUCCEED);
-
- return message;
-
}
catch (RuleServiceException e)
{
updateJBRulesCounter( startTime, ruleSet, JBRulesCounter.RULES_FAILED );
throw new RuleServiceException("Could not parse the rules. " + e.getMessage(), e);
}
+ return message;
}
/**
@@ -286,8 +288,6 @@
* @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 globals -
@@ -300,7 +300,6 @@
public Message executeStatefulRulesFromDecisionTable(
final String decisionTable,
final boolean ruleReload,
- final boolean dispose,
Message message,
final Map<String,Object> globals,
final List<Object> objectList) throws RuleServiceException
@@ -312,18 +311,16 @@
try
{
RuleBase ruleBase = getRuleBaseForDecisionTable(decisionTable, ruleReload);
- message = executeStatefulRules(ruleBase, dispose, message, globals, objectList);
+ message = executeStatefulRules(ruleBase, false, message, globals, objectList);
updateJBRulesCounter( startTime, decisionTable, JBRulesCounter.RULES_SUCCEED );
-
- return message;
-
}
catch (RuleServiceException e)
{
updateJBRulesCounter( startTime, decisionTable, JBRulesCounter.RULES_FAILED );
throw new RuleServiceException("Could not parse the rules. " + e.getMessage(), e);
}
+ return message;
}
/**
@@ -332,8 +329,6 @@
*
* @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 globals -
@@ -345,7 +340,6 @@
*/
public Message executeStatefulRulesFromRuleAgent(
final String ruleAgentProperties,
- final boolean dispose,
Message message,
final Map<String,Object> globals,
final List<Object> objectList) throws RuleServiceException
@@ -363,13 +357,10 @@
{
ruleBases.put(ruleAgentProperties, ruleBase);
- message = executeStatefulRules(ruleBase, dispose, message, globals, objectList);
+ message = executeStatefulRules(ruleBase, false, message, globals, objectList);
updateJBRulesCounter( startTime, ruleAgentProperties, JBRulesCounter.RULES_SUCCEED );
}
-
- return message;
-
}
catch (IOException e)
{
@@ -386,6 +377,7 @@
updateJBRulesCounter( startTime, ruleAgentProperties, JBRulesCounter.RULES_FAILED );
throw new RuleServiceException( "RuleAgent could not get the RuleBase. " + e.getMessage(), e);
}
+ return message;
}
/**
@@ -404,8 +396,6 @@
* working memory
*
* @return Message with updated objects.
- * TODO: Is this method really needed. Can we not simply check for
- * existing StatefulSessions in executeStatefulRules? /Daniel
*/
public Message continueStatefulRulesExecution(
final String rules,
@@ -414,7 +404,6 @@
Map<String,Object> globals,
final List<Object> objectList) throws RuleServiceException
{
- /*
AssertArgument.isNotNullAndNotEmpty( rules, "rules" );
final long startTime = System.nanoTime();
@@ -422,43 +411,20 @@
try
{
final Map<String, RuleBase> ruleBases = lifecycleRuleBases.getLifecycleResource();
+ final RuleBase ruleBase = ruleBases.get(rules);
+
+ message = executeStatefulRules(ruleBase, dispose, message, globals, objectList);
- 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);
-
- addGlobalsVariables( statefulSession, globals );
- 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();
- }
-
updateJBRulesCounter( startTime, rules, JBRulesCounter.RULES_SUCCEED );
return message;
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
updateJBRulesCounter( startTime, rules, JBRulesCounter.RULES_FAILED );
throw new RuleServiceException( "Could not continue rule execution. " + e.getMessage(), e);
}
- */
- return message;
}
public void setConfigTree( final ConfigTree configTree )
@@ -467,6 +433,47 @@
rulesCounter.registerMBean();
}
+ private void updateJBRulesCounter( final long startTime , final String rules, final String result )
+ {
+ if (rulesCounter != null)
+ {
+ long procTime = System.nanoTime() - startTime;
+ rulesCounter.update(procTime, rules, result );
+ }
+ }
+
+ public boolean acceptsDecisionTable( final String fileName )
+ {
+ return decisionTableSuffixes.contains( getSuffix( fileName ) );
+ }
+
+
+ public boolean acceptsRuleAgent( final String fileName )
+ {
+ return ruleAgentSuffixes.contains( getSuffix( fileName ) );
+ }
+
+ public boolean acceptsRuleFile( final String fileName )
+ {
+ return ruleFileSuffixes.contains( getSuffix( fileName ) );
+ }
+
+
+ public List<String> getSupportedDecsionTableSuffixes()
+ {
+ return decisionTableSuffixes;
+ }
+
+ public List<String> getSupportedRuleAgentSuffixes()
+ {
+ return ruleAgentSuffixes;
+ }
+
+ public List<String> getSupportedRuleFileSuffixes()
+ {
+ return ruleFileSuffixes;
+ }
+
/**
* Determine if file based rules need reloading and return the rulebase
*
@@ -661,7 +668,12 @@
finally
{
if ( dispose )
- statefulSession.dispose();
+ {
+ for ( StatefulSession session : ruleBase.getStatefulSessions())
+ {
+ session.dispose();
+ }
+ }
}
return message;
@@ -711,7 +723,9 @@
{
Set<Entry<String, Object>> entrySet = globals.entrySet();
for ( Entry<String, Object> entry : entrySet )
+ {
statefulSession.setGlobal( entry.getKey(), entry.getValue() );
+ }
}
}
@@ -809,25 +823,21 @@
private void insertObjectsIntoWorkingMemory(final List<Object> objectList, final WorkingMemory workingMemory)
{
if (objectList != null)
+ {
for (Object object : objectList)
+ {
workingMemory.insert(object);
- }
-
- private void updateJBRulesCounter( final long startTime , final String rules, final String result )
- {
- if (rulesCounter != null)
- {
- long procTime = System.nanoTime() - startTime;
- rulesCounter.update(procTime, rules, result );
+ }
}
}
- public static boolean isDecisionTable( final String ruleSet )
+
+
+ private String getSuffix ( final String fileName )
{
- if ( ruleSet == null )
- throw new NullPointerException("[ruleSet] argument was null");
+ if ( fileName == null )
+ throw new NullPointerException("[fileName] argument was null");
- return ruleSet.endsWith( ".xls" ) || ruleSet.endsWith( ".csv" );
-
+ return fileName.substring( fileName.lastIndexOf( '.' ) );
}
}
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceBuilderException.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceBuilderException.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceBuilderException.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -1,24 +1,25 @@
/*
- * 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.
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * 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.drools.compiler.PackageBuilderErrors;
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceCallHelper.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceCallHelper.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceCallHelper.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -1,38 +1,40 @@
/*
- * 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.
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * 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 static org.jboss.soa.esb.services.rules.RuleServicePropertiesNames.*;
+import static org.jboss.soa.esb.services.rules.RuleServicePropertiesNames.DISPOSE;
+import static org.jboss.soa.esb.services.rules.RuleServicePropertiesNames.IMPL_CLASS;
+import static org.jboss.soa.esb.services.rules.RuleServicePropertiesNames.STATEFUL;
+import static org.jboss.soa.esb.services.rules.RuleServicePropertiesNames.CONTINUE;
import java.util.List;
import java.util.Map;
-import org.apache.log4j.Logger;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.rules.RuleService;
/**
- * RuleServiceCallHelper is a singleton helper class for calling
+ * RuleServiceCallHelper is a util class for calling
* methods on a {@link RuleService} implementation.
* </p>
*
@@ -41,46 +43,131 @@
*/
public class RuleServiceCallHelper
{
- private static Logger log = Logger.getLogger( RuleServiceCallHelper.class );
-
private RuleServiceCallHelper()
{
throw new AssertionError();
}
- public static void executeRulesService(
+ /**
+ *
+ * @param ruleSet
+ * @param ruleLanguage
+ * @param ruleReload
+ * @param message
+ * @param objectList
+ * @param globals
+ * @param configTree
+ * @return
+ * @throws RuleServiceException
+ */
+ public static Message executeRulesService(
final String ruleSet,
final String ruleLanguage,
final boolean ruleReload,
- final Message message,
+ Message message,
final List<Object> objectList,
final Map<String, Object> globals,
final ConfigTree configTree ) throws RuleServiceException
{
final String ruleServiceImpl = configTree.getAttribute( IMPL_CLASS.getTagName(), "org.jboss.internal.soa.esb.services.rules.DroolsRuleService" );
- RuleService ruleService = RuleServiceFactory.getRuleService( ruleServiceImpl );
+ final RuleService ruleService = RuleServiceFactory.getRuleService( ruleServiceImpl );
ruleService.setConfigTree( configTree );
- boolean stateful = Boolean.valueOf( configTree.getAttribute( STATEFUL.getTagName()) );
+ final Boolean continueStateful = (Boolean) message.getProperties().getProperty( CONTINUE.getTagName(), Boolean.FALSE );
+ if ( continueStateful )
+ {
+ return ruleService.continueStatefulRulesExecution( ruleSet, getDisposeProperty( message ), message, globals, objectList );
+ }
- boolean dispose = Boolean.valueOf( (String) message.getProperties().getProperty( DISPOSE.getTagName(), "true" ) );
-
- log.debug( "Stateful [" + stateful + "]" );
- log.debug( "dispose [" + dispose + "]" );
- if ( DroolsRuleService.isDecisionTable( ruleSet ) )
+ final boolean stateful = Boolean.valueOf( configTree.getAttribute( STATEFUL.getTagName()) );
+
+ if ( stateful )
{
- if ( stateful )
- ruleService.executeStatefulRulesFromDecisionTable( ruleSet, ruleReload, dispose, message, globals, objectList );
- else
- ruleService.executeStatelessRulesFromDecisionTable( ruleSet, ruleReload, message, globals, objectList );
+ return executeStatefulRules( ruleService, ruleSet, ruleLanguage, ruleReload, message, globals, objectList );
}
else
{
- if ( stateful )
- ruleService.executeStatefulRules( ruleSet, ruleLanguage, ruleReload, dispose, message, globals, objectList );
- else
- ruleService.executeStatelessRules( ruleSet, ruleLanguage, ruleReload, message, globals, objectList );
+ return executeStatelessRules( ruleService, ruleSet, ruleLanguage, ruleReload, message, globals, objectList );
}
}
+
+ // private static methods
+
+ private static Message executeStatefulRules(
+ RuleService ruleService,
+ final String ruleSet,
+ final String dsl,
+ final boolean ruleReload,
+ Message message,
+ final Map<String,Object> globals,
+ final List<Object> objectList) throws RuleServiceException
+ {
+ if ( ruleService.acceptsDecisionTable( ruleSet ) )
+ {
+ message = ruleService.executeStatefulRulesFromDecisionTable( ruleSet, ruleReload, message, globals, objectList );
+ }
+ else if ( ruleService.acceptsRuleAgent( ruleSet ) )
+ {
+ message = ruleService.executeStatefulRulesFromRuleAgent( ruleSet, message, globals, objectList );
+ }
+ else if ( ruleService.acceptsRuleFile( ruleSet ) )
+ {
+ message = ruleService.executeStatefulRules( ruleSet, dsl, ruleReload, message, globals, objectList );
+ }
+ return message;
+ }
+
+ private static Message executeStatelessRules(
+ RuleService ruleService,
+ final String ruleSet,
+ final String dsl,
+ final boolean ruleReload,
+ Message message,
+ final Map<String,Object> globals,
+ final List<Object> objectList) throws RuleServiceException
+ {
+ if ( ruleService.acceptsDecisionTable( ruleSet ) )
+ {
+ message = ruleService.executeStatelessRulesFromDecisionTable( ruleSet, ruleReload, message, globals, objectList );
+ }
+ else if ( ruleService.acceptsRuleAgent( ruleSet ) )
+ {
+ message = ruleService.executeStatelessRulesFromRuleAgent( ruleSet, message, globals, objectList );
+ }
+ else if ( ruleService.acceptsRuleFile( ruleSet ) )
+ {
+ message = ruleService.executeStatelessRules( ruleSet, dsl, ruleReload, message, globals, objectList );
+ }
+ else
+ {
+ throwRuleExceptionWithSupportedSuffixes( ruleService, ruleSet );
+ }
+
+ return message;
+ }
+
+ private static void throwRuleExceptionWithSupportedSuffixes( final RuleService ruleService , final String fileName ) throws RuleServiceException
+ {
+ String lineSeparator = System.getProperty( "line.separator" );
+ throw new RuleServiceException(
+ "The RuleService does not recognize the type of file : [" + fileName + "]." +
+ "The RuleService accepts the following decision table type(s): " + ruleService.getSupportedDecsionTableSuffixes() +
+ lineSeparator +
+ ", and these rule agent type(s) " + ruleService.getSupportedRuleAgentSuffixes() +
+ lineSeparator +
+ ", and these rule file types(s) : " + ruleService.getSupportedRuleFileSuffixes());
+ }
+ private static boolean getDisposeProperty( final Message message ) throws RuleServiceException
+ {
+ Object dispose = message.getProperties().getProperty( DISPOSE.getTagName() );
+ if ( dispose == null )
+ {
+ throw new RuleServiceException("The property [" + DISPOSE.getTagName() + "] must be specified when [" +
+ CONTINUE.getTagName() + "] is true. This is required as it is important that the rules working memory "+
+ " be disposed or memory leaks can occur.");
+ }
+ return (Boolean)dispose;
+ }
+
}
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceException.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceException.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceException.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -19,6 +19,7 @@
* 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;
/**
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceFactory.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceFactory.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/rules/RuleServiceFactory.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -1,24 +1,25 @@
/*
-* 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.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * 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;
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/BusinessRulesProcessor.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/BusinessRulesProcessor.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/BusinessRulesProcessor.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -94,7 +94,7 @@
try
{
List<Object> objectList = _mapper.createObjectList(message, _messagePathList);
- executeRulesService( message, objectList );
+ message = executeRulesService( message, objectList );
}
catch (final ObjectMappingException e)
{
@@ -114,11 +114,11 @@
* @throws RuleServiceException
* @throws MessageRouterException
*/
- void executeRulesService( final Message message, final List<Object> objectList) throws RuleServiceException
+ Message executeRulesService( final Message message, final List<Object> objectList) throws RuleServiceException
{
Map<String,Object> globals = new HashMap<String,Object>();
globals.put( "message", message );
- RuleServiceCallHelper.executeRulesService( _ruleSet, _ruleLanguage, _ruleReload, message, objectList, globals, configTree ) ;
+ return RuleServiceCallHelper.executeRulesService( _ruleSet, _ruleLanguage, _ruleReload, message, objectList, globals, configTree ) ;
}
}
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleService.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleService.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleService.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -19,6 +19,7 @@
* 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;
@@ -58,9 +59,13 @@
*
* @return Message with updated objects.
*/
- public Message executeStatelessRules(String ruleSet, String dsl,
- boolean ruleReload, Message message, Map<String,Object> globals, List<Object> objectList)
- throws RuleServiceException;
+ public Message executeStatelessRules(
+ String ruleSet,
+ String dsl,
+ boolean ruleReload,
+ Message message,
+ Map<String,Object> globals,
+ List<Object> objectList) throws RuleServiceException;
/**
* Execute rules from a decision table using the Stateless rule engine API
@@ -77,9 +82,12 @@
*
* @return Message with updated objects.
*/
- public Message executeStatelessRulesFromDecisionTable(String decisionTable,
- boolean ruleReload, Message message, Map<String,Object> globals, List<Object> objectList)
- throws RuleServiceException;
+ public Message executeStatelessRulesFromDecisionTable(
+ String decisionTable,
+ boolean ruleReload,
+ Message message,
+ Map<String,Object> globals,
+ List<Object> objectList) throws RuleServiceException;
/**
* Execute rules using a rule package retrieved via the Rule Agent from a URL of local file system
@@ -95,8 +103,10 @@
* @return Message with updated objects.
*/
public Message executeStatelessRulesFromRuleAgent(
- String ruleAgentProperties, Message message, Map<String,Object> globals, List<Object> objectList)
- throws RuleServiceException;
+ String ruleAgentProperties,
+ Message message,
+ Map<String,Object> globals,
+ List<Object> objectList) throws RuleServiceException;
/**
* Execute rules using a certain ruleSet and domain specific language using the Stateful rule engine API
@@ -118,8 +128,12 @@
*
* @return Message with updated objects.
*/
- public Message executeStatefulRules(String ruleSet, String dsl,
- boolean ruleReload, boolean dispose, Message message,Map<String,Object> globals,
+ public Message executeStatefulRules(
+ String ruleSet,
+ String dsl,
+ boolean ruleReload,
+ Message message,
+ Map<String,Object> globals,
List<Object> objectList) throws RuleServiceException;
/**
@@ -139,8 +153,11 @@
*
* @return Message with updated objects.
*/
- public Message executeStatefulRulesFromDecisionTable(String decisionTable,
- boolean ruleReload, boolean dispose, Message message, Map<String,Object> globals,
+ public Message executeStatefulRulesFromDecisionTable(
+ String decisionTable,
+ boolean ruleReload,
+ Message message,
+ Map<String,Object> globals,
List<Object> objectList) throws RuleServiceException;
/**
@@ -159,7 +176,9 @@
* @return Message with updated objects.
*/
public Message executeStatefulRulesFromRuleAgent(
- String ruleAgentProperties, boolean dispose, Message message,Map<String,Object> globals,
+ String ruleAgentProperties,
+ Message message,
+ Map<String,Object> globals,
List<Object> objectList) throws RuleServiceException;
/**
@@ -177,8 +196,55 @@
*
* @return Message with updated objects.
*/
- public Message continueStatefulRulesExecution(String rules,
- boolean dispose, Message message,Map<String,Object> globals, List<Object> objectList)
- throws RuleServiceException;
-
+ public Message continueStatefulRulesExecution(
+ String rules,
+ boolean dispose,
+ Message message,
+ Map<String,Object> globals,
+ List<Object> objectList) throws RuleServiceException;
+
+ /**
+ * Determines whether this RuleService can process file of passed in type.
+ *
+ * @param fileName - rule file to be processed
+ * @return true if this RuleService can process files of the passed in type
+ */
+ public boolean acceptsDecisionTable( String fileName );
+
+ /**
+ * Get the supported decision tables suffixes
+ *
+ * @return List<String> containing all the supported suffixes by this RuleService
+ */
+ public List<String> getSupportedDecsionTableSuffixes();
+
+ /**
+ * Determines whether this RuleService can process file of passed in type.
+ *
+ * @param fileName - rule file to be processed
+ * @return true if this RuleService can process files of the passed in type
+ */
+ public boolean acceptsRuleAgent( String fileName );
+
+ /**
+ * Get the supported rule agent suffixes
+ *
+ * @return List<String> containing all the supported suffixes by this RuleService
+ */
+ public List<String> getSupportedRuleAgentSuffixes();
+
+ /**
+ * Determines whether this RuleService can process file of passed in type.
+ *
+ * @param fileName - rule file to be processed
+ * @return true if this RuleService can process files of the passed in type
+ */
+ public boolean acceptsRuleFile( String fileName );
+
+ /**
+ * Get the supported rule agent suffixes
+ *
+ * @return List<String> containing all the supported suffixes by this RuleService
+ */
+ public List<String> getSupportedRuleFileSuffixes();
}
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleServicePropertiesNames.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleServicePropertiesNames.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/main/java/org/jboss/soa/esb/services/rules/RuleServicePropertiesNames.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -19,16 +19,19 @@
* 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;
/**
- * Contains tag names as they can be used in the configuration.
+ * This enum contains properties specific for a RuleService.
+ * <p/>
*
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
*/
-package org.jboss.soa.esb.services.rules;
-
public enum RuleServicePropertiesNames {
IMPL_CLASS ( "rulsServiceImplClass" ),
- RULE_SET ( "ruleSet" ),
+ RULE_SET ( "ruleSet" ),
RULE_LANGUAGE ("ruleLanguage"),
RULE_RELOAD ( "ruleReload" ),
DECISION_TABLE ( "decisionTable" ),
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleServiceUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleServiceUnitTest.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/rules/DroolsRuleServiceUnitTest.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -1,40 +1,51 @@
/*
- * 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.
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * 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 static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import junit.framework.JUnit4TestAdapter;
+
import org.drools.RuleBase;
+import org.jboss.internal.soa.esb.services.routing.cbr.Order;
+import org.jboss.soa.esb.actions.Counter;
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;
-import junit.framework.JUnit4TestAdapter;
-
/**
* Unit test for {@link DroolsRuleService}
* <p/>
@@ -44,12 +55,18 @@
*/
public class DroolsRuleServiceUnitTest
{
+ private static final String DRL_FILE = "JBossESBRules.drl";
+
private static final String DESTINATIONS = "destinations";
private DroolsRuleService ruleService = new DroolsRuleService();
private RuleBase ruleBase;
private Message message;
+
+ private Order order;
+
+ private ArrayList<String> messagePathList;
@Test
public void executeStatefulRules() throws RuleServiceException
@@ -61,6 +78,15 @@
}
@Test
+ public void executeStatefulRulesDrl() throws RuleServiceException
+ {
+ Map<String,Object> globals = getGlobalsWithDestAndMessage();
+ message = ruleService.executeStatefulRules( DRL_FILE, null, true, message, globals, null );
+ ArrayList<String> destinations = getDistinations( globals );
+ assertTrue( destinations.size() == 1 );
+ }
+
+ @Test
public void executeStatelessRules()
{
Map<String,Object> globals = getGlobalsWithDestAndMessage();
@@ -70,11 +96,40 @@
}
@Test
- public void executeStatelessRulesContinueSession()
+ public void executeStatefulRulesContinueSession() throws RuleServiceException, ObjectMappingException
{
- Map<String,Object> globals = getGlobalsWithDestAndMessage();
- message = ruleService.executeStatefulRules( ruleBase, true, message , globals, null );
+ Message message = createMessageWithOrder( order );
+ Map<String,Object> globals = getGlobalsWithMessage( message );
+ ArrayList<String> messagePathList = new ArrayList<String>();
+ messagePathList.add("body.Order");
+ messagePathList.add("body.Counter");
+
+ List<Object> objectList = new ObjectMapper().createObjectList(message, messagePathList);
+ // process message
+ message = ruleService.executeStatefulRules( "JBossESBPricingRulesStateful.drl", null, true, message, globals, objectList );
+ assertEquals( 20.0, order.getDiscount() );
+ assertEquals( "20%" ,message.getBody().get("DiscountObject"));
+
+ // process message again with a counter instance
+ objectList = new ObjectMapper().createObjectList(message, messagePathList);
+ //message = ruleService.executeStatefulRules( "JBossESBPricingRulesStateful.drl", null, false, false, message, globals, objectList );
+ message = ruleService.continueStatefulRulesExecution( "JBossESBPricingRulesStateful.drl", true, message, globals, objectList );
+
+ Counter counter = (Counter) message.getBody().get("Counter");
+ System.out.println(counter.getCounter());
+
+ assertEquals( 2 , counter.getCounter() );
+
+ }
+
+ @Test
+ public void executeStatefulRulesFromRuleAgent() throws RuleServiceException
+ {
+ Map<String,Object> globals = getGlobalsWithDest();
+
+ message = ruleService.executeStatefulRulesFromRuleAgent( "RuleBaseHelper.properties", message , globals, null );
+
ArrayList<String> destinations = getDistinations( globals );
assertTrue( destinations.size() == 1 );
@@ -83,13 +138,91 @@
assertTrue( "Should have added a second destination to the existing global", destinations.size() == 2 );
}
+ @Test
+ public void getSupportedDecsionTableSuffixes()
+ {
+ List<String> suffixes = ruleService.getSupportedDecsionTableSuffixes();
+ assertNotNull ( suffixes );
+ assertEquals ( 2 , suffixes.size() );
+ try
+ {
+ suffixes.add( ".xxx" );
+ }
+ catch (Exception e )
+ {
+ assertTrue( e instanceof UnsupportedOperationException );
+ }
+ }
+
+ @Test
+ public void getSupportedRuleAgentSuffixes()
+ {
+ List<String> suffixes = ruleService.getSupportedRuleAgentSuffixes();
+ assertNotNull ( suffixes );
+ assertEquals ( 1 , suffixes.size() );
+ try
+ {
+ suffixes.add( ".xxx" );
+ }
+ catch (Exception e )
+ {
+ assertTrue( e instanceof UnsupportedOperationException );
+ }
+ }
+
+ @Test
+ public void getSupportedRuleFileSuffixes()
+ {
+ List<String> suffixes = ruleService.getSupportedRuleFileSuffixes();
+ assertNotNull ( suffixes );
+ assertEquals ( 1 , suffixes.size() );
+ try
+ {
+ suffixes.add( ".xxx" );
+ }
+ catch (Exception e )
+ {
+ assertTrue( e instanceof UnsupportedOperationException );
+ }
+ }
+
+ @Test
+ public void acceptsDecisionTable( )
+ {
+ assertTrue ( ruleService.acceptsDecisionTable( "Helper.xls" ) );
+ assertTrue ( ruleService.acceptsDecisionTable( "Helper.csv" ) );
+ assertFalse ( ruleService.acceptsDecisionTable( "Helper.cvs" ) );
+ }
+
+ @Test
+ public void acceptsRuleAgentTable( )
+ {
+ assertTrue ( ruleService.acceptsRuleAgent( "Helper.properties" ) );
+ assertFalse ( ruleService.acceptsRuleAgent( "Helper.csv" ) );
+ }
+
+ @Test
+ public void acceptsRuleFileTable( )
+ {
+ assertTrue ( ruleService.acceptsRuleFile( "Helper.drl" ) );
+ assertFalse ( ruleService.acceptsRuleFile( "Helper.csv" ) );
+ }
+
// Test setup methods
@Before
public void setup() throws RuleServiceException
{
- ruleBase = ruleService.getRuleBaseForFileBasedRules( "JBossESBRules.drl", null, true );
+ ruleBase = ruleService.getRuleBaseForFileBasedRules( DRL_FILE, null, true );
message = MessageFactory.getInstance().getMessage();
+
+ order = new Order();
+ order.setQuantity(20);
+ order.setUnitPrice( new BigDecimal("20.0") );
+
+ messagePathList = new ArrayList<String>();
+ messagePathList.add("body.Order");
+ messagePathList.add("body.Counter");
}
public static junit.framework.Test suite()
@@ -113,4 +246,26 @@
globals.put("message", message );
return globals;
}
+
+ private Map<String,Object> getGlobalsWithDest()
+ {
+ Map<String,Object> globals = new HashMap<String,Object>();
+ ArrayList<String> destinations = new ArrayList<String>();
+ globals.put(DESTINATIONS, destinations );
+ return globals;
+ }
+
+ private Map<String,Object> getGlobalsWithMessage( final Message message )
+ {
+ Map<String,Object> globals = new HashMap<String,Object>();
+ globals.put("message", message );
+ return globals;
+ }
+
+ private Message createMessageWithOrder( final Order order )
+ {
+ Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ message.getBody().add("Order", order);
+ return message;
+ }
}
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/BusinessRulesProcessorUnitTest.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -1,23 +1,23 @@
/*
- * 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.
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * 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;
@@ -51,7 +51,6 @@
*/
public class BusinessRulesProcessorUnitTest
{
- private static final String DROOLS_STATFUL_RULESET = "JBossESBPricingRulesStateful.drl";
private Order order;
private ArrayList<String> messagePathList;
@@ -59,7 +58,7 @@
public void processDiscount() throws ObjectMappingException, ConfigurationException, RegistryException, MessageRouterException, ActionProcessingException
{
Message message = createMessageWithOrder( order );
- ConfigTree configTree = new CBRConfigTreeBuilder( DROOLS_STATFUL_RULESET, "true" ).messagePaths(messagePathList).build();
+ ConfigTree configTree = new CBRConfigTreeBuilder( "JBossESBPricingRulesStateful.drl", "true" ).messagePaths(messagePathList).build();
BusinessRulesProcessor processor = new BusinessRulesProcessor( configTree );
processor.process( message );
@@ -72,25 +71,50 @@
public void processDiscountStateful() throws ObjectMappingException, ConfigurationException, RegistryException, MessageRouterException, ActionProcessingException
{
Message message = createMessageWithOrder( order );
- ConfigTree configTree = new CBRConfigTreeBuilder( DROOLS_STATFUL_RULESET, "true" ).messagePaths(messagePathList).stateful( true ).build();
+ ConfigTree configTree = new CBRConfigTreeBuilder( "JBossESBPricingRulesStateful.drl", "true" ).messagePaths(messagePathList).stateful( true ).build();
BusinessRulesProcessor processor = new BusinessRulesProcessor( configTree );
- // do not dispose of working memory
- message.getProperties().setProperty( RuleServicePropertiesNames.DISPOSE.getTagName(), "false" );
-
// process message
processor.process( message );
assertEquals( 20.0, order.getDiscount() );
assertEquals( "20%" ,message.getBody().get("DiscountObject"));
// now dispose after this call
- message.getProperties().setProperty( RuleServicePropertiesNames.DISPOSE.getTagName(), "true" );
+ message.getProperties().setProperty( RuleServicePropertiesNames.DISPOSE.getTagName(), Boolean.TRUE );
+ message.getProperties().setProperty( RuleServicePropertiesNames.CONTINUE.getTagName(), Boolean.TRUE );
+ processor.process( message );
+
+ // counter is inserted into the working memory by the first rules execution
+ // from the above process call.
+ Counter counter = (Counter) message.getBody().get("Counter");
+ assertEquals( 2 , counter.getCounter() );
+ }
+
+ @Test ( expected = ActionProcessingException.class )
+ public void shouldThrowIfDisposePropertyIsNotSet() throws ObjectMappingException, ConfigurationException, RegistryException, MessageRouterException, ActionProcessingException
+ {
+ Message message = createMessageWithOrder( order );
+ ConfigTree configTree = new CBRConfigTreeBuilder( "JBossESBPricingRulesStateful.drl", "true" ).messagePaths(messagePathList).stateful( true ).build();
+ BusinessRulesProcessor processor = new BusinessRulesProcessor( configTree );
+
+ // process message
+ processor.process( message );
+ assertEquals( 20.0, order.getDiscount() );
+ assertEquals( "20%" ,message.getBody().get("DiscountObject"));
- // process message again which a counter instance
- message.getBody().add( "Counter", new Counter( 30 ) );
+ // We don't set 'dispose' which should cause an exception to be thrown...
+ message.getProperties().setProperty( RuleServicePropertiesNames.CONTINUE.getTagName(), Boolean.TRUE );
processor.process( message );
+ }
+
+ @Test ( expected = ActionProcessingException.class )
+ public void throwIfFileTypeIsNotValid() throws ActionProcessingException, ConfigurationException, RegistryException, MessageRouterException
+ {
+ Message message = createMessageWithOrder( order );
+ ConfigTree configTree = new CBRConfigTreeBuilder( "test.bla", "true" ).messagePaths(messagePathList).build();
+ BusinessRulesProcessor processor = new BusinessRulesProcessor( configTree );
- assertEquals( 100 ,message.getBody().get("IntFromPriorityRuleHighQuantity") );
+ processor.process( message );
}
public static junit.framework.Test suite()
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/CBRConfigTreeBuilder.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/CBRConfigTreeBuilder.java 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/java/org/jboss/soa/esb/actions/CBRConfigTreeBuilder.java 2008-06-18 09:08:59 UTC (rev 20571)
@@ -67,8 +67,8 @@
public ConfigTree build()
{
ConfigTree configTree = new ConfigTree("cbr-config");
- configTree.setAttribute( RuleServicePropertiesNames.RULE_SET.getTagName(), ruleFile );
- configTree.setAttribute( RuleServicePropertiesNames.RULE_RELOAD.getTagName(), reload );
+ configTree.setAttribute( ListenerTagNames.RULE_SET_TAG, ruleFile );
+ configTree.setAttribute( ListenerTagNames.RULE_RELOAD_TAG, reload );
if ( messagePathList != null )
{
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/resources/JBossESBPricingRulesStateful.drl
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/resources/JBossESBPricingRulesStateful.drl 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/resources/JBossESBPricingRulesStateful.drl 2008-06-18 09:08:59 UTC (rev 20571)
@@ -23,24 +23,24 @@
m : Message ()
order : Order( quantity >= 10)
Order( discount == 0 )
+ not Counter()
then
- #System.out.println("high volume");
+ System.out.println("high volume");
order.setDiscount( 20 );
- # set an integer to show that this will be stored in the
- # working memory.
- insert( new Integer(100) );
+ insert( new Counter(1) );
m.getBody().add("DiscountObject","20%");
end
rule "Continue Rule - high quantity"
+ no-loop
when
- counter : Counter( counter == 30 )
- # if the previous rule was executed and this is a stateful
- # execution, and we havn't dispose of the working memory, the
- # Integer from the previous rule will be set to 100.
- $i : Number(intValue == 100)
+ $counter : Counter()
m : Message ()
then
- #System.out.println("Continue high quantity. Int value == " + $i);
- m.getBody().add( "IntFromPriorityRuleHighQuantity", $i );
+ System.out.println("Continue high quantity. Int value == " + $counter.getCounter());
+ Integer inc = $counter.getCounter();
+ inc++;
+ $counter.setCounter( inc );
+ m.getBody().add( "Counter", $counter );
+ System.out.println("Continue high quantity. Inc value == " + $counter.getCounter());
end
\ No newline at end of file
Modified: labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/resources/JBossESBRules.drl
===================================================================
--- labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/resources/JBossESBRules.drl 2008-06-18 08:52:05 UTC (rev 20570)
+++ labs/jbossesb/workspace/dbevenius/ruleservice/product/services/jbrules/src/test/resources/JBossESBRules.drl 2008-06-18 09:08:59 UTC (rev 20571)
@@ -15,7 +15,7 @@
when
Message( type == MessageType.JAVA_SERIALIZED)
then
- System.out.println("Serialized");
+ System.out.println("Message Type : Serialized");
destinations.add("serialized-destination");
end
@@ -25,6 +25,6 @@
when
Message( type == MessageType.JBOSS_XML)
then
- System.out.println("JBoss_XML");
+ System.out.println("MessageType : JBoss_XML");
destinations.add("xml-destination");
end
\ No newline at end of file
More information about the jboss-svn-commits
mailing list