Author: veithen
Date: Mon Jul 21 09:46:10 2008
New Revision: 678476

URL: http://svn.apache.org/viewvc?rev=678476&view=rev
Log:
* Corrected a problem in JMSUtils that prevented the JMS listener from 
correctly processing TextMessages.
* Further improvements in TransportListenerTestTemplate.
* Added test cases for TextMessages to VFSTransportListenerTest.

Added:
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/ContentTypeMode.java
Modified:
    
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSUtils.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/TransportListenerTestTemplate.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSListenerTest.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListenerTest.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTransportListenerTest.java

Modified: 
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSUtils.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSUtils.java?rev=678476&r1=678475&r2=678476&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSUtils.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/jms/JMSUtils.java
 Mon Jul 21 09:46:10 2008
@@ -324,7 +324,8 @@
                     return new ByteArrayInputStream(
                         
txtMsg.getText().getBytes(BuilderUtil.getCharSetEncoding(contentType)));
                 } else {
-                    return new 
ByteArrayInputStream(txtMsg.getText().getBytes());
+                    return new ByteArrayInputStream(
+                            
txtMsg.getText().getBytes(MessageContext.DEFAULT_CHAR_SET_ENCODING));
                 }
 
             } else {

Added: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/ContentTypeMode.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/ContentTypeMode.java?rev=678476&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/ContentTypeMode.java
 (added)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/ContentTypeMode.java
 Mon Jul 21 09:46:10 2008
@@ -0,0 +1,38 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.transport;
+
+/**
+ * Enumeration specifying how a transport listener determines the content type
+ * of a message.
+ */
+public enum ContentTypeMode {
+    /**
+     * The content type information is sent by the client using some feature
+     * of the transport protocol. Example are the Content-Type header of the 
HTTP
+     * protocol or a JMS message property. 
+     */
+    TRANSPORT,
+    
+    /**
+     * The content type is statically configured on the service.
+     */
+    SERVICE
+}

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/TransportListenerTestTemplate.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/TransportListenerTestTemplate.java?rev=678476&r1=678475&r2=678476&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/TransportListenerTestTemplate.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/TransportListenerTestTemplate.java
 Mon Jul 21 09:46:10 2008
@@ -22,7 +22,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.StringWriter;
 import java.util.Arrays;
-import java.util.List;
 import java.util.Random;
 import java.util.concurrent.TimeUnit;
 
@@ -102,28 +101,29 @@
         }
         
         /**
-         * Get the parameters necessary to configure a service to receive 
messages of
-         * a given content type through the transport under test.
+         * Set up the service so that it can receive messages through the 
transport under test.
+         * Implementations will typically call [EMAIL PROTECTED] 
AxisService#addParameter(Parameter)} to
+         * setup the service parameters required by the transport.
+         * The default implementation does nothing.
          * 
-         * @param contentType the content type
-         * @return a list of service parameters
+         * @param service
          * @throws Exception
          */
-        protected List<Parameter> getServiceParameters(String contentType) 
throws Exception {
-            return null;
+        protected void setupService(AxisService service) throws Exception {
         }
         
         /**
-         * Send a message to the transport listener. It is not recommended to 
use the
-         * corresponding transport sender to achieve this. Instead the 
implementation
-         * should use protocol specific libraries or APIs.
+         * Set up the expected content type on the given service. This method 
should only be
+         * implemented for transports that support [EMAIL PROTECTED] 
ContentTypeMode#SERVICE}.
+         * The default implementation throws an [EMAIL PROTECTED] 
UnsupportedOperationException}.
          * 
-         * @param endpointReference the endpoint reference of the service
-         * @param contentType the content type of the message
-         * @param content the content of the message
+         * @param service
+         * @param contentType the content type
          * @throws Exception
          */
-        protected abstract void sendMessage(String endpointReference, String 
contentType, byte[] content) throws Exception;
+        protected void setupContentType(AxisService service, String 
contentType) throws Exception {
+            throw new UnsupportedOperationException();
+        }
         
         public String getTestName(String baseName) {
             if (name == null) {
@@ -136,11 +136,13 @@
     
     public static abstract class TransportListenerTestCase extends TestCase {
         protected final TestStrategy strategy;
-        protected final String contentType;
+        private final ContentTypeMode contentTypeMode;
+        private final String contentType;
         
-        public TransportListenerTestCase(TestStrategy strategy, String 
baseName, String contentType) {
-            super(strategy.getTestName(baseName));
+        public TransportListenerTestCase(TestStrategy strategy, String 
baseName, ContentTypeMode contentTypeMode, String contentType) {
+            super(strategy.getTestName(baseName) + "_" + contentTypeMode);
             this.strategy = strategy;
+            this.contentTypeMode = contentTypeMode;
             this.contentType = contentType;
         }
 
@@ -174,11 +176,9 @@
             MockMessageReceiver messageReceiver = new MockMessageReceiver();
             operation.setMessageReceiver(messageReceiver);
             service.addOperation(operation);
-            List<Parameter> parameters = 
strategy.getServiceParameters(contentType);
-            if (parameters != null) {
-                for (Parameter parameter : parameters) {
-                    service.addParameter(parameter);
-                }
+            strategy.setupService(service);
+            if (contentTypeMode == ContentTypeMode.SERVICE) {
+                strategy.setupContentType(service, contentType);
             }
             axisConfiguration.addService(service);
             
@@ -190,7 +190,8 @@
                 EndpointReference[] endpointReferences
                     = 
trpInDesc.getReceiver().getEPRsForService(service.getName(), "localhost");
                 sendMessage(endpointReferences != null && 
endpointReferences.length > 0
-                                        ? endpointReferences[0].getAddress() : 
null);
+                                        ? endpointReferences[0].getAddress() : 
null,
+                                                contentTypeMode == 
ContentTypeMode.TRANSPORT ? contentType : null);
                 messageData = messageReceiver.waitForMessage(8, 
TimeUnit.SECONDS);
                 if (messageData == null) {
                     fail("Failed to get message");
@@ -203,18 +204,47 @@
             checkMessageData(messageData);
         }
         
-        protected abstract void sendMessage(String endpointReference) throws 
Exception;
+        protected abstract void sendMessage(String endpointReference, String 
contentType) throws Exception;
         protected abstract void checkMessageData(MessageData messageData) 
throws Exception;
     }
     
+    public interface XMLMessageSender {
+        void sendMessage(TestStrategy strategy, String endpointReference, 
String contentType, String charset, OMElement message) throws Exception;
+    }
+    
+    public static abstract class MessageSender implements XMLMessageSender {
+        public void sendMessage(TestStrategy strategy, String 
endpointReference, String contentType, String charset, OMElement message) 
throws Exception {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            OMOutputFormat outputFormat = new OMOutputFormat();
+            outputFormat.setCharSetEncoding(charset);
+            outputFormat.setIgnoreXMLDeclaration(true);
+            message.serializeAndConsume(baos, outputFormat);
+            sendMessage(strategy, endpointReference, contentType, 
baos.toByteArray());
+        }
+
+        /**
+         * Send a message to the transport listener. It is not recommended to 
use the
+         * corresponding transport sender to achieve this. Instead the 
implementation
+         * should use protocol specific libraries or APIs.
+         * 
+         * @param endpointReference the endpoint reference of the service
+         * @param contentType the content type of the message
+         * @param content the content of the message
+         * @throws Exception
+         */
+        public abstract void sendMessage(TestStrategy strategy, String 
endpointReference, String contentType, byte[] content) throws Exception;
+    }
+    
     public static abstract class XMLMessageTestCase extends 
TransportListenerTestCase {
+        private final XMLMessageSender sender;
         private final String text;
         private final String charset;
         private OMElement orgElement;
         protected OMFactory factory;
         
-        public XMLMessageTestCase(TestStrategy strategy, String baseName, 
String baseContentType, String text, String charset) {
-            super(strategy, baseName, baseContentType + "; charset=\"" + 
charset + "\"");
+        public XMLMessageTestCase(TestStrategy strategy, XMLMessageSender 
sender, String baseName, ContentTypeMode contentTypeMode, String 
baseContentType, String text, String charset) {
+            super(strategy, baseName, contentTypeMode, baseContentType + "; 
charset=\"" + charset + "\"");
+            this.sender = sender;
             this.text = text;
             this.charset = charset;
         }
@@ -235,13 +265,8 @@
         }
 
         @Override
-        protected void sendMessage(String endpointReference) throws Exception {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            OMOutputFormat outputFormat = new OMOutputFormat();
-            outputFormat.setCharSetEncoding(charset);
-            outputFormat.setIgnoreXMLDeclaration(true);
-            getMessage(orgElement).serializeAndConsume(baos, outputFormat);
-            strategy.sendMessage(endpointReference, contentType, 
baos.toByteArray());
+        protected void sendMessage(String endpointReference, String 
contentType) throws Exception {
+            sender.sendMessage(strategy, endpointReference, contentType, 
charset, getMessage(orgElement));
         }
         
         protected abstract OMFactory getOMFactory();
@@ -249,8 +274,8 @@
     }
     
     public static abstract class SOAPTestCase extends XMLMessageTestCase {
-        public SOAPTestCase(TestStrategy strategy, String baseName, String 
baseContentType, String text, String charset) {
-            super(strategy, baseName, baseContentType, text, charset);
+        public SOAPTestCase(TestStrategy strategy, XMLMessageSender sender, 
String baseName, ContentTypeMode contentTypeMode, String baseContentType, 
String text, String charset) {
+            super(strategy, sender, baseName, contentTypeMode, 
baseContentType, text, charset);
         }
 
         @Override
@@ -267,8 +292,8 @@
     }
     
     public static class SOAP11TestCaseImpl extends SOAPTestCase {
-        public SOAP11TestCaseImpl(TestStrategy strategy, String baseName, 
String text, String charset) {
-            super(strategy, baseName, SOAP11Constants.SOAP_11_CONTENT_TYPE, 
text, charset);
+        public SOAP11TestCaseImpl(TestStrategy strategy, XMLMessageSender 
sender, String baseName, ContentTypeMode contentTypeMode, String text, String 
charset) {
+            super(strategy, sender, baseName, contentTypeMode, 
SOAP11Constants.SOAP_11_CONTENT_TYPE, text, charset);
         }
 
         @Override
@@ -278,8 +303,8 @@
     }
     
     public static class SOAP12TestCaseImpl extends SOAPTestCase {
-        public SOAP12TestCaseImpl(TestStrategy strategy, String baseName, 
String text, String charset) {
-            super(strategy, baseName, SOAP12Constants.SOAP_12_CONTENT_TYPE, 
text, charset);
+        public SOAP12TestCaseImpl(TestStrategy strategy, XMLMessageSender 
sender, String baseName, ContentTypeMode contentTypeMode, String text, String 
charset) {
+            super(strategy, sender, baseName, contentTypeMode, 
SOAP12Constants.SOAP_12_CONTENT_TYPE, text, charset);
         }
 
         @Override
@@ -289,8 +314,8 @@
     }
     
     public static class POXTestCaseImpl extends XMLMessageTestCase {
-        public POXTestCaseImpl(TestStrategy strategy, String baseName, String 
text, String charset) {
-            super(strategy, baseName, "application/xml", text, charset);
+        public POXTestCaseImpl(TestStrategy strategy, XMLMessageSender sender, 
String baseName, ContentTypeMode contentTypeMode, String text, String charset) {
+            super(strategy, sender, baseName, contentTypeMode, 
"application/xml", text, charset);
         }
 
         @Override
@@ -305,18 +330,20 @@
     }
     
     public static class TextPlainTestCaseImpl extends 
TransportListenerTestCase {
+        private final MessageSender sender;
         private final String text;
         private final String charset;
 
-        public TextPlainTestCaseImpl(TestStrategy strategy, String baseName, 
String text, String charset) {
-            super(strategy, baseName, "text/plain; charset=\"" + charset + 
"\"");
+        public TextPlainTestCaseImpl(TestStrategy strategy, MessageSender 
sender, String baseName, ContentTypeMode contentTypeMode, String text, String 
charset) {
+            super(strategy, baseName, contentTypeMode, "text/plain; 
charset=\"" + charset + "\"");
+            this.sender = sender;
             this.text = text;
             this.charset = charset;
         }
 
         @Override
-        protected void sendMessage(String endpointReference) throws Exception {
-            strategy.sendMessage(endpointReference, contentType, 
text.getBytes(charset));
+        protected void sendMessage(String endpointReference, String 
contentType) throws Exception {
+            sender.sendMessage(strategy, endpointReference, contentType, 
text.getBytes(charset));
         }
         
         @Override
@@ -332,24 +359,24 @@
     
     private static final Random random = new Random();
 
-    public static void addSOAPTests(final TestStrategy strategy, TestSuite 
suite) {
-        suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11ASCII", "test 
string", "us-ascii"));
-        suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11UTF8", 
testString, "UTF-8"));
-        suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11Latin1", 
testString, "ISO-8859-1"));
-        suite.addTest(new SOAP12TestCaseImpl(strategy, "SOAP12ASCII", "test 
string", "us-ascii"));
-        suite.addTest(new SOAP12TestCaseImpl(strategy, "SOAP12UTF8", 
testString, "UTF-8"));
-        suite.addTest(new SOAP12TestCaseImpl(strategy, "SOAP12Latin1", 
testString, "ISO-8859-1"));
+    public static void addSOAPTests(TestStrategy strategy, XMLMessageSender 
sender, TestSuite suite, ContentTypeMode contentTypeMode) {
+        suite.addTest(new SOAP11TestCaseImpl(strategy, sender, "SOAP11ASCII", 
contentTypeMode, "test string", "us-ascii"));
+        suite.addTest(new SOAP11TestCaseImpl(strategy, sender, "SOAP11UTF8", 
contentTypeMode, testString, "UTF-8"));
+        suite.addTest(new SOAP11TestCaseImpl(strategy, sender, "SOAP11Latin1", 
contentTypeMode, testString, "ISO-8859-1"));
+        suite.addTest(new SOAP12TestCaseImpl(strategy, sender, "SOAP12ASCII", 
contentTypeMode, "test string", "us-ascii"));
+        suite.addTest(new SOAP12TestCaseImpl(strategy, sender, "SOAP12UTF8", 
contentTypeMode, testString, "UTF-8"));
+        suite.addTest(new SOAP12TestCaseImpl(strategy, sender, "SOAP12Latin1", 
contentTypeMode, testString, "ISO-8859-1"));
     }
     
-    public static void addPOXTests(final TestStrategy strategy, TestSuite 
suite) {
-        suite.addTest(new POXTestCaseImpl(strategy, "POXASCII", "test string", 
"us-ascii"));
-        suite.addTest(new POXTestCaseImpl(strategy, "POXUTF8", testString, 
"UTF-8"));
-        suite.addTest(new POXTestCaseImpl(strategy, "POXLatin1", testString, 
"ISO-8859-1"));
+    public static void addPOXTests(TestStrategy strategy, XMLMessageSender 
sender, TestSuite suite, ContentTypeMode contentTypeMode) {
+        suite.addTest(new POXTestCaseImpl(strategy, sender, "POXASCII", 
contentTypeMode, "test string", "us-ascii"));
+        suite.addTest(new POXTestCaseImpl(strategy, sender, "POXUTF8", 
contentTypeMode, testString, "UTF-8"));
+        suite.addTest(new POXTestCaseImpl(strategy, sender, "POXLatin1", 
contentTypeMode, testString, "ISO-8859-1"));
     }
     
     // TODO: this test actually only makes sense if the transport supports a 
Content-Type header
-    public static void addSwATests(TestStrategy strategy, TestSuite suite) {
-        suite.addTest(new TransportListenerTestCase(strategy, 
"SOAPWithAttachments", null) {
+    public static void addSwATests(final TestStrategy strategy, final 
MessageSender sender, TestSuite suite) {
+        suite.addTest(new TransportListenerTestCase(strategy, 
"SOAPWithAttachments", ContentTypeMode.TRANSPORT, null) {
             private byte[] attachmentContent;
             private String contentID;
             
@@ -361,7 +388,7 @@
             }
 
             @Override
-            protected void sendMessage(String endpointReference) throws 
Exception {
+            protected void sendMessage(String endpointReference, String 
contentType) throws Exception {
                 SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
                 SOAPEnvelope orgEnvelope = factory.createSOAPEnvelope();
                 SOAPBody orgBody = factory.createSOAPBody();
@@ -377,7 +404,7 @@
                 orgAttachments.addDataHandler(contentID, new DataHandler(new 
ByteArrayDataSource(attachmentContent, "application/octet-stream")));
                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 MIMEOutputUtils.writeSOAPWithAttachmentsMessage(writer, baos, 
orgAttachments, outputFormat);
-                strategy.sendMessage(endpointReference, 
outputFormat.getContentTypeForSwA(SOAP12Constants.SOAP_12_CONTENT_TYPE), 
baos.toByteArray());
+                sender.sendMessage(strategy, endpointReference, 
outputFormat.getContentTypeForSwA(SOAP12Constants.SOAP_12_CONTENT_TYPE), 
baos.toByteArray());
             }
 
             @Override
@@ -392,14 +419,14 @@
         });
     }
     
-    public static void addTextPlainTests(final TestStrategy strategy, 
TestSuite suite) {
-        suite.addTest(new TextPlainTestCaseImpl(strategy, "TextPlainASCII", 
"test string", "us-ascii"));
-        suite.addTest(new TextPlainTestCaseImpl(strategy, "TextPlainUTF8", 
testString, "UTF-8"));
-        suite.addTest(new TextPlainTestCaseImpl(strategy, "TextPlainLatin1", 
testString, "ISO-8859-1"));
+    public static void addTextPlainTests(TestStrategy strategy, MessageSender 
sender, TestSuite suite, ContentTypeMode contentTypeMode) {
+        suite.addTest(new TextPlainTestCaseImpl(strategy, sender, 
"TextPlainASCII", contentTypeMode, "test string", "us-ascii"));
+        suite.addTest(new TextPlainTestCaseImpl(strategy, sender, 
"TextPlainUTF8", contentTypeMode, testString, "UTF-8"));
+        suite.addTest(new TextPlainTestCaseImpl(strategy, sender, 
"TextPlainLatin1", contentTypeMode, testString, "ISO-8859-1"));
     }
     
-    public static void addBinaryTest(final TestStrategy strategy, TestSuite 
suite) {
-        suite.addTest(new TransportListenerTestCase(strategy, "Binary", 
"application/octet-stream") {
+    public static void addBinaryTest(final TestStrategy strategy, final 
MessageSender sender, TestSuite suite, ContentTypeMode contentTypeMode) {
+        suite.addTest(new TransportListenerTestCase(strategy, "Binary", 
contentTypeMode, "application/octet-stream") {
             private byte[] content;
             
             @Override
@@ -409,8 +436,8 @@
             }
 
             @Override
-            protected void sendMessage(String endpointReference) throws 
Exception {
-                strategy.sendMessage(endpointReference, contentType, content);
+            protected void sendMessage(String endpointReference, String 
contentType) throws Exception {
+                sender.sendMessage(strategy, endpointReference, contentType, 
content);
             }
             
             @Override

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSListenerTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSListenerTest.java?rev=678476&r1=678475&r2=678476&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSListenerTest.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSListenerTest.java
 Mon Jul 21 09:46:10 2008
@@ -19,20 +19,20 @@
 
 package org.apache.synapse.transport.jms;
 
-import java.util.LinkedList;
-import java.util.List;
+import java.io.StringWriter;
 
 import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
 import javax.jms.Queue;
 import javax.jms.QueueConnection;
 import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueSender;
 import javax.jms.QueueSession;
 import javax.jms.Session;
+import javax.jms.TextMessage;
 import javax.jms.Topic;
 import javax.jms.TopicConnection;
 import javax.jms.TopicConnectionFactory;
-import javax.jms.TopicPublisher;
 import javax.jms.TopicSession;
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -43,15 +43,20 @@
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.TransportInDescription;
+import org.apache.synapse.transport.ContentTypeMode;
 import org.apache.synapse.transport.TransportListenerTestTemplate;
 import org.apache.synapse.transport.base.BaseConstants;
 import org.mockejb.jndi.MockContextFactory;
 
 import com.mockrunner.jms.ConfigurationManager;
 import com.mockrunner.jms.DestinationManager;
+import com.mockrunner.mock.jms.MockConnectionFactory;
+import com.mockrunner.mock.jms.MockDestination;
 import com.mockrunner.mock.jms.MockQueueConnectionFactory;
 import com.mockrunner.mock.jms.MockTopicConnectionFactory;
 
@@ -60,13 +65,13 @@
         private final OMFactory factory = OMAbstractFactory.getOMFactory();
         
         private final boolean useTopic;
-        private final boolean useContentTypeHeader;
         
-        public TestStrategyImpl(boolean useTopic, boolean 
useContentTypeHeader) {
-            super((useTopic ? "Topic" : "Queue") +
-                    (useContentTypeHeader ? "WithContentTypeHeader" : 
"WithoutContentTypeHeader"));
+        private MockConnectionFactory connectionFactory;
+        private MockDestination destination;
+        
+        public TestStrategyImpl(boolean useTopic) {
+            super(useTopic ? "Topic" : "Queue");
             this.useTopic = useTopic;
-            this.useContentTypeHeader = useContentTypeHeader;
         }
 
         private OMElement createParameterElement(String name, String value) {
@@ -85,14 +90,14 @@
             DestinationManager destinationManager = new DestinationManager();
             ConfigurationManager configurationManager = new 
ConfigurationManager();
             if (useTopic) {
-                context.bind("ConnectionFactory",
-                        new MockTopicConnectionFactory(destinationManager, 
configurationManager));
-                context.bind("TestService", 
destinationManager.createTopic("TestService"));
+                connectionFactory = new 
MockTopicConnectionFactory(destinationManager, configurationManager);
+                destination = destinationManager.createTopic("TestService");
             } else {
-                context.bind("ConnectionFactory",
-                        new MockQueueConnectionFactory(destinationManager, 
configurationManager));
-                context.bind("TestService", 
destinationManager.createQueue("TestService"));
+                connectionFactory = new 
MockQueueConnectionFactory(destinationManager, configurationManager);
+                destination = destinationManager.createQueue("TestService");
             }
+            context.bind("ConnectionFactory", connectionFactory);
+            context.bind("TestService", destination);
             
             TransportInDescription trpInDesc = new 
TransportInDescription(JMSListener.TRANSPORT_NAME);
             OMElement element = 
createParameterElement(JMSConstants.DEFAULT_CONFAC_NAME, null);
@@ -108,73 +113,104 @@
         }
     
         @Override
-        protected List<Parameter> getServiceParameters(String contentType) 
throws Exception {
-            List<Parameter> params = new LinkedList<Parameter>();
-            params.add(new Parameter(JMSConstants.DEST_PARAM_TYPE,
+        protected void setupService(AxisService service) throws Exception {
+            service.addParameter(JMSConstants.DEST_PARAM_TYPE,
                     useTopic ? JMSConstants.DESTINATION_TYPE_TOPIC
-                             : JMSConstants.DESTINATION_TYPE_QUEUE));
-            return params;
+                             : JMSConstants.DESTINATION_TYPE_QUEUE);
         }
-    
+
         @Override
-        protected void sendMessage(String endpointReference,
-                                   String contentType,
-                                   byte[] content) throws Exception {
-            Context context = new InitialContext();
+        protected void setupContentType(AxisService service, String 
contentType) throws Exception {
+            // TODO: this is not yet supported.
+        }
+    
+        public boolean isUseTopic() {
+            return useTopic;
+        }
+        
+        public Session createSession() throws JMSException {
             if (useTopic) {
-                TopicConnectionFactory connFactory
-                    = 
(TopicConnectionFactory)context.lookup("ConnectionFactory");
-                Topic topic = (Topic)context.lookup("TestService");
-                TopicConnection connection = 
connFactory.createTopicConnection();
-                TopicSession session
-                    = connection.createTopicSession(false, 
Session.AUTO_ACKNOWLEDGE);
-                TopicPublisher publisher = session.createPublisher(topic);
-                BytesMessage message = session.createBytesMessage();
-                if (useContentTypeHeader) {
-                    message.setStringProperty(BaseConstants.CONTENT_TYPE, 
contentType);
-                }
-                message.writeBytes(content);
-                publisher.send(message);
+                TopicConnection connection = 
((TopicConnectionFactory)connectionFactory).createTopicConnection();
+                return connection.createTopicSession(false, 
Session.AUTO_ACKNOWLEDGE);
             } else {
-                QueueConnectionFactory connFactory
-                    = 
(QueueConnectionFactory)context.lookup("ConnectionFactory");
-                Queue queue = (Queue)context.lookup("TestService");
-                QueueConnection connection = 
connFactory.createQueueConnection();
-                QueueSession session
-                    = connection.createQueueSession(false, 
Session.AUTO_ACKNOWLEDGE);
-                QueueSender sender = session.createSender(queue);
-                BytesMessage message = session.createBytesMessage();
-                if (useContentTypeHeader) {
-                    message.setStringProperty(BaseConstants.CONTENT_TYPE, 
contentType);
-                }
-                message.writeBytes(content);
-                sender.send(message);
+                QueueConnection connection = 
((QueueConnectionFactory)connectionFactory).createQueueConnection();
+                return connection.createQueueSession(false, 
Session.AUTO_ACKNOWLEDGE);
             }
         }
+
+        public void send(Session session, Message message) throws JMSException 
{
+            if (useTopic) {
+                
((TopicSession)session).createPublisher((Topic)destination).send(message);
+            } else {
+                
((QueueSession)session).createProducer((Queue)destination).send(message);
+            }
+        }
+    }
+    
+    private static class BytesMessageSender extends MessageSender {
+        @Override
+        public void sendMessage(TestStrategy _strategy,
+                                String endpointReference,
+                                String contentType,
+                                byte[] content) throws Exception {
+            TestStrategyImpl strategy = (TestStrategyImpl)_strategy;
+            Session session = strategy.createSession();
+            BytesMessage message = session.createBytesMessage();
+            if (contentType != null) {
+                message.setStringProperty(BaseConstants.CONTENT_TYPE, 
contentType);
+            }
+            message.writeBytes(content);
+            strategy.send(session, message);
+        }
+    }
+    
+    private static class TextMessageSender implements XMLMessageSender {
+        public void sendMessage(TestStrategy _strategy,
+                String endpointReference, String contentType, String charset,
+                OMElement omMessage) throws Exception {
+            TestStrategyImpl strategy = (TestStrategyImpl)_strategy;
+            Session session = strategy.createSession();
+            TextMessage message = session.createTextMessage();
+            if (contentType != null) {
+                message.setStringProperty(BaseConstants.CONTENT_TYPE, 
contentType);
+            }
+            OMOutputFormat format = new OMOutputFormat();
+            format.setIgnoreXMLDeclaration(true);
+            StringWriter sw = new StringWriter();
+            omMessage.serializeAndConsume(sw, format);
+            message.setText(sw.toString());
+            strategy.send(session, message);
+        }
     }
     
     public static TestSuite suite() {
         TestSuite suite = new TestSuite();
+        BytesMessageSender bytesMessageSender = new BytesMessageSender();
+        TextMessageSender textMessageSender = new TextMessageSender();
         for (boolean useTopic : new boolean[] { false, true }) {
-            for (boolean useContentTypeHeader : new boolean[] { false, true }) 
{
-                TestStrategy strategy = new TestStrategyImpl(useTopic, 
useContentTypeHeader);
-                if (useContentTypeHeader) {
-                    addSOAPTests(strategy, suite);
-                    addPOXTests(strategy, suite);
-                    addSwATests(strategy, suite);
-                } else {
-                    // If no content type header is used, SwA can't be used 
and the JMS transport
-                    // always uses the default charset encoding
-                    suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11", 
testString,
-                            MessageContext.DEFAULT_CHAR_SET_ENCODING));
-                    suite.addTest(new SOAP12TestCaseImpl(strategy, "SOAP12", 
testString,
-                            MessageContext.DEFAULT_CHAR_SET_ENCODING));
-                    suite.addTest(new POXTestCaseImpl(strategy, "POX", 
testString,
-                            MessageContext.DEFAULT_CHAR_SET_ENCODING));
+            TestStrategy strategy = new TestStrategyImpl(useTopic);
+            for (ContentTypeMode contentTypeMode : ContentTypeMode.values()) {
+                for (XMLMessageSender sender : new XMLMessageSender[] { 
bytesMessageSender, textMessageSender }) {
+                    if (contentTypeMode == ContentTypeMode.TRANSPORT) {
+                        addSOAPTests(strategy, sender, suite, contentTypeMode);
+                        addPOXTests(strategy, sender, suite, contentTypeMode);
+                    } else {
+                        // If no content type header is used, SwA can't be 
used and the JMS transport
+                        // always uses the default charset encoding
+                        suite.addTest(new SOAP11TestCaseImpl(strategy, sender, 
"SOAP11", contentTypeMode, testString,
+                                MessageContext.DEFAULT_CHAR_SET_ENCODING));
+                        suite.addTest(new SOAP12TestCaseImpl(strategy, sender, 
"SOAP12", contentTypeMode, testString,
+                                MessageContext.DEFAULT_CHAR_SET_ENCODING));
+                        suite.addTest(new POXTestCaseImpl(strategy, sender, 
"POX", contentTypeMode, testString,
+                                MessageContext.DEFAULT_CHAR_SET_ENCODING));
+                    }
+                }
+                if (contentTypeMode == ContentTypeMode.TRANSPORT) {
+                    addSwATests(strategy, bytesMessageSender, suite);
                 }
                 // TODO: these tests are temporarily disabled because of 
SYNAPSE-304
                 // addTextPlainTests(strategy, suite);
-                addBinaryTest(strategy, suite);
+                addBinaryTest(strategy, bytesMessageSender, suite, 
contentTypeMode);
             }
         }
         return suite;

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java?rev=678476&r1=678475&r2=678476&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
 Mon Jul 21 09:46:10 2008
@@ -19,9 +19,7 @@
 
 package org.apache.synapse.transport.mail;
 
-import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
 import java.util.Properties;
 
 import javax.activation.DataHandler;
@@ -36,21 +34,15 @@
 
 import junit.framework.TestSuite;
 
-import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.TransportInDescription;
+import org.apache.synapse.transport.ContentTypeMode;
 import org.apache.synapse.transport.TransportListenerTestTemplate;
 
 public class MailTransportListenerTest extends TransportListenerTestTemplate {
+    private static final String ADDRESS = "[EMAIL PROTECTED]";
+    
     public static class TestStrategyImpl extends TestStrategy {
-        private static final String ADDRESS = "[EMAIL PROTECTED]";
-        
-        private boolean useMultipart;
-        
-        public TestStrategyImpl(boolean useMultipart) {
-            super(useMultipart ? "Multipart" : null);
-            this.useMultipart = useMultipart;
-        }
-
         @Override
         protected TransportInDescription createTransportInDescription() {
             TransportInDescription trpInDesc
@@ -60,21 +52,19 @@
         }
     
         @Override
-        protected List<Parameter> getServiceParameters(String contentType) 
throws Exception {
-            List<Parameter> parameters = new ArrayList<Parameter>();
-            parameters.add(new Parameter("transport.mail.Protocol", 
"test-store"));
-            parameters.add(new Parameter("transport.mail.Address", ADDRESS));
-            parameters.add(new Parameter("transport.PollInterval", "1"));
+        protected void setupService(AxisService service) throws Exception {
+            service.addParameter("transport.mail.Protocol", "test-store");
+            service.addParameter("transport.mail.Address", ADDRESS);
+            service.addParameter("transport.PollInterval", "1");
             // TODO: logically, this should be mail.test-store.user and 
mail.test-store.password
-            parameters.add(new Parameter("mail.pop3.user", ADDRESS));
-            parameters.add(new Parameter("mail.pop3.password", "dummy"));
-            return parameters;
+            service.addParameter("mail.pop3.user", ADDRESS);
+            service.addParameter("mail.pop3.password", "dummy");
         }
+    }
     
+    private static abstract class MailSender extends MessageSender {
         @Override
-        protected void sendMessage(String endpointReference,
-                                   String contentType,
-                                   byte[] content) throws Exception {
+        public void sendMessage(TestStrategy strategy, String 
endpointReference, String contentType, byte[] content) throws Exception {
             Properties props = new Properties();
             props.put("mail.smtp.class", TestTransport.class.getName());
             Session session = Session.getInstance(props);
@@ -83,32 +73,44 @@
             msg.setFrom(new InternetAddress("[EMAIL PROTECTED]"));
             msg.setSentDate(new Date());
             DataHandler dh = new DataHandler(new ByteArrayDataSource(content, 
contentType));
-            if (useMultipart) {
-                MimeMultipart multipart = new MimeMultipart();
-                MimeBodyPart part1 = new MimeBodyPart();
-                part1.setContent("This is an automated message.", 
"text/plain");
-                multipart.addBodyPart(part1);
-                MimeBodyPart part2 = new MimeBodyPart();
-                part2.setDataHandler(dh);
-                multipart.addBodyPart(part2);
-                msg.setContent(multipart);
-            } else {
-                msg.setDataHandler(dh);
-            }
+            setupMessage(msg, dh);
             Transport.send(msg);
         }
+        
+        protected abstract void setupMessage(MimeMessage msg, DataHandler dh) 
throws Exception;
+    }
+    
+    private static class MimeSender extends MailSender {
+        @Override
+        protected void setupMessage(MimeMessage msg, DataHandler dh) throws 
Exception {
+            msg.setDataHandler(dh);
+        }
+    }
+    
+    private static class MultipartSender extends MailSender {
+        @Override
+        protected void setupMessage(MimeMessage msg, DataHandler dh) throws 
Exception {
+            MimeMultipart multipart = new MimeMultipart();
+            MimeBodyPart part1 = new MimeBodyPart();
+            part1.setContent("This is an automated message.", "text/plain");
+            multipart.addBodyPart(part1);
+            MimeBodyPart part2 = new MimeBodyPart();
+            part2.setDataHandler(dh);
+            multipart.addBodyPart(part2);
+            msg.setContent(multipart);
+        }
     }
     
     public static TestSuite suite() {
         TestSuite suite = new TestSuite();
-        for (boolean useMultipart : new boolean[] { false, true }) {
-            TestStrategy strategy = new TestStrategyImpl(useMultipart);
+        TestStrategy strategy = new TestStrategyImpl();
+        for (MessageSender sender : new MessageSender[] { new MimeSender(), 
new MultipartSender() }) {
             // TODO: SOAP 1.2 tests don't work yet for mail transport
-            suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11ASCII", 
"test string", "us-ascii"));
-            suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11UTF8", 
testString, "UTF-8"));
+            suite.addTest(new SOAP11TestCaseImpl(strategy, sender, 
"SOAP11ASCII", ContentTypeMode.TRANSPORT, "test string", "us-ascii"));
+            suite.addTest(new SOAP11TestCaseImpl(strategy, sender, 
"SOAP11UTF8", ContentTypeMode.TRANSPORT, testString, "UTF-8"));
             // TODO: this test fails when using multipart
-            if (!useMultipart) {
-                suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11Latin1", 
testString, "ISO-8859-1"));
+            if (sender instanceof MimeSender) {
+                suite.addTest(new SOAP11TestCaseImpl(strategy, sender, 
"SOAP11Latin1", ContentTypeMode.TRANSPORT, testString, "ISO-8859-1"));
             }
             // addSOAPTests(strategy, suite);
             // TODO: POX tests don't work yet for mail transport

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListenerTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListenerTest.java?rev=678476&r1=678475&r2=678476&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListenerTest.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/nhttp/HttpCoreNIOListenerTest.java
 Mon Jul 21 09:46:10 2008
@@ -28,6 +28,7 @@
 
 import org.apache.axis2.description.TransportInDescription;
 import org.apache.commons.io.IOUtils;
+import org.apache.synapse.transport.ContentTypeMode;
 import org.apache.synapse.transport.DefaultOperationDispatcher;
 import org.apache.synapse.transport.MessageData;
 import org.apache.synapse.transport.TransportListenerTestTemplate;
@@ -40,9 +41,11 @@
             trpInDesc.setReceiver(new HttpCoreNIOListener());
             return trpInDesc;
         }
-
+    }
+    
+    public static class JavaNetSender extends MessageSender {
         @Override
-        protected void sendMessage(String endpointReference, String 
contentType, byte[] content) throws Exception {
+        public void sendMessage(TestStrategy strategy, String 
endpointReference, String contentType, byte[] content) throws Exception {
             URLConnection connection = new 
URL(endpointReference).openConnection();
             connection.setDoOutput(true);
             connection.setDoInput(true);
@@ -59,14 +62,15 @@
     public static TestSuite suite() {
         TestSuite suite = new TestSuite();
         TestStrategy strategy = new TestStrategyImpl();
-        addSOAPTests(strategy, suite);
-        addPOXTests(strategy, suite);
-        addSwATests(strategy, suite);
-        addTextPlainTests(strategy, suite);
-        addBinaryTest(strategy, suite);
-        suite.addTest(new TransportListenerTestCase(strategy, "REST", null) {
+        MessageSender sender = new JavaNetSender();
+        addSOAPTests(strategy, sender, suite, ContentTypeMode.TRANSPORT);
+        addPOXTests(strategy, sender, suite, ContentTypeMode.TRANSPORT);
+        addSwATests(strategy, sender, suite);
+        addTextPlainTests(strategy, sender, suite, ContentTypeMode.TRANSPORT);
+        addBinaryTest(strategy, sender, suite, ContentTypeMode.TRANSPORT);
+        suite.addTest(new TransportListenerTestCase(strategy, "REST", 
ContentTypeMode.TRANSPORT, null) {
             @Override
-            protected void sendMessage(String endpointReference) throws 
Exception {
+            protected void sendMessage(String endpointReference, String 
contentType) throws Exception {
                 URLConnection connection = new URL(endpointReference + "/" + 
DefaultOperationDispatcher.DEFAULT_OPERATION_NAME).openConnection();
                 connection.setDoInput(true);
                 InputStream in = connection.getInputStream();

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTransportListenerTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTransportListenerTest.java?rev=678476&r1=678475&r2=678476&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTransportListenerTest.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTransportListenerTest.java
 Mon Jul 21 09:46:10 2008
@@ -22,13 +22,12 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.List;
 
 import junit.framework.TestSuite;
 
-import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.TransportInDescription;
+import org.apache.synapse.transport.ContentTypeMode;
 import org.apache.synapse.transport.TransportListenerTestTemplate;
 
 /**
@@ -53,17 +52,21 @@
         }
         
         @Override
-        protected List<Parameter> getServiceParameters(String contentType) 
throws Exception {
-            List<Parameter> parameters = new ArrayList<Parameter>();
-            parameters.add(new Parameter("transport.vfs.FileURI", "vfs:" + 
requestFile.toURL()));
-            parameters.add(new Parameter("transport.vfs.ContentType", 
contentType));
-            parameters.add(new Parameter("transport.PollInterval", "1"));
-            parameters.add(new Parameter("transport.vfs.ActionAfterProcess", 
"DELETE"));
-            return parameters;
+        protected void setupService(AxisService service) throws Exception {
+            service.addParameter("transport.vfs.FileURI", "vfs:" + 
requestFile.toURL());
+            service.addParameter("transport.PollInterval", "1");
+            service.addParameter("transport.vfs.ActionAfterProcess", "DELETE");
         }
-        
+
+        @Override
+        protected void setupContentType(AxisService service, String 
contentType) throws Exception {
+            service.addParameter("transport.vfs.ContentType", contentType);
+        }
+    }
+    
+    private static class MessageSenderImpl extends MessageSender {
         @Override
-        protected void sendMessage(String endpointReference, String 
contentType, byte[] content) throws Exception {
+        public void sendMessage(TestStrategy strategy, String 
endpointReference, String contentType, byte[] content) throws Exception {
             OutputStream out = new FileOutputStream("target/vfs3/req/in");
             out.write(content);
             out.close();
@@ -73,11 +76,12 @@
     public static TestSuite suite() {
         TestSuite suite = new TestSuite();
         TestStrategy strategy = new TestStrategyImpl();
-        addSOAPTests(strategy, suite);
-        addPOXTests(strategy, suite);
+        MessageSender sender = new MessageSenderImpl();
+        addSOAPTests(strategy, sender, suite, ContentTypeMode.SERVICE);
+        addPOXTests(strategy, sender, suite, ContentTypeMode.SERVICE);
         // Since VFS has no Content-Type header, SwA is not supported.
-        addTextPlainTests(strategy, suite);
-        addBinaryTest(strategy, suite);
+        addTextPlainTests(strategy, sender, suite, ContentTypeMode.SERVICE);
+        addBinaryTest(strategy, sender, suite, ContentTypeMode.SERVICE);
         return suite;
     }
 }


Reply via email to