servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r782998 - in /servicemix/components/engines/servicemix-eip/trunk/src/test: java/org/apache/servicemix/eip/ java/org/apache/servicemix/eip/packaging/ java/org/apache/servicemix/eip/support/ resources/org/apache/servicemix/eip/
Date Tue, 09 Jun 2009 13:27:43 GMT
Author: ffang
Date: Tue Jun  9 13:27:42 2009
New Revision: 782998

URL: http://svn.apache.org/viewvc?rev=782998&view=rev
Log:
[SMXCOMP-531]Improve test coverage - ServiceMix :: EIP

Added:
    servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterSwitchPredicateTest.java
  (with props)
    servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/packaging/
    servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/packaging/EipServiceUnitAnalyzerTest.java
  (with props)
    servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/support/ExchangeTargetTest.java
  (with props)
    servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch-off.properties
  (with props)
    servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch.properties
  (with props)
Modified:
    servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterTest.java
    servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/SplitAggregatorTest.java
    servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/XPathSplitterTest.java

Added: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterSwitchPredicateTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterSwitchPredicateTest.java?rev=782998&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterSwitchPredicateTest.java
(added)
+++ servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterSwitchPredicateTest.java
Tue Jun  9 13:27:42 2009
@@ -0,0 +1,169 @@
+package org.apache.servicemix.eip;
+
+import java.net.URL;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.eip.patterns.MessageFilter;
+import org.apache.servicemix.eip.support.SwitchPredicate;
+import org.apache.servicemix.tck.ReceiverComponent;
+import org.springframework.core.io.FileSystemResource;
+
+// Test for SwitchPredicate methods.  Switch can be turned on/off with a
+// property file, a property on the message exchange, or a system property.
+public class MessageFilterSwitchPredicateTest extends AbstractEIPTest {
+    
+	private static Log log = LogFactory.getLog(MessageFilterSwitchPredicateTest.class);
+	protected MessageFilter messageFilter;
+	protected SwitchPredicate predicate;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        messageFilter = new MessageFilter();
+        predicate = new SwitchPredicate();
+        
+    }
+    
+    protected void tearDown() throws Exception {
+    	messageFilter = null;
+    	predicate = null;
+    	
+    	super.tearDown();
+    }
+    
+    // Test for switch predicate on/off when set on the message exchange.
+    public void testPropertyOnExchange() throws Exception {
+        InOnly me = client.createInOnlyExchange();
+    	me.setProperty("on", Boolean.FALSE);
+    	predicate.setFromExchange(true);
+    	predicate.setPropertyName("on");
+    	
+    	messageFilter.setFilter(predicate);
+    	messageFilter.setTarget(createServiceExchangeTarget(new QName("target")));
+        configurePattern(messageFilter);
+        activateComponent(messageFilter, "messageFilter");
+        ReceiverComponent rec = activateReceiver("target");
+        me.setService(new QName("messageFilter"));
+        
+        // Message exchange turned off - message should NOT reach the target.
+        me.getInMessage().setContent(createSource("<orderIn><widget>5</widget></orderIn>"));
+        me.getInMessage().setProperty("on", Boolean.FALSE);
+        log.info("Before client.sendSync me.getProperty(\"on\") is: " + me.getProperty("on"));
+        client.sendSync(me);
+        log.info("After client.sendSync me.getProperty(\"on\" is: " + me.getProperty("on"));
+        assertEquals("Message exchange status should be DONE", ExchangeStatus.DONE, me.getStatus());
+        
+        rec.getMessageList().assertMessagesReceived(0);
+
+/*
+ * Comment this part of the test out until SMXCOMP-553 is fixed.        
+        // Message exchange turned on - message should reach the target.
+        me = client.createInOnlyExchange();
+        me.setProperty("on", Boolean.TRUE);
+        predicate.setFromExchange(true);
+        predicate.setPropertyName("on");
+        
+        messageFilter.setFilter(predicate);
+        configurePattern(messageFilter);
+        me.setService(new QName("messageFilter"));
+        
+        me.getInMessage().setContent(createSource("<orderIn><widget>5</widget></orderIn>"));
+        me.getInMessage().setProperty("on", Boolean.TRUE);
+        log.info("Before client.sendSync me.getProperty(\"on\") is: " + me.getProperty("on"));
+        client.sendSync(me);
+        log.info("After client.sendSync me.getProperty(\"on\" is: " + me.getProperty("on"));
+        assertEquals("Message exchange status should be DONE", ExchangeStatus.DONE, me.getStatus());
+        
+        rec.getMessageList().assertMessagesReceived(1);
+*/
+    }
+    
+    // Test switch predicate on and off when property value comes from a file.
+    public void testPropertyFromFile() throws Exception {
+    	InOnly me = client.createInOnlyExchange();
+    	
+    	URL fileUrl = getClass().getResource("switch-off.properties");
+    	FileSystemResource propFile = new FileSystemResource(fileUrl.getFile());
+    	predicate.setPropertyResource(propFile);
+    	predicate.setPropertyName("on");
+    	
+        // Message exchange turned off - message should not reach the target.
+    	messageFilter.setFilter(predicate);
+    	messageFilter.setTarget(createServiceExchangeTarget(new QName("target")));
+        configurePattern(messageFilter);
+        activateComponent(messageFilter, "messageFilter");
+        ReceiverComponent rec = activateReceiver("target");
+        me.setService(new QName("messageFilter"));
+        
+        me.getInMessage().setContent(createSource("<orderIn><gadget>10</gadget></orderIn>"));
+        client.sendSync(me);
+        assertEquals("Message exchange status should be DONE", ExchangeStatus.DONE, me.getStatus());
+
+        rec.getMessageList().assertMessagesReceived(0);
+       
+        // Message exchange turned on - message should reach the target.
+        me = client.createInOnlyExchange();
+        fileUrl = getClass().getResource("switch.properties");
+        propFile = new FileSystemResource(fileUrl.getFile());
+        predicate.setPropertyResource(propFile);
+        predicate.setPropertyName("on");
+        
+        messageFilter.setFilter(predicate);
+        me.setService(new QName("messageFilter"));
+        
+        me.getInMessage().setContent(createSource("<orderIn><widget>5</widget></orderIn>"));
+        client.sendSync(me);
+        assertEquals("Message exchange status should be DONE", ExchangeStatus.DONE, me.getStatus());
+        
+        rec.getMessageList().assertMessagesReceived(1);
+        
+    }
+    
+    // Test switch predicate on and off when property is a system property.
+    public void testSystemProperty() throws Exception {
+    	System.setProperty("on", "false");
+    	
+    	InOnly me = client.createInOnlyExchange();
+    	
+    	predicate.setPropertyName("on");
+    	
+    	// Message exchange turned off - message should not reach the target.
+    	messageFilter.setFilter(predicate);
+    	messageFilter.setTarget(createServiceExchangeTarget(new QName("target")));
+        configurePattern(messageFilter);
+        activateComponent(messageFilter, "messageFilter");
+        ReceiverComponent rec = activateReceiver("target");
+        me.setService(new QName("messageFilter"));
+        
+        me.getInMessage().setContent(createSource("<orderIn><gadget>10</gadget></orderIn>"));
+        client.sendSync(me);
+        assertEquals("Message exchange status should be DONE", ExchangeStatus.DONE, me.getStatus());
+
+        rec.getMessageList().assertMessagesReceived(0);
+        
+        // Need to clear the previously set System property.
+        System.clearProperty("on");
+        System.setProperty("on", "true");
+        
+        me = client.createInOnlyExchange();
+        
+        predicate.setPropertyName("on");
+        
+        // Message exchange turned on - message should reach the target.
+    	messageFilter.setFilter(predicate);
+    	messageFilter.setTarget(createServiceExchangeTarget(new QName("target")));
+        configurePattern(messageFilter);
+        me.setService(new QName("messageFilter"));
+        
+        me.getInMessage().setContent(createSource("<orderIn><gadget>10</gadget></orderIn>"));
+        client.sendSync(me);
+        assertEquals("Message exchange status should be DONE", ExchangeStatus.DONE, me.getStatus());
+
+        rec.getMessageList().assertMessagesReceived(1);
+    }
+}

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterSwitchPredicateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterSwitchPredicateTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterTest.java?rev=782998&r1=782997&r2=782998&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterTest.java
(original)
+++ servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/MessageFilterTest.java
Tue Jun  9 13:27:42 2009
@@ -66,5 +66,26 @@
         client.sendSync(me);
         assertEquals(ExchangeStatus.ERROR, me.getStatus());
     }
+    
+    // Test XPath filter when XPath expression is invalid.
+    public void testInvalidXPathExpression() throws Exception {
+    	// Create an invalid XPath expression predicate and set it as the filter.
+    	XPathPredicate predicate = new XPathPredicate();
+    	predicate.setXPath("\\invalid");
+    	messageFilter.setFilter(predicate);
+    	configurePattern(messageFilter);
+        
+        ReceiverComponent rec = activateReceiver("target");
+        
+        // Create an inOnly exchange and send a basic XML message.
+        InOnly me = client.createInOnlyExchange();
+        me.setService(new QName("messageFilter"));
+        me.getInMessage().setContent(createSource("<hello><one/><two/><three/></hello>"));
+        client.sendSync(me);
+        assertEquals("", ExchangeStatus.DONE, me.getStatus());
+        
+        // No messages should be received due to the invalid XPath expression.
+        rec.getMessageList().assertMessagesReceived(0);
+    }
 
 }

Modified: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/SplitAggregatorTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/SplitAggregatorTest.java?rev=782998&r1=782997&r2=782998&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/SplitAggregatorTest.java
(original)
+++ servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/SplitAggregatorTest.java
Tue Jun  9 13:27:42 2009
@@ -20,6 +20,7 @@
 
 import javax.jbi.JBIException;
 import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
@@ -165,4 +166,47 @@
         Thread.sleep(500);
         rec.getMessageList().assertMessagesReceived(0);
     }
+    
+    // Test aggregator when InOut MEP is used.  An exception should be thrown.
+    public void testInvalidInOutMep() throws Exception {
+    	
+        int nbMessages = 3;
+        int nbMessagesSent = 0;
+        String corrId = Long.toString(System.currentTimeMillis());
+        try {
+            for (int i = 0; i < 3; i++) {
+                InOut me = client.createInOutExchange();
+                me.setService(new QName("aggregator"));
+                me.getInMessage().setContent(createSource("<hello id='" + i + "' />"));
+                me.getInMessage().setProperty(AbstractSplitter.SPLITTER_COUNT, new Integer(nbMessages));
+                me.getInMessage().setProperty(AbstractSplitter.SPLITTER_INDEX, new Integer(i));
+                me.getInMessage().setProperty(AbstractSplitter.SPLITTER_CORRID, corrId);
+                me.getInMessage().setProperty("prop", "value");
+                client.send(me);
+                nbMessagesSent++;
+            }
+        } catch (UnsupportedOperationException uoe) {
+        	// test succeeds
+        }
+    }
+    
+    // Test aggregator when no correlation id is set on the message.
+    public void testNullCorrelationId() throws Exception {
+    	int nbMessages = 3;
+        int nbMessagesSent = 0;
+        try {
+            for (int i = 0; i < 3; i++) {
+                InOut me = client.createInOutExchange();
+                me.setService(new QName("aggregator"));
+                me.getInMessage().setContent(createSource("<hello id='" + i + "' />"));
+                me.getInMessage().setProperty(AbstractSplitter.SPLITTER_COUNT, new Integer(nbMessages));
+                me.getInMessage().setProperty(AbstractSplitter.SPLITTER_INDEX, new Integer(i));
+                me.getInMessage().setProperty("prop", "value");
+                client.send(me);
+                nbMessagesSent++;
+            }
+        } catch (IllegalArgumentException iae) {
+        	// test succeeds
+        }
+    }
 }

Modified: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/XPathSplitterTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/XPathSplitterTest.java?rev=782998&r1=782997&r2=782998&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/XPathSplitterTest.java
(original)
+++ servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/XPathSplitterTest.java
Tue Jun  9 13:27:42 2009
@@ -16,14 +16,14 @@
  */
 package org.apache.servicemix.eip;
 
+import javax.jbi.management.DeploymentException;
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.InOut;
-import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.MessagingException;
 import javax.xml.namespace.QName;
 
 import org.apache.servicemix.eip.patterns.XPathSplitter;
+import org.apache.servicemix.eip.support.ExchangeTarget;
 import org.apache.servicemix.tck.ReceiverComponent;
 
 public class XPathSplitterTest extends AbstractEIPTest {
@@ -84,4 +84,30 @@
         assertEquals(ExchangeStatus.ERROR, me.getStatus());
     }
 
+    // Test validate() with null target
+    public void testValidateNullTarget() throws Exception {
+    	ExchangeTarget target = null;
+    	splitter.setTarget(target);
+    	
+    	try {
+    		splitter.validate();
+    		fail("ExchangeTarget is null, validate should throw an exception");
+    	} catch (IllegalArgumentException iae) {
+    		// test succeeds
+    	}
+    }
+    
+    // Test validate() with null XPath expression
+    public void testValidateNullXPathExpression() throws Exception {
+        XPathSplitter badSplitter = new XPathSplitter();
+        badSplitter.setTarget(createServiceExchangeTarget(new QName("target")));
+    	badSplitter.setXPath(null);
+    	
+    	try {
+    		badSplitter.validate();
+    		fail("XPath expression is null, validate should throw an exception");
+    	} catch (DeploymentException de) {
+    		// test succeeds
+    	}
+    }
 }

Added: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/packaging/EipServiceUnitAnalyzerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/packaging/EipServiceUnitAnalyzerTest.java?rev=782998&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/packaging/EipServiceUnitAnalyzerTest.java
(added)
+++ servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/packaging/EipServiceUnitAnalyzerTest.java
Tue Jun  9 13:27:42 2009
@@ -0,0 +1,317 @@
+package org.apache.servicemix.eip.packaging;
+
+import java.util.List;
+
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessageExchange.Role;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.common.DefaultServiceUnit;
+import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.common.packaging.Consumes;
+import org.apache.servicemix.eip.AbstractEIPTest;
+import org.apache.servicemix.eip.patterns.ContentBasedRouter;
+import org.apache.servicemix.eip.patterns.ContentEnricher;
+import org.apache.servicemix.eip.patterns.MessageFilter;
+import org.apache.servicemix.eip.patterns.Pipeline;
+import org.apache.servicemix.eip.patterns.SplitAggregator;
+import org.apache.servicemix.eip.patterns.StaticRecipientList;
+import org.apache.servicemix.eip.patterns.StaticRoutingSlip;
+import org.apache.servicemix.eip.patterns.WireTap;
+import org.apache.servicemix.eip.patterns.XPathSplitter;
+import org.apache.servicemix.eip.support.ExchangeTarget;
+import org.apache.servicemix.eip.support.RoutingRule;
+import org.apache.servicemix.eip.support.XPathPredicate;
+import org.w3c.dom.Document;
+
+public class EipServiceUnitAnalyzerTest extends AbstractEIPTest {
+
+	private EipServiceUnitAnalyzer analyzer;
+	private DefaultServiceUnit su;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		analyzer = new EipServiceUnitAnalyzer();
+		su = new DefaultServiceUnit();
+	}
+
+	protected void tearDown() throws Exception {
+		su = null;
+		analyzer = null;
+		super.tearDown();
+	}
+	
+	// Test isValidEndpoint for a valid EIP endpoint.
+	public void testIsValidEndpointTrue() throws Exception {
+		ContentBasedRouter router = new ContentBasedRouter();
+		router.setService(new QName("cbr"));
+		router.setEndpoint("cbr");
+		su.addEndpoint(router);
+		
+		assertTrue("isValidEndpoint() should return true for ContentBasedRouter endpoint", 
+				analyzer.isValidEndpoint(router));
+	}
+	
+	// Test isValidEndpoint for a non-EIP endpoint.
+	public void testIsValidEndpointFalse() throws Exception {
+		TestEndpoint testEp = new TestEndpoint();
+		su.addEndpoint(testEp);
+		
+		assertFalse("isValidEndpoint() should return false for non-EIP endpoint",
+				analyzer.isValidEndpoint(testEp));
+	}
+	
+	// test getConsumes() with a ContentBasedRouter endpoint
+	public void testGetConsumesContentBasedRouter() throws Exception {
+		ContentBasedRouter router = new ContentBasedRouter();
+		router.setService(new QName("cbr"));
+		router.setEndpoint("cbr");
+		router.setRules(new RoutingRule[] {
+	            new RoutingRule(
+	                    new XPathPredicate("/hello/@id = '1'"),
+	                    createServiceExchangeTarget(new QName("target1"))),
+	            new RoutingRule(
+	                    new XPathPredicate("/hello/@id = '2'"),
+	                    createServiceExchangeTarget(new QName("target2"))),
+	            new RoutingRule(
+	                    null,
+	                    createServiceExchangeTarget(new QName("target3")))
+	        });
+		su.addEndpoint(router);
+		
+		List<Consumes> consumesList = analyzer.getConsumes(router);
+		
+		assertNotNull("getConsumes() for ContentBasedRouter endpoint should return a non-null list",

+				consumesList);
+		assertTrue("Consumes list should contain 3 entries", consumesList.size() == 3);
+	}
+	
+	// test getConsumes() with the MessageFilter endpoint
+	public void testGetConsumesMessageFilter() throws Exception {
+		MessageFilter messageFilter = new MessageFilter();
+		messageFilter = new MessageFilter();
+        messageFilter.setFilter(new XPathPredicate("/hello/@id = '1'"));
+        messageFilter.setTarget(createServiceExchangeTarget(new QName("target")));
+        messageFilter.setService(new QName("messageFilter"));
+        messageFilter.setEndpoint("messageFilter");
+        
+        su.addEndpoint(messageFilter);
+        
+        List<Consumes> consumesList = analyzer.getConsumes(messageFilter);
+        
+        assertNotNull("getConsumes() for MessageFilter endpoint should return a non-null
list", 
+				consumesList);
+		assertTrue("Consumes list should contain 1 entry", consumesList.size() == 1);
+	}
+	
+	// test getConsumes() with the Pipeline endpoint
+	public void testGetConsumesPipeline() throws Exception {
+		Pipeline pipeline = new Pipeline();
+		pipeline.setTransformer(createServiceExchangeTarget(new QName("transformer")));
+        pipeline.setTarget(createServiceExchangeTarget(new QName("target")));
+        pipeline.setService(new QName("pipeline"));
+        pipeline.setEndpoint("pipeline");
+        
+        su.addEndpoint(pipeline);
+        
+        List<Consumes> consumesList = analyzer.getConsumes(pipeline);
+        
+        assertNotNull("getConsumes() for Pipeline endpoint should return a non-null list",

+				consumesList);
+		assertTrue("Consumes list should contain 2 entries", consumesList.size() == 2);
+	}
+	
+	// test getConsumes() with SplitAggregator endpoint
+	public void testGetConsumesSplitAggregator() throws Exception {
+		SplitAggregator aggregator = new SplitAggregator();
+		aggregator.setTarget(createServiceExchangeTarget(new QName("target")));
+        aggregator.setCopyProperties(true);
+        aggregator.setService(new QName("splitAggregator"));
+        aggregator.setEndpoint("splitAggregator");
+        
+        su.addEndpoint(aggregator);
+        
+        List<Consumes> consumesList = analyzer.getConsumes(aggregator);
+        
+        assertNotNull("getConsumes() for SplitAggregator endpoint should return a non-null
list", 
+				consumesList);
+		assertTrue("Consumes list should contain 1 entry", consumesList.size() == 1);      
+	}
+	
+	// test getConsumes() with StaticRecipientList endpoint
+	public void testGetConsumesStaticRecipientList() throws Exception {
+		StaticRecipientList recipientList = new StaticRecipientList();
+		recipientList.setRecipients(
+                new ExchangeTarget[] {
+                        createServiceExchangeTarget(new QName("recipient1")),
+                        createServiceExchangeTarget(new QName("recipient2")),
+                        createServiceExchangeTarget(new QName("recipient3")),
+                        createServiceExchangeTarget(new QName("recipient4"))
+                });
+		recipientList.setService(new QName("recipList"));
+		recipientList.setEndpoint("recipList");
+		
+		su.addEndpoint(recipientList);
+
+		List<Consumes> consumesList = analyzer.getConsumes(recipientList);
+        
+        assertNotNull("getConsumes() for StaticRecipientList endpoint should return a non-null
list", 
+				consumesList);
+		assertTrue("Consumes list should contain 4 entries", consumesList.size() == 4);      	
+	}
+	
+	// test getConsumes() with StaticRoutingSlip endpoint
+	public void testGetConsumesStaticRoutingSlip() throws Exception {
+		StaticRoutingSlip routingSlip = new StaticRoutingSlip();
+		routingSlip.setTargets(
+                new ExchangeTarget[] {
+                        createServiceExchangeTarget(new QName("target1")),
+                        createServiceExchangeTarget(new QName("target2")),
+                        createServiceExchangeTarget(new QName("target3"))
+                });
+		routingSlip.setService(new QName("routingSlip"));
+		routingSlip.setEndpoint("routingSlip");
+		
+		su.addEndpoint(routingSlip);
+		
+        List<Consumes> consumesList = analyzer.getConsumes(routingSlip);
+        
+        assertNotNull("getConsumes() for StaticRoutingSlip endpoint should return a non-null
list", 
+				consumesList);
+		assertTrue("Consumes list should contain 3 entries", consumesList.size() == 3);
+	}
+	
+	// test getConsumes() with WireTap endpoint
+	public void testGetConsumesWireTap() throws Exception {
+		WireTap wireTap = new WireTap();
+        wireTap.setInListener(createServiceExchangeTarget(new QName("in")));
+        wireTap.setOutListener(createServiceExchangeTarget(new QName("out")));
+        wireTap.setFaultListener(createServiceExchangeTarget(new QName("fault")));
+        wireTap.setTarget(createServiceExchangeTarget(new QName("target")));
+        wireTap.setService(new QName("wireTap"));
+        wireTap.setEndpoint("wireTap");
+        
+        su.addEndpoint(wireTap);
+        
+        List<Consumes> consumesList = analyzer.getConsumes(wireTap);
+        
+        assertNotNull("getConsumes() for WireTap endpoint should return a non-null list",

+				consumesList);
+		assertTrue("Consumes list should contain 4 entries", consumesList.size() == 4);
+	}
+	
+	// test getConsumes() with XPathSplitter endpoint
+	public void testGetConsumesXPathSplitter() throws Exception {
+		XPathSplitter splitter = new XPathSplitter();
+        splitter.setTarget(createServiceExchangeTarget(new QName("target")));
+        splitter.setXPath("/hello/*");
+        splitter.setService(new QName("splitter"));
+        splitter.setEndpoint("splitter");
+        
+        su.addEndpoint(splitter);
+       
+        List<Consumes> consumesList = analyzer.getConsumes(splitter);
+        
+        assertNotNull("getConsumes() for XPathSplitter endpoint should return a non-null
list", 
+				consumesList);
+		assertTrue("Consumes list should contain 1 entry", consumesList.size() == 1);      
+	}
+	
+	// test getConsumes() with unresolvable EIP endpoint
+	public void testGetConsumesUnresolvableEndpoint() throws Exception {
+		ContentEnricher enricher = new ContentEnricher();
+        enricher.setEnricherTarget(createServiceExchangeTarget(new QName("enricherTarget")));
+        enricher.setTarget(createServiceExchangeTarget(new QName("target")));
+        enricher.setService(new QName("enricher"));
+        enricher.setEndpoint("enricher");
+        
+        su.addEndpoint(enricher);
+        
+        List<Consumes> consumesList = analyzer.getConsumes(enricher);
+        
+        // EipServiceUnitAnalyzer's getConsumes just creates an empty array for
+        // unresolvable endpoints.  Unresolvable means that there is no resolve*()
+        // method for it in EipServiceUnitAnalyzer.java.
+        assertNotNull("getConsumes() for ContentEnricher endpoint should return a non-null
list", 
+        		consumesList);
+        assertTrue("Consumes list should contain 0 entries", consumesList.size() == 0);
+	}
+	
+	// test getXBeanFile
+	public void testGetXBeanFile() throws Exception {
+		String xbeanFile = analyzer.getXBeanFile();
+		
+		assertTrue("getXBeanFile should return xbean.xml", xbeanFile.equalsIgnoreCase("xbean.xml"));
+	}
+
+	// Dummy Endpoint implementation for testing.
+	public static class TestEndpoint implements Endpoint {
+
+		private String key;
+		
+		public TestEndpoint() {
+			key = "test";
+		}
+		
+		public void activate() throws Exception {
+		}
+
+		public void deactivate() throws Exception {
+		}
+
+		public Document getDescription() {
+			return null;
+		}
+
+		public String getEndpoint() {
+			return null;
+		}
+
+		public QName getInterfaceName() {
+			return null;
+		}
+
+		public String getKey() {
+			return key;
+		}
+
+		public Role getRole() {
+			return null;
+		}
+
+		public QName getService() {
+			return null;
+		}
+
+		public ServiceUnit getServiceUnit() {
+			return null;
+		}
+
+		public boolean isExchangeOkay(MessageExchange exchange) {
+			return false;
+		}
+
+		public void process(MessageExchange exchange) throws Exception {
+			
+		}
+
+		public void setServiceUnit(ServiceUnit serviceUnit) {
+			
+		}
+
+		public void start() throws Exception {
+			
+		}
+
+		public void stop() throws Exception {
+			
+		}
+
+		public void validate() throws DeploymentException {
+			
+		}
+		
+	}
+}

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/packaging/EipServiceUnitAnalyzerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/packaging/EipServiceUnitAnalyzerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/support/ExchangeTargetTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/support/ExchangeTargetTest.java?rev=782998&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/support/ExchangeTargetTest.java
(added)
+++ servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/support/ExchangeTargetTest.java
Tue Jun  9 13:27:42 2009
@@ -0,0 +1,78 @@
+package org.apache.servicemix.eip.support;
+
+import javax.jbi.messaging.MessagingException;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.components.util.EchoComponent;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.tck.mock.MockMessageExchange;
+
+import junit.framework.TestCase;
+
+// ExchangeTargetTest creates an ExchangeTarget object and tests the methods on it
+// that are not covered by other tests.
+public class ExchangeTargetTest extends TestCase {
+
+	private ExchangeTarget exchangeTarget;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		exchangeTarget = new ExchangeTarget();
+	}
+
+	protected void tearDown() throws Exception {
+		exchangeTarget = null;
+		super.tearDown();
+	}
+	
+	// Test afterPropertiesSet() when interface, service, and uri are all null.
+	public void testAfterPropertiesSetException() throws Exception {
+		try {
+			exchangeTarget.afterPropertiesSet();
+			fail("afterPropertiesSet should fail when interface, service, and uri are null.");
+		} catch (MessagingException me) {
+			// test succeeds
+		}
+	}
+	
+	// Test configureTarget() when interface, service, and uri are all null.
+	public void testConfigureTargetException() throws Exception {
+		try {
+			exchangeTarget.configureTarget(null, null);
+			fail("configureTarget should fail when interface, service, and uri are null.");
+		} catch (MessagingException me) {
+			// test succeeds
+		}
+	}
+	
+	// Test configureTarget() when interface, service, uri, and endpoint are set.
+	public void testConfigureTargetSet() throws Exception {
+		MockMessageExchange exchange = new MockMessageExchange();
+		EchoComponent echo = new EchoComponent();
+        echo.setService(new QName("urn:test", "echo"));
+        echo.setEndpoint("endpoint");
+        
+        JBIContainer container = new JBIContainer();
+        container.init();
+        
+        container.activateComponent(echo, "echo");
+        container.start();
+
+		exchangeTarget.setInterface(new QName("test-interface"));
+		exchangeTarget.setService(new QName("urn:test", "echo"));
+		exchangeTarget.setUri("urn:test:echo");
+		exchangeTarget.setEndpoint("endpoint");
+		
+		// configureTarget should set the interface, service, and endpoint on the
+		// exchange.
+		exchangeTarget.configureTarget(exchange, echo.getContext());
+		
+		assertNotNull("Service name should be set on the exchange", exchange.getService());
+		assertNotNull("Interface name should be set on the exchange", exchange.getInterfaceName());
+		assertNotNull("Endpoint should be set on the exchange", exchange.getEndpoint());
+		
+		container.stop();
+		
+	}
+
+}

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/support/ExchangeTargetTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/java/org/apache/servicemix/eip/support/ExchangeTargetTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch-off.properties
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch-off.properties?rev=782998&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch-off.properties
(added)
+++ servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch-off.properties
Tue Jun  9 13:27:42 2009
@@ -0,0 +1 @@
+on=false
\ No newline at end of file

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch-off.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch-off.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch-off.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch.properties
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch.properties?rev=782998&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch.properties
(added)
+++ servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch.properties
Tue Jun  9 13:27:42 2009
@@ -0,0 +1 @@
+on=true
\ No newline at end of file

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: servicemix/components/engines/servicemix-eip/trunk/src/test/resources/org/apache/servicemix/eip/switch.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message