Added: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSMockAsyncEndpoint.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSMockAsyncEndpoint.java?rev=684448&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSMockAsyncEndpoint.java
 (added)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSMockAsyncEndpoint.java
 Sun Aug 10 03:28:24 2008
@@ -0,0 +1,64 @@
+/*
+ *  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.vfs;
+
+import java.io.File;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.synapse.transport.testkit.message.ByteArrayMessage;
+import org.apache.synapse.transport.testkit.server.AsyncEndpoint;
+
+import de.schlichtherle.io.FileInputStream;
+
+public class VFSMockAsyncEndpoint implements AsyncEndpoint<ByteArrayMessage> {
+    private final VFSFileChannel channel;
+    private final String contentType;
+    
+    public VFSMockAsyncEndpoint(VFSFileChannel channel, String contentType) {
+        this.channel = channel;
+        this.contentType = contentType;
+    }
+    
+    public String getEPR() throws Exception {
+        return "vfs:file:" + channel.getRequestFile().getAbsolutePath();
+    }
+
+    public ByteArrayMessage waitForMessage(int timeout) throws Throwable {
+        long time = System.currentTimeMillis();
+        File file = channel.getRequestFile();
+        while (System.currentTimeMillis() < time + timeout) {
+            if (file.exists()) {
+                InputStream in = new FileInputStream(file);
+                try {
+                    return new ByteArrayMessage(contentType, 
IOUtils.toByteArray(in));
+                } finally {
+                    in.close();
+                }
+            }
+            Thread.sleep(100);
+        }
+        return null;
+    }
+
+    public void remove() throws Exception {
+        // Nothing to do
+    }
+}

Added: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTestSetup.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTestSetup.java?rev=684448&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTestSetup.java
 (added)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTestSetup.java
 Sun Aug 10 03:28:24 2008
@@ -0,0 +1,30 @@
+/*
+ *  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.vfs;
+
+import org.apache.axis2.description.AxisService;
+import org.apache.synapse.transport.testkit.listener.ListenerTestSetup;
+
+public class VFSTestSetup extends ListenerTestSetup {
+    @Override
+    public void setupContentType(AxisService service, String contentType) 
throws Exception {
+        service.addParameter("transport.vfs.ContentType", contentType);
+    }
+}
\ No newline at end of file

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=684448&r1=684447&r2=684448&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
 Sun Aug 10 03:28:24 2008
@@ -19,6 +19,8 @@
 
 package org.apache.synapse.transport.vfs;
 
+import static org.apache.synapse.transport.testkit.AdapterUtils.adapt;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.OutputStream;
@@ -28,31 +30,21 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-import org.apache.axis2.description.AxisService;
 import org.apache.synapse.transport.testkit.listener.AbstractMessageSender;
-import org.apache.synapse.transport.testkit.listener.Adapter;
 import org.apache.synapse.transport.testkit.listener.AsyncMessageSender;
 import org.apache.synapse.transport.testkit.listener.AxisAsyncMessageSender;
-import org.apache.synapse.transport.testkit.listener.ByteArrayMessage;
 import org.apache.synapse.transport.testkit.listener.ContentTypeMode;
-import org.apache.synapse.transport.testkit.listener.ListenerTestSetup;
 import org.apache.synapse.transport.testkit.listener.ListenerTestSuite;
 import org.apache.synapse.transport.testkit.listener.SenderOptions;
-import org.apache.synapse.transport.testkit.listener.XMLMessage;
-import org.apache.synapse.transport.testkit.server.Server;
+import org.apache.synapse.transport.testkit.message.ByteArrayMessage;
+import org.apache.synapse.transport.testkit.message.MessageConverter;
+import org.apache.synapse.transport.testkit.message.XMLMessage;
 import org.apache.synapse.transport.testkit.server.axis2.AxisServer;
 
 /**
  * TransportListenerTestTemplate implementation for the VFS transport.
  */
 public class VFSTransportListenerTest extends TestCase {
-    public static class TestStrategyImpl extends ListenerTestSetup {
-        @Override
-        public void setupContentType(AxisService service, String contentType) 
throws Exception {
-            service.addParameter("transport.vfs.ContentType", contentType);
-        }
-    }
-    
     private static class MessageSenderImpl extends 
AbstractMessageSender<VFSFileChannel> implements 
AsyncMessageSender<VFSFileChannel,ByteArrayMessage> {
         public void sendMessage(VFSFileChannel channel, SenderOptions options, 
ByteArrayMessage message) throws Exception {
             OutputStream out = new FileOutputStream(channel.getRequestFile());
@@ -64,20 +56,20 @@
     public static TestSuite suite() {
         // TODO: the VFS listener doesn't like reuseServer == true...
         ListenerTestSuite suite = new ListenerTestSuite(false);
-        TestStrategyImpl setup = new TestStrategyImpl();
-        Server<TestStrategyImpl> server = new 
AxisServer<TestStrategyImpl>(setup);
+        VFSTestSetup setup = new VFSTestSetup();
+        AxisServer<VFSTestSetup> server = new AxisServer<VFSTestSetup>(setup);
         VFSFileChannel channel = new VFSFileChannel(server, new 
File("target/vfs3/req/in").getAbsoluteFile());
         MessageSenderImpl vfsSender = new MessageSenderImpl();
         List<AsyncMessageSender<? super VFSFileChannel,XMLMessage>> senders = 
new LinkedList<AsyncMessageSender<? super VFSFileChannel,XMLMessage>>();
-        senders.add(new Adapter<VFSFileChannel>(vfsSender));
+        senders.add(adapt(vfsSender, MessageConverter.XML_TO_BYTE));
         senders.add(new AxisAsyncMessageSender());
         for (AsyncMessageSender<? super VFSFileChannel,XMLMessage> sender : 
senders) {
-            suite.addSOAPTests(channel, sender, ContentTypeMode.SERVICE);
-            suite.addPOXTests(channel, sender, ContentTypeMode.SERVICE);
+            suite.addSOAPTests(channel, sender, server, 
ContentTypeMode.SERVICE);
+            suite.addPOXTests(channel, sender, server, 
ContentTypeMode.SERVICE);
             // Since VFS has no Content-Type header, SwA is not supported.
         }
-        suite.addTextPlainTests(channel, vfsSender, ContentTypeMode.SERVICE);
-        suite.addBinaryTest(channel, vfsSender, ContentTypeMode.SERVICE);
+        suite.addTextPlainTests(channel, adapt(vfsSender, 
MessageConverter.STRING_TO_BYTE), adapt(server, 
MessageConverter.AXIS_TO_STRING), ContentTypeMode.SERVICE);
+        suite.addBinaryTest(channel, vfsSender, adapt(server, 
MessageConverter.AXIS_TO_BYTE), ContentTypeMode.SERVICE);
         return suite;
     }
 }

Added: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTransportSenderTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTransportSenderTest.java?rev=684448&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTransportSenderTest.java
 (added)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/vfs/VFSTransportSenderTest.java
 Sun Aug 10 03:28:24 2008
@@ -0,0 +1,64 @@
+/*
+ *  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.vfs;
+
+import static org.apache.synapse.transport.testkit.AdapterUtils.adapt;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.synapse.transport.testkit.listener.AxisAsyncMessageSender;
+import org.apache.synapse.transport.testkit.listener.ContentTypeMode;
+import org.apache.synapse.transport.testkit.listener.ListenerTestSuite;
+import org.apache.synapse.transport.testkit.message.ByteArrayMessage;
+import org.apache.synapse.transport.testkit.message.MessageConverter;
+import org.apache.synapse.transport.testkit.server.AsyncEndpoint;
+import org.apache.synapse.transport.testkit.server.AsyncEndpointFactory;
+import org.apache.synapse.transport.testkit.server.DummyServer;
+
+public class VFSTransportSenderTest extends TestCase {
+    public static TestSuite suite() {
+        // TODO: ListenerTestSuite is inappropriate!
+        ListenerTestSuite suite = new ListenerTestSuite();
+        
+        VFSTestSetup setup = new VFSTestSetup();
+        
+        AsyncEndpointFactory<VFSFileChannel,ByteArrayMessage> endpointFactory =
+            new AsyncEndpointFactory<VFSFileChannel,ByteArrayMessage>() {
+            
+            public AsyncEndpoint<ByteArrayMessage> createAsyncEndpoint(
+                    VFSFileChannel channel, String contentType)
+                    throws Exception {
+                
+                return new VFSMockAsyncEndpoint(channel, contentType);
+            }
+        };
+        
+        VFSFileChannel channel = new VFSFileChannel(new 
DummyServer<VFSTestSetup>(setup), new 
File("target/vfs3/req/in").getAbsoluteFile());
+        AxisAsyncMessageSender sender = new AxisAsyncMessageSender();
+        
+        suite.addBinaryTest(channel, adapt(sender, 
MessageConverter.BINARY_WRAPPER), endpointFactory, ContentTypeMode.SERVICE);
+        suite.addTextPlainTests(channel, adapt(sender, 
MessageConverter.TEXT_WRAPPER), adapt(endpointFactory, 
MessageConverter.BYTE_TO_STRING), ContentTypeMode.SERVICE);
+        
+        return suite;
+    }
+}


Reply via email to