[jboss-svn-commits] JBL Code SVN: r16072 - in labs/jbossesb/trunk/product: services/jbrules/src/main/java/org/jboss/soa/esb/actions and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 25 15:15:41 EDT 2007


Author: kurt.stam at jboss.com
Date: 2007-10-25 15:15:41 -0400 (Thu, 25 Oct 2007)
New Revision: 16072

Added:
   labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/
   labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/
   labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedRouterUnitTest.java
   labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedRouterUnitTest.xml
   labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedWiretapUnitTest.java
   labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedWiretapUnitTest.xml
   labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/MessageFilterUnitTest.java
   labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/MessageFilterUnitTest.xml
   labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRulesNoMatch.drl
Modified:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java
   labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/ContentBasedWiretap.java
   labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/MessageFilter.java
   labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java
   labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java
Log:
JBESB-1199 Cleaning up the code, and adding unittests to ensure correct behavior.

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java	2007-10-25 18:12:37 UTC (rev 16071)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java	2007-10-25 19:15:41 UTC (rev 16072)
@@ -61,8 +61,8 @@
  */
 public class ServiceInvoker {
 
-    private static final String INTERNAL_SERVICE_CATEGORY = "JBossESB-Internal";
-    private static final String DEAD_LETTER_SERVICE_NAME = "DeadLetterService";
+    public static final String INTERNAL_SERVICE_CATEGORY = "JBossESB-Internal";
+    public static final String DEAD_LETTER_SERVICE_NAME = "DeadLetterService";
     public static final String DELIVER_TO = "org.jboss.soa.esb.deliver.to";
     
     /**

Modified: labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/ContentBasedWiretap.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/ContentBasedWiretap.java	2007-10-25 18:12:37 UTC (rev 16071)
+++ labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/ContentBasedWiretap.java	2007-10-25 19:15:41 UTC (rev 16072)
@@ -59,8 +59,6 @@
 
     public static final String DEFAULT_CBR_CLASS = "org.jboss.internal.soa.esb.services.routing.cbr.JBossRulesRouter";
 
-    private static final String INTERNAL_SERVICE_CATEGORY = "JBossESB-Internal";
-    private static final String DEAD_LETTER_SERVICE_NAME = "DeadLetterService";
     ServiceInvoker dlQueueInvoker;
 
     public ContentBasedWiretap(ConfigTree config)
@@ -73,17 +71,15 @@
         _cbr.setConfigTree(config);
         _mapper = new ObjectMapper(config);
         try {
-            dlQueueInvoker = new ServiceInvoker(INTERNAL_SERVICE_CATEGORY, DEAD_LETTER_SERVICE_NAME);
+            dlQueueInvoker = new ServiceInvoker(ServiceInvoker.INTERNAL_SERVICE_CATEGORY, ServiceInvoker.DEAD_LETTER_SERVICE_NAME);
         } catch (MessageDeliverException e) {
             new MessageRouterException(e);
         }
     }
 
     public void initialise() {
-        if (messageMulticaster.getRecipientCount() == 0) {
-            // some classes don't need to worry about this anyway.
-            
-            _logger.debug("Missing or empty destination list - This action class won't have any effect");
+        if (messageMulticaster.getRecipientCount() == 0) { 
+            _logger.info("Missing or empty destination list - This action class won't have any effect");
         }
     }
 
@@ -96,70 +92,64 @@
      * @return Message
      * @throws ActionProcessingException
      */
-    public Message process(Message message) throws ActionProcessingException {
+    public Message process(Message message) throws ActionProcessingException 
+    {
         try {
-            routeMessage(message);
-
-            return message;
+            List<Service> outgoingDestinations = executeRules(message);
+            if (outgoingDestinations.size()==0) {
+                String error = "No rule destination(s) "+ _destinations.keySet() + " were matched, "
+                           + ". Please fix your configuration and/or routing rules.";
+                _logger.error(error);
+                try {
+                    _logger.debug("Sending message to the DeadLetterService");
+                    dlQueueInvoker.deliverAsync(message);
+                    throw new ActionProcessingException(error);
+                } catch (MessageDeliverException e) {
+                    throw new MessageRouterException("Failed to deliver message to Dead Letter Channel.", e);
+                }
+            } else {
+                routeMessage(message, outgoingDestinations);
+            }
+        } catch (MessageRouterException e) {
+            throw new ActionProcessingException(e);
         }
-        catch (MessageRouterException mre) {
-            throw new ActionProcessingException(mre.getMessage(), mre);
-        }
+        return message;
     }
-
-    protected void noDestinations() {
-        // nothing by default
-    }
-
-    protected void invalidRuleConfiguration(Message message,
-                                            List<String> destinations) throws MessageRouterException {
-        _logger
-                .error("The rule destination(s) "
-                        + destinations
-                        + " was not found in the destination names in the configuration "
-                        + _destinations.keySet()
-                        + ". Please fix your configuration.");
-
+    
+    protected List<Service> executeRules(Message message)
+        throws MessageRouterException 
+    {
+        List<Service> outgoingDestinations = new ArrayList<Service>();
         try {
-            dlQueueInvoker.deliverAsync(message);
-        } catch (MessageDeliverException e) {
-            throw new MessageRouterException("Failed to deliver message to Dead Letter Channel.", e);
-        }
-    }
-
-    protected final void routeMessage(Message message)
-            throws MessageRouterException {
-        try {
             List<Object> objectList = _mapper.createObjectList(message,
                     _messagePathList);
             List<String> destinations = _cbr.route(_ruleSet, _ruleLanguage,
                     _ruleReload, message, objectList);
-            List<Service> outgoingDestinations = new ArrayList<Service>();
             for (String destination : destinations) {
                 if (_destinations.containsKey(destination)) {
                     outgoingDestinations.add(_destinations.get(destination));
+                } else {
+                    throw new MessageRouterException("Destination " + destination + " does not exist your configuration");
                 }
             }
-            if (outgoingDestinations.size() > 0) {
-                try {
-                    messageMulticaster.sendToSubset(message, outgoingDestinations);
-                } catch (RegistryException e) {
-                    throw new MessageRouterException(e);
-                } catch (MessageDeliverException e) {
-                    throw new MessageRouterException(e);
-                }
-            } else {
-                noDestinations();
-    
-                if (destinations.size() > 0) {
-                    invalidRuleConfiguration(message, destinations);
-                }
-            }
         } catch (ObjectMappingException ome) {
             throw new MessageRouterException(ome);
         }
+        return outgoingDestinations;
     }
 
+    protected final void routeMessage(Message message, List<Service> outgoingDestinations)
+        throws MessageRouterException 
+    {  
+        try {
+            messageMulticaster.sendToSubset(message, outgoingDestinations);
+        } catch (RegistryException e) {
+            throw new MessageRouterException(e);
+        } catch (MessageDeliverException e) {
+            throw new MessageRouterException(e);
+        }
+    }
+
     /**
      * Reading the piece of configTree specific to the CBR, and setting the
      * configuration.
@@ -170,7 +160,7 @@
         if (_config.getAttribute(ListenerTagNames.RULE_SET_TAG) == null) {
             _logger.error("Required attribute " + ListenerTagNames.RULE_SET_TAG
                     + " not found in " + _config.getName() + ".");
-            throw new ConfigurationException("Required attribute"
+            throw new ConfigurationException("Required attribute "
                     + ListenerTagNames.RULE_SET_TAG + " not found.");
         } else {
             _ruleSet = _config.getAttribute(ListenerTagNames.RULE_SET_TAG);

Modified: labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/MessageFilter.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/MessageFilter.java	2007-10-25 18:12:37 UTC (rev 16071)
+++ labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/soa/esb/actions/MessageFilter.java	2007-10-25 19:15:41 UTC (rev 16072)
@@ -31,6 +31,7 @@
 
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.Service;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.services.registry.RegistryException;
@@ -61,8 +62,13 @@
     {
 	try
 	{
-	    
-	    routeMessage(message);
+        List<Service> outgoingDestinations = executeRules(message);
+        
+        if (outgoingDestinations.size()==0) {
+            log.debug("No destinations where matched, the Message is filtered");
+        } else {
+            routeMessage(message, outgoingDestinations);
+        }
 	}
 	catch (MessageRouterException mre)
 	{
@@ -72,15 +78,6 @@
 	return null;
     }
 
-    protected void noDestinations ()
-    {
-	log
-	.debug("No destinations where found, the Message is filtered");
-    }
 
-    protected void invalidRuleConfiguration (Message message,
-	    List<String> destinations) throws MessageRouterException
-    {
-	// do nothing
-    }
+
 }

Added: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedRouterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedRouterUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedRouterUnitTest.java	2007-10-25 19:15:41 UTC (rev 16072)
@@ -0,0 +1,142 @@
+/*
+ * 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.jbrules.actions;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.net.URI;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+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.actions.ContentBasedRouter;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.client.ServiceInvoker;
+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.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test the jBPM command interpreter class
+ *
+ * @author <a href="mailto:kurt.stam at jboss.com">Kurt Stam</a>
+ */
+
+
+public class ContentBasedRouterUnitTest
+{
+	static Logger 				_logger = Logger.getLogger(ContentBasedRouterUnitTest.class);
+    static Message message = null;
+    
+    private static EPR epr1;
+    private static EPR epr2;
+    private static EPR epr3;
+    private static MockCourier courier1;
+    private static MockCourier courier2;
+    private static MockCourier courier3;
+    
+    private static ConfigTree[] actions;
+	
+    public static junit.framework.Test suite()
+    {
+        return new JUnit4TestAdapter(ContentBasedRouterUnitTest.class);
+    }
+    
+    
+    @BeforeClass
+    public static void before() throws Exception {
+        MockCourierFactory.install();
+        MockRegistry.install();
+
+        epr1 = new EPR(new URI("test1"));
+        epr2 = new EPR(new URI("test2"));
+        epr3 = new EPR(new URI("DLS"));
+        courier1 = new MockCourier(true);
+        courier2 = new MockCourier(true);
+        courier3 = new MockCourier(true);
+
+        MockRegistry.register("test", "java", epr1, courier1);
+        MockRegistry.register("test", "xml", epr2, courier2);
+        MockRegistry.register(ServiceInvoker.INTERNAL_SERVICE_CATEGORY, ServiceInvoker.DEAD_LETTER_SERVICE_NAME, epr3, courier3);
+ 
+        message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+        message.getBody().add(("Hello CBR"));
+        
+        InputStream in = ClassUtil.getResourceAsStream("ContentBasedRouterUnitTest.xml", ContentBasedRouterUnitTest.class);
+        String xml = FileUtil.readStream(in);
+        actions = ConfigTree.fromXml(xml).getChildren("action");
+    }
+    
+    @Test
+	public void wrongDestinationName()
+    {
+		try {
+			ContentBasedRouter cbr = new ContentBasedRouter(actions[0]);
+            cbr.process(message);
+            //the config is wrong so we should error here, and try to send the message to the DLS
+            assertTrue(false);
+		} catch (Exception e) {
+            /* As it can't send the message to the DLS the log should say:
+               ERROR [main][ContentBasedWiretap] Destination serialized-destination does not exist your configuration
+               ERROR [main][ContentBasedWiretap] No rule destination(s) were matched, [serialized, xml]. Please fix your configuration and/or routing rules.
+             */
+			assertTrue(true);
+		}
+    }
+    
+    @Test
+    public void correctDestinationName()
+    {
+        try {
+            ContentBasedRouter cbr = new ContentBasedRouter(actions[1]);
+            Message returnMessage = cbr.process(message);
+            //the cbr should return a null message
+            assertNull(returnMessage);
+        } catch (Exception e) {
+            assertTrue(false);
+        }
+    }
+    
+    @Test
+    public void noDestinationMatches()
+    {
+        try {
+            ContentBasedRouter cbr = new ContentBasedRouter(actions[2]);
+            cbr.process(message);
+            //no destination matches, expecting error, and try to send the message to the DLS
+            assertTrue(false);
+        } catch (Exception e) {
+            assertTrue(true);
+        }
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedRouterUnitTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedRouterUnitTest.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedRouterUnitTest.xml	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedRouterUnitTest.xml	2007-10-25 19:15:41 UTC (rev 16072)
@@ -0,0 +1,23 @@
+<testActions>
+	<action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="WrongDestinion"
+		ruleSet="JBossESBRules.drl"
+		>
+			<route-to destination-name="serialized"  service-category="test"  service-name="java" /> 
+			<route-to destination-name="xml"         service-category="test"  service-name="xml" /> 
+	</action>
+	
+	<action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="Correct"
+		ruleSet="JBossESBRules.drl"
+		>
+			<route-to destination-name="serialized-destination"  service-category="test"  service-name="java" /> 
+			<route-to destination-name="xml-destination"         service-category="test"  service-name="xml" /> 
+	</action>
+	
+	<action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="MyType"
+		ruleSet="JBossESBRulesNoMatch.drl"
+		>
+			<route-to destination-name="mytype-destination"      service-category="test"  service-name="mytype" /> 
+			<route-to destination-name="xml-destination"         service-category="test"  service-name="xml" /> 
+	</action>
+
+</testActions>


Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedRouterUnitTest.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedWiretapUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedWiretapUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedWiretapUnitTest.java	2007-10-25 19:15:41 UTC (rev 16072)
@@ -0,0 +1,142 @@
+/*
+ * 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.jbrules.actions;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.net.URI;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+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.actions.ContentBasedWiretap;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.client.ServiceInvoker;
+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.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test the jBPM command interpreter class
+ *
+ * @author <a href="mailto:kurt.stam at jboss.com">Kurt Stam</a>
+ */
+
+
+public class ContentBasedWiretapUnitTest
+{
+	static Logger 				_logger = Logger.getLogger(ContentBasedWiretapUnitTest.class);
+    static Message message = null;
+    
+    private static EPR epr1;
+    private static EPR epr2;
+    private static EPR epr3;
+    private static MockCourier courier1;
+    private static MockCourier courier2;
+    private static MockCourier courier3;
+    
+    private static ConfigTree[] actions;
+	
+    public static junit.framework.Test suite()
+    {
+        return new JUnit4TestAdapter(ContentBasedWiretapUnitTest.class);
+    }
+    
+    
+    @BeforeClass
+    public static void before() throws Exception {
+        MockCourierFactory.install();
+        MockRegistry.install();
+
+        epr1 = new EPR(new URI("test1"));
+        epr2 = new EPR(new URI("test2"));
+        epr3 = new EPR(new URI("DLS"));
+        courier1 = new MockCourier(true);
+        courier2 = new MockCourier(true);
+        courier3 = new MockCourier(true);
+
+        MockRegistry.register("test", "java", epr1, courier1);
+        MockRegistry.register("test", "xml", epr2, courier2);
+        MockRegistry.register(ServiceInvoker.INTERNAL_SERVICE_CATEGORY, ServiceInvoker.DEAD_LETTER_SERVICE_NAME, epr3, courier3);
+ 
+        message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+        message.getBody().add(("Hello CBR"));
+        
+        InputStream in = ClassUtil.getResourceAsStream("ContentBasedWiretapUnitTest.xml", ContentBasedWiretapUnitTest.class);
+        String xml = FileUtil.readStream(in);
+        actions = ConfigTree.fromXml(xml).getChildren("action");
+    }
+    
+    @Test
+	public void wrongDestinationName()
+    {
+		try {
+            ContentBasedWiretap cbr = new ContentBasedWiretap(actions[0]);
+            cbr.process(message);
+            //the config is wrong so we should error here, no message to the DLS
+            assertTrue(false);
+		} catch (Exception e) {
+            /* As it can't send the message to the DLS the log should say:
+               ERROR [main][ContentBasedWiretap] Destination serialized-destination does not exist your configuration
+               ERROR [main][ContentBasedWiretap] No rule destination(s) were matched, [serialized, xml]. Please fix your configuration and/or routing rules.
+             */
+			assertTrue(true);
+		}
+    }
+    
+    @Test
+    public void correctDestinationName()
+    {
+        try {
+            ContentBasedWiretap cbr = new ContentBasedWiretap(actions[1]);
+            Message returnMessage = cbr.process(message);
+            //the cbr should return a null message
+            assertNotNull(returnMessage);
+        } catch (Exception e) {
+            assertTrue(false);
+        }
+    }
+    
+    @Test
+    public void noDestinationMatches()
+    {
+        try {
+            ContentBasedWiretap cbr = new ContentBasedWiretap(actions[2]);
+            cbr.process(message);
+            //no destination matches, expecting error, and try to send the message to the DLS
+            assertTrue(false);
+        } catch (Exception e) {
+            assertTrue(true);
+        }
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedWiretapUnitTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedWiretapUnitTest.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedWiretapUnitTest.xml	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedWiretapUnitTest.xml	2007-10-25 19:15:41 UTC (rev 16072)
@@ -0,0 +1,23 @@
+<testActions>
+	<action class="org.jboss.soa.esb.actions.ContentBasedWiretap" name="WrongDestinion"
+		ruleSet="JBossESBRules.drl"
+		>
+			<route-to destination-name="serialized"  service-category="test"  service-name="java" /> 
+			<route-to destination-name="xml"         service-category="test"  service-name="xml" /> 
+	</action>
+	
+	<action class="org.jboss.soa.esb.actions.ContentBasedWiretap" name="Correct"
+		ruleSet="JBossESBRules.drl"
+		>
+			<route-to destination-name="serialized-destination"  service-category="test"  service-name="java" /> 
+			<route-to destination-name="xml-destination"         service-category="test"  service-name="xml" /> 
+	</action>
+	
+	<action class="org.jboss.soa.esb.actions.ContentBasedWiretap" name="MyType"
+		ruleSet="JBossESBRulesNoMatch.drl"
+		>
+			<route-to destination-name="mytype-destination"      service-category="test"  service-name="mytype" /> 
+			<route-to destination-name="xml-destination"         service-category="test"  service-name="xml" /> 
+	</action>
+
+</testActions>


Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/ContentBasedWiretapUnitTest.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/MessageFilterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/MessageFilterUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/MessageFilterUnitTest.java	2007-10-25 19:15:41 UTC (rev 16072)
@@ -0,0 +1,142 @@
+/*
+ * 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.jbrules.actions;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.net.URI;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+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.actions.MessageFilter;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.client.ServiceInvoker;
+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.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test the jBPM command interpreter class
+ *
+ * @author <a href="mailto:kurt.stam at jboss.com">Kurt Stam</a>
+ */
+
+
+public class MessageFilterUnitTest
+{
+	static Logger 				_logger = Logger.getLogger(MessageFilterUnitTest.class);
+    static Message message = null;
+    
+    private static EPR epr1;
+    private static EPR epr2;
+    private static EPR epr3;
+    private static MockCourier courier1;
+    private static MockCourier courier2;
+    private static MockCourier courier3;
+    
+    private static ConfigTree[] actions;
+	
+    public static junit.framework.Test suite()
+    {
+        return new JUnit4TestAdapter(MessageFilterUnitTest.class);
+    }
+    
+    
+    @BeforeClass
+    public static void before() throws Exception {
+        MockCourierFactory.install();
+        MockRegistry.install();
+
+        epr1 = new EPR(new URI("test1"));
+        epr2 = new EPR(new URI("test2"));
+        epr3 = new EPR(new URI("DLS"));
+        courier1 = new MockCourier(true);
+        courier2 = new MockCourier(true);
+        courier3 = new MockCourier(true);
+
+        MockRegistry.register("test", "java", epr1, courier1);
+        MockRegistry.register("test", "xml", epr2, courier2);
+        MockRegistry.register(ServiceInvoker.INTERNAL_SERVICE_CATEGORY, ServiceInvoker.DEAD_LETTER_SERVICE_NAME, epr3, courier3);
+ 
+        message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+        message.getBody().add(("Hello CBR"));
+        
+        InputStream in = ClassUtil.getResourceAsStream("ContentBasedRouterUnitTest.xml", MessageFilterUnitTest.class);
+        String xml = FileUtil.readStream(in);
+        actions = ConfigTree.fromXml(xml).getChildren("action");
+    }
+    
+    @Test
+	public void wrongDestinationName()
+    {
+		try {
+            MessageFilter cbr = new MessageFilter(actions[0]);
+            cbr.process(message);
+            //the config is wrong so we should error here, and try to send the message to the DLS
+            assertTrue(false);
+		} catch (Exception e) {
+            /* As it can't send the message to the DLS the log should say:
+               ERROR [main][ContentBasedWiretap] Destination serialized-destination does not exist your configuration
+               ERROR [main][ContentBasedWiretap] No rule destination(s) were matched, [serialized, xml]. Please fix your configuration and/or routing rules.
+             */
+			assertTrue(true);
+		}
+    }
+    
+    @Test
+    public void correctDestinationName()
+    {
+        try {
+            MessageFilter cbr = new MessageFilter(actions[1]);
+            Message returnMessage = cbr.process(message);
+            //the cbr should return a null message
+            assertNull(returnMessage);
+        } catch (Exception e) {
+            assertTrue(false);
+        }
+    }
+    
+    @Test
+    public void noDestinationMatches()
+    {
+        try {
+            MessageFilter cbr = new MessageFilter(actions[2]);
+            Message returnMessage = cbr.process(message);
+            //the cbr should return a null message, message should be filtered with no errors.
+            assertNull(returnMessage);
+        } catch (Exception e) {
+            assertTrue(false);
+        }
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/MessageFilterUnitTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/MessageFilterUnitTest.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/MessageFilterUnitTest.xml	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/MessageFilterUnitTest.xml	2007-10-25 19:15:41 UTC (rev 16072)
@@ -0,0 +1,23 @@
+<testActions>
+	<action class="org.jboss.soa.esb.actions.MessageFilter" name="WrongDestinion"
+		ruleSet="JBossESBRules.drl"
+		>
+			<route-to destination-name="serialized"  service-category="test"  service-name="java" /> 
+			<route-to destination-name="xml"         service-category="test"  service-name="xml" /> 
+	</action>
+	
+	<action class="org.jboss.soa.esb.actions.MessageFilter" name="Correct"
+		ruleSet="JBossESBRules.drl"
+		>
+			<route-to destination-name="serialized-destination"  service-category="test"  service-name="java" /> 
+			<route-to destination-name="xml-destination"         service-category="test"  service-name="xml" /> 
+	</action>
+	
+	<action class="org.jboss.soa.esb.actions.MessageFilter" name="MyType"
+		ruleSet="JBossESBRulesNoMatch.drl"
+		>
+			<route-to destination-name="mytype-destination"      service-category="test"  service-name="mytype" /> 
+			<route-to destination-name="xml-destination"         service-category="test"  service-name="xml" /> 
+	</action>
+
+</testActions>


Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/jbrules/actions/MessageFilterUnitTest.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Modified: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java	2007-10-25 18:12:37 UTC (rev 16071)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java	2007-10-25 19:15:41 UTC (rev 16072)
@@ -29,7 +29,6 @@
 import junit.framework.JUnit4TestAdapter;
 
 import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.body.content.BytesBody;
 import org.jboss.soa.esb.message.format.MessageFactory;
 import org.jboss.soa.esb.message.format.MessageType;
 import org.jboss.soa.esb.services.routing.MessageRouterException;

Modified: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java	2007-10-25 18:12:37 UTC (rev 16071)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java	2007-10-25 19:15:41 UTC (rev 16072)
@@ -29,7 +29,6 @@
 import junit.framework.JUnit4TestAdapter;
 
 import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.body.content.BytesBody;
 import org.jboss.soa.esb.message.format.MessageFactory;
 import org.jboss.soa.esb.message.format.MessageType;
 import org.jboss.soa.esb.services.routing.MessageRouterException;

Added: labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRulesNoMatch.drl
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRulesNoMatch.drl	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRulesNoMatch.drl	2007-10-25 19:15:41 UTC (rev 16072)
@@ -0,0 +1,29 @@
+#created on: Oct 30, 2006
+package com.jboss.soa.esb.routing.cbr
+
+#list any import classes here.
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageType;
+
+#declare any global variables here
+global java.util.List destinations;
+
+
+rule "Routing Rule - Serialized based message"
+	
+	when
+		Message( type == "MyType")
+	then
+		System.out.println("MyType");
+		destinations.add("mytype-destination");
+		
+end
+
+rule "Routing Rule - XML based message"
+	
+	when
+		Message( type == MessageType.JBOSS_XML)
+	then 
+		System.out.println("JBoss_XML"); 
+		destinations.add("xml-destination");
+end
\ No newline at end of file




More information about the jboss-svn-commits mailing list