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=678237&r1=678236&r2=678237&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 Sat Jul 19 15:57:29 2008 @@ -30,6 +30,7 @@ import javax.xml.namespace.QName; import junit.framework.TestCase; +import junit.framework.TestSuite; import org.apache.axiom.attachments.Attachments; import org.apache.axiom.attachments.ByteArrayDataSource; @@ -69,14 +70,58 @@ * configuring a service with a custom message receiver. */ public abstract class TransportListenerTestTemplate extends TestCase { + public static abstract class TestStrategy { + /** + * Create a TransportInDescription for the transport under test. + * + * @return the transport description + * @throws Exception + */ + protected abstract TransportInDescription createTransportInDescription() throws Exception; + + /** + * Carry out initialization before server startup. This method is called + * immediately before the test server is started and can be used by subclasses + * to set up the test environment. + * + * @throws Exception + */ + protected void beforeStartup() throws Exception { + } + + /** + * Get the parameters necessary to configure a service to receive messages of + * a given content type through the transport under test. + * + * @param contentType the content type + * @return a list of service parameters + * @throws Exception + */ + protected List<Parameter> getServiceParameters(String contentType) throws Exception { + return null; + } + + /** + * 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 + */ + protected abstract void sendMessage(String endpointReference, String contentType, byte[] content) throws Exception; + } + private static final String testString = "\u00e0 peine arriv\u00e9s nous entr\u00e2mes dans sa chambre"; - private final Random random = new Random(); + private static final Random random = new Random(); - private MessageData runTest(String contentType, byte[] content) throws Exception { + private static MessageData runTest(TestStrategy strategy, String contentType, byte[] content) throws Exception { UtilsTransportServer server = new UtilsTransportServer(); - TransportInDescription trpInDesc = createTransportInDescription(); + TransportInDescription trpInDesc = strategy.createTransportInDescription(); server.addTransport(trpInDesc); AxisConfiguration axisConfiguration = server.getAxisConfiguration(); @@ -102,7 +147,7 @@ MockMessageReceiver messageReceiver = new MockMessageReceiver(); operation.setMessageReceiver(messageReceiver); service.addOperation(operation); - List<Parameter> parameters = getServiceParameters(contentType); + List<Parameter> parameters = strategy.getServiceParameters(contentType); if (parameters != null) { for (Parameter parameter : parameters) { service.addParameter(parameter); @@ -111,14 +156,14 @@ axisConfiguration.addService(service); // Run the test. - beforeStartup(); + strategy.beforeStartup(); server.start(); try { EndpointReference[] endpointReferences = trpInDesc.getReceiver().getEPRsForService(service.getName(), "localhost"); - sendMessage(endpointReferences != null && endpointReferences.length > 0 - ? endpointReferences[0].getAddress() : null, - contentType, content); + strategy.sendMessage(endpointReferences != null && endpointReferences.length > 0 + ? endpointReferences[0].getAddress() : null, + contentType, content); MessageData messageData = messageReceiver.waitForMessage(8, TimeUnit.SECONDS); if (messageData == null) { fail("Failed to get message"); @@ -131,7 +176,7 @@ } } - private void testSOAP11(String text, String charset) throws Exception { + private static void testSOAP11(TestStrategy strategy, String text, String charset) throws Exception { SOAPFactory factory = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope orgEnvelope = factory.createSOAPEnvelope(); SOAPBody orgBody = factory.createSOAPBody(); @@ -144,124 +189,110 @@ outputFormat.setCharSetEncoding(charset); outputFormat.setIgnoreXMLDeclaration(true); orgEnvelope.serializeAndConsume(baos, outputFormat); - SOAPEnvelope envelope = runTest("text/xml; charset=\"" + charset + "\"", baos.toByteArray()).getEnvelope(); + SOAPEnvelope envelope = runTest(strategy, "text/xml; charset=\"" + charset + "\"", baos.toByteArray()).getEnvelope(); OMElement element = envelope.getBody().getFirstElement(); assertEquals(orgElement.getQName(), element.getQName()); assertEquals(text, element.getText()); } - public void testSOAP11ASCII() throws Exception { - testSOAP11("test string", "us-ascii"); - } - - public void testSOAP11UTF8() throws Exception { - testSOAP11(testString, "UTF-8"); - } - - public void testSOAP11Latin1() throws Exception { - testSOAP11(testString, "ISO-8859-1"); + public static void addSOAP11Tests(final TestStrategy strategy, TestSuite suite) { + suite.addTest(new TestCase("testSOAP11ASCII") { + @Override + protected void runTest() throws Throwable { + testSOAP11(strategy, "test string", "us-ascii"); + } + }); + suite.addTest(new TestCase("testSOAP11UTF8") { + @Override + protected void runTest() throws Throwable { + testSOAP11(strategy, testString, "UTF-8"); + } + }); + suite.addTest(new TestCase("testSOAP11Latin1") { + @Override + protected void runTest() throws Throwable { + testSOAP11(strategy, testString, "ISO-8859-1"); + } + }); } // TODO: this test actually only makes sense if the transport supports a Content-Type header - public void testSOAPWithAttachments() throws Exception { - SOAPFactory factory = OMAbstractFactory.getSOAP12Factory(); - SOAPEnvelope orgEnvelope = factory.createSOAPEnvelope(); - SOAPBody orgBody = factory.createSOAPBody(); - OMElement orgElement = factory.createOMElement(new QName("root")); - orgBody.addChild(orgElement); - orgEnvelope.addChild(orgBody); - OMOutputFormat outputFormat = new OMOutputFormat(); - outputFormat.setCharSetEncoding("UTF-8"); - outputFormat.setIgnoreXMLDeclaration(true); - StringWriter writer = new StringWriter(); - orgEnvelope.serializeAndConsume(writer); - byte[] attachmentContent = new byte[8192]; - random.nextBytes(attachmentContent); - String contentID = UUIDGenerator.getUUID(); - Attachments orgAttachments = new Attachments(); - orgAttachments.addDataHandler(contentID, new DataHandler(new ByteArrayDataSource(attachmentContent, "application/octet-stream"))); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - MIMEOutputUtils.writeSOAPWithAttachmentsMessage(writer, baos, orgAttachments, outputFormat); - MessageData messageData = runTest(outputFormat.getContentTypeForSwA(SOAP12Constants.SOAP_12_CONTENT_TYPE), baos.toByteArray()); - Attachments attachments = messageData.getAttachments(); - DataHandler dataHandler = attachments.getDataHandler(contentID); - assertNotNull(dataHandler); - baos.reset(); - dataHandler.writeTo(baos); - assertTrue(Arrays.equals(attachmentContent, baos.toByteArray())); + public static void addSwATests(final TestStrategy strategy, TestSuite suite) { + suite.addTest(new TestCase("testSOAPWithAttachments") { + @Override + protected void runTest() throws Throwable { + SOAPFactory factory = OMAbstractFactory.getSOAP12Factory(); + SOAPEnvelope orgEnvelope = factory.createSOAPEnvelope(); + SOAPBody orgBody = factory.createSOAPBody(); + OMElement orgElement = factory.createOMElement(new QName("root")); + orgBody.addChild(orgElement); + orgEnvelope.addChild(orgBody); + OMOutputFormat outputFormat = new OMOutputFormat(); + outputFormat.setCharSetEncoding("UTF-8"); + outputFormat.setIgnoreXMLDeclaration(true); + StringWriter writer = new StringWriter(); + orgEnvelope.serializeAndConsume(writer); + byte[] attachmentContent = new byte[8192]; + random.nextBytes(attachmentContent); + String contentID = UUIDGenerator.getUUID(); + Attachments orgAttachments = new Attachments(); + orgAttachments.addDataHandler(contentID, new DataHandler(new ByteArrayDataSource(attachmentContent, "application/octet-stream"))); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + MIMEOutputUtils.writeSOAPWithAttachmentsMessage(writer, baos, orgAttachments, outputFormat); + MessageData messageData = TransportListenerTestTemplate.runTest(strategy, outputFormat.getContentTypeForSwA(SOAP12Constants.SOAP_12_CONTENT_TYPE), baos.toByteArray()); + Attachments attachments = messageData.getAttachments(); + DataHandler dataHandler = attachments.getDataHandler(contentID); + assertNotNull(dataHandler); + baos.reset(); + dataHandler.writeTo(baos); + assertTrue(Arrays.equals(attachmentContent, baos.toByteArray())); + } + }); } - private void testTextPlain(String text, String charset) throws Exception { - SOAPEnvelope envelope = runTest("text/plain; charset=" + charset, text.getBytes(charset)).getEnvelope(); + private static void testTextPlain(TestStrategy strategy, String text, String charset) throws Exception { + SOAPEnvelope envelope = runTest(strategy, "text/plain; charset=" + charset, text.getBytes(charset)).getEnvelope(); OMElement wrapper = envelope.getBody().getFirstElement(); assertEquals(BaseConstants.DEFAULT_TEXT_WRAPPER, wrapper.getQName()); assertEquals(text, wrapper.getText()); } - public void testTextPlainASCII() throws Exception { - testTextPlain("test string", "us-ascii"); - } - - public void testTextPlainUTF8() throws Exception { - testTextPlain(testString, "UTF-8"); - } - - public void testTextPlainLatin1() throws Exception { - testTextPlain(testString, "ISO-8859-1"); + public static void addTextPlainTests(final TestStrategy strategy, TestSuite suite) { + suite.addTest(new TestCase("testTextPlainASCII") { + @Override + public void runTest() throws Exception { + testTextPlain(strategy, "test string", "us-ascii"); + } + }); + suite.addTest(new TestCase("testTextPlainUTF8") { + @Override + public void runTest() throws Exception { + testTextPlain(strategy, testString, "UTF-8"); + } + }); + suite.addTest(new TestCase("testTextPlainLatin1") { + @Override + public void runTest() throws Exception { + testTextPlain(strategy, testString, "ISO-8859-1"); + } + }); } - public void testBinary() throws Exception { - byte[] content = new byte[8192]; - random.nextBytes(content); - SOAPEnvelope envelope = runTest("application/octet-stream", content).getEnvelope(); - OMElement wrapper = envelope.getBody().getFirstElement(); - assertEquals(BaseConstants.DEFAULT_BINARY_WRAPPER, wrapper.getQName()); - OMNode child = wrapper.getFirstOMChild(); - assertTrue(child instanceof OMText); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ((DataHandler)((OMText)child).getDataHandler()).writeTo(baos); - assertTrue(Arrays.equals(content, baos.toByteArray())); + public static void addBinaryTest(final TestStrategy strategy, TestSuite suite) { + suite.addTest(new TestCase("testBinary") { + @Override + public void runTest() throws Exception { + byte[] content = new byte[8192]; + random.nextBytes(content); + SOAPEnvelope envelope = TransportListenerTestTemplate.runTest(strategy, "application/octet-stream", content).getEnvelope(); + OMElement wrapper = envelope.getBody().getFirstElement(); + assertEquals(BaseConstants.DEFAULT_BINARY_WRAPPER, wrapper.getQName()); + OMNode child = wrapper.getFirstOMChild(); + assertTrue(child instanceof OMText); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ((DataHandler)((OMText)child).getDataHandler()).writeTo(baos); + assertTrue(Arrays.equals(content, baos.toByteArray())); + } + }); } - - /** - * Create a TransportInDescription for the transport under test. - * - * @return the transport description - * @throws Exception - */ - protected abstract TransportInDescription createTransportInDescription() throws Exception; - - /** - * Carry out initialization before server startup. This method is called - * immediately before the test server is started and can be used by subclasses - * to set up the test environment. - * - * @throws Exception - */ - protected void beforeStartup() throws Exception { - } - - /** - * Get the parameters necessary to configure a service to receive messages of - * a given content type through the transport under test. - * - * @param contentType the content type - * @return a list of service parameters - * @throws Exception - */ - protected List<Parameter> getServiceParameters(String contentType) throws Exception { - return null; - } - - /** - * 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 - */ - protected abstract void sendMessage(String endpointReference, String contentType, byte[] content) throws Exception; }
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=678237&r1=678236&r2=678237&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 Sat Jul 19 15:57:29 2008 @@ -32,6 +32,8 @@ import javax.naming.InitialContext; import javax.xml.namespace.QName; +import junit.framework.TestSuite; + import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMFactory; @@ -46,60 +48,68 @@ import com.mockrunner.mock.jms.MockQueueConnectionFactory; public class JMSListenerTest extends TransportListenerTestTemplate { - private final OMFactory factory = OMAbstractFactory.getOMFactory(); + public static class TestStrategyImpl extends TestStrategy { + private final OMFactory factory = OMAbstractFactory.getOMFactory(); + + private OMElement createParameterElement(String name, String value) { + OMElement element = factory.createOMElement(new QName("parameter")); + element.addAttribute("name", name, null); + if (value != null) { + element.setText(value); + } + return element; + } + + @Override + protected TransportInDescription createTransportInDescription() throws Exception { + MockContextFactory.setAsInitial(); + Context context = new InitialContext(); + DestinationManager destinationManager = new DestinationManager(); + ConfigurationManager configurationManager = new ConfigurationManager(); + context.bind("QueueConnectionFactory", new MockQueueConnectionFactory(destinationManager, configurationManager)); + context.bind("TestService", destinationManager.createQueue("TestService")); + + TransportInDescription trpInDesc = new TransportInDescription(JMSListener.TRANSPORT_NAME); + OMElement element = createParameterElement(JMSConstants.DEFAULT_CONFAC_NAME, null); + element.addChild(createParameterElement("java.naming.factory.initial", MockContextFactory.class.getName())); + element.addChild(createParameterElement("transport.jms.ConnectionFactoryJNDIName", "QueueConnectionFactory")); + element.addChild(createParameterElement("transport.jms.ConnectionFactoryType", "queue")); + trpInDesc.addParameter(new Parameter(JMSConstants.DEFAULT_CONFAC_NAME, element)); + trpInDesc.setReceiver(new JMSListener()); + return trpInDesc; + } - private OMElement createParameterElement(String name, String value) { - OMElement element = factory.createOMElement(new QName("parameter")); - element.addAttribute("name", name, null); - if (value != null) { - element.setText(value); + @Override + protected List<Parameter> getServiceParameters(String contentType) throws Exception { + return null; } - return element; - } - @Override - protected TransportInDescription createTransportInDescription() throws Exception { - MockContextFactory.setAsInitial(); - Context context = new InitialContext(); - DestinationManager destinationManager = new DestinationManager(); - ConfigurationManager configurationManager = new ConfigurationManager(); - context.bind("QueueConnectionFactory", new MockQueueConnectionFactory(destinationManager, configurationManager)); - context.bind("TestService", destinationManager.createQueue("TestService")); - - TransportInDescription trpInDesc = new TransportInDescription(JMSListener.TRANSPORT_NAME); - OMElement element = createParameterElement(JMSConstants.DEFAULT_CONFAC_NAME, null); - element.addChild(createParameterElement("java.naming.factory.initial", MockContextFactory.class.getName())); - element.addChild(createParameterElement("transport.jms.ConnectionFactoryJNDIName", "QueueConnectionFactory")); - element.addChild(createParameterElement("transport.jms.ConnectionFactoryType", "queue")); - trpInDesc.addParameter(new Parameter(JMSConstants.DEFAULT_CONFAC_NAME, element)); - trpInDesc.setReceiver(new JMSListener()); - return trpInDesc; - } - - @Override - protected List<Parameter> getServiceParameters(String contentType) throws Exception { - return null; + @Override + protected void sendMessage(String endpointReference, + String contentType, + byte[] content) throws Exception { + Context context = new InitialContext(); + QueueConnectionFactory connFactory + = (QueueConnectionFactory)context.lookup("QueueConnectionFactory"); + 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(); + message.setStringProperty(BaseConstants.CONTENT_TYPE, contentType); + message.writeBytes(content); + sender.send(message); + } } - - @Override - protected void sendMessage(String endpointReference, - String contentType, - byte[] content) throws Exception { - Context context = new InitialContext(); - QueueConnectionFactory connFactory - = (QueueConnectionFactory)context.lookup("QueueConnectionFactory"); - 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(); - message.setStringProperty(BaseConstants.CONTENT_TYPE, contentType); - message.writeBytes(content); - sender.send(message); + + public static TestSuite suite() { + TestSuite suite = new TestSuite(); + TestStrategy strategy = new TestStrategyImpl(); + addSOAP11Tests(strategy, suite); + addSwATests(strategy, suite); + // TODO: these tests are temporarily disabled because of SYNAPSE-304 + // addTextPlainTests(strategy, suite); + addBinaryTest(strategy, suite); + return suite; } - - // TODO: these tests are temporarily disabled because of SYNAPSE-304 - @Override public void testTextPlainASCII() {} - @Override public void testTextPlainLatin1() {} - @Override public void testTextPlainUTF8() {} } 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=678237&r1=678236&r2=678237&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 Sat Jul 19 15:57:29 2008 @@ -32,54 +32,61 @@ import javax.mail.internet.MimeMessage; import javax.mail.util.ByteArrayDataSource; +import junit.framework.TestSuite; + import org.apache.axis2.description.Parameter; import org.apache.axis2.description.TransportInDescription; 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]"; + + @Override + protected TransportInDescription createTransportInDescription() { + TransportInDescription trpInDesc + = new TransportInDescription(MailConstants.TRANSPORT_NAME); + trpInDesc.setReceiver(new MailTransportListener()); + return trpInDesc; + } - @Override - protected TransportInDescription createTransportInDescription() { - TransportInDescription trpInDesc - = new TransportInDescription(MailConstants.TRANSPORT_NAME); - trpInDesc.setReceiver(new MailTransportListener()); - return trpInDesc; - } - - @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")); - // 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; - } - - @Override - protected void sendMessage(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); - MimeMessage msg = new MimeMessage(session); - msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(ADDRESS)); - msg.setFrom(new InternetAddress("[EMAIL PROTECTED]")); - msg.setSentDate(new Date()); - msg.setDataHandler(new DataHandler(new ByteArrayDataSource(content, contentType))); - Transport.send(msg); - } + @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")); + // 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; + } - // Temporarily skip the following tests until SYNAPSE-359 is solved - @Override public void testBinary() throws Exception {} - @Override public void testTextPlainASCII() throws Exception {} - @Override public void testTextPlainLatin1() throws Exception {} - @Override public void testTextPlainUTF8() throws Exception {} + @Override + protected void sendMessage(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); + MimeMessage msg = new MimeMessage(session); + msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(ADDRESS)); + msg.setFrom(new InternetAddress("[EMAIL PROTECTED]")); + msg.setSentDate(new Date()); + msg.setDataHandler(new DataHandler(new ByteArrayDataSource(content, contentType))); + Transport.send(msg); + } + } - // Temporarily skip this test until we know why it fails. - @Override public void testSOAPWithAttachments() {} + public static TestSuite suite() { + TestSuite suite = new TestSuite(); + TestStrategy strategy = new TestStrategyImpl(); + addSOAP11Tests(strategy, suite); + // Temporarily skip this test until we know why it fails. + // addSwATests(strategy, suite); + // Temporarily skip the following tests until SYNAPSE-359 is solved + // addTextPlainTests(strategy, suite); + // addBinaryTest(strategy, suite); + return suite; + } } 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=678237&r1=678236&r2=678237&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 Sat Jul 19 15:57:29 2008 @@ -24,29 +24,45 @@ import java.net.URL; import java.net.URLConnection; +import junit.framework.TestSuite; + import org.apache.axis2.description.TransportInDescription; import org.apache.commons.io.IOUtils; import org.apache.synapse.transport.TransportListenerTestTemplate; +import org.apache.synapse.transport.TransportListenerTestTemplate.TestStrategy; +import org.apache.synapse.transport.mail.MailTransportListenerTest.TestStrategyImpl; public class HttpCoreNIOListenerTest extends TransportListenerTestTemplate { - @Override - protected TransportInDescription createTransportInDescription() { - TransportInDescription trpInDesc = new TransportInDescription("http"); - trpInDesc.setReceiver(new HttpCoreNIOListener()); - return trpInDesc; - } + public static class TestStrategyImpl extends TestStrategy { + @Override + protected TransportInDescription createTransportInDescription() { + TransportInDescription trpInDesc = new TransportInDescription("http"); + trpInDesc.setReceiver(new HttpCoreNIOListener()); + return trpInDesc; + } - @Override - protected void sendMessage(String endpointReference, String contentType, byte[] content) throws Exception { - URLConnection connection = new URL(endpointReference).openConnection(); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setRequestProperty("Content-Type", contentType); - OutputStream out = connection.getOutputStream(); - out.write(content); - out.close(); - InputStream in = connection.getInputStream(); - IOUtils.copy(in, System.out); - in.close(); + @Override + protected void sendMessage(String endpointReference, String contentType, byte[] content) throws Exception { + URLConnection connection = new URL(endpointReference).openConnection(); + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setRequestProperty("Content-Type", contentType); + OutputStream out = connection.getOutputStream(); + out.write(content); + out.close(); + InputStream in = connection.getInputStream(); + IOUtils.copy(in, System.out); + in.close(); + } + } + + public static TestSuite suite() { + TestSuite suite = new TestSuite(); + TestStrategy strategy = new TestStrategyImpl(); + addSOAP11Tests(strategy, suite); + addSwATests(strategy, suite); + addTextPlainTests(strategy, suite); + addBinaryTest(strategy, suite); + return suite; } } 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=678237&r1=678236&r2=678237&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 Sat Jul 19 15:57:29 2008 @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.List; +import junit.framework.TestSuite; + import org.apache.axis2.description.Parameter; import org.apache.axis2.description.TransportInDescription; import org.apache.synapse.transport.TransportListenerTestTemplate; @@ -33,39 +35,48 @@ * TransportListenerTestTemplate implementation for the VFS transport. */ public class VFSTransportListenerTest extends TransportListenerTestTemplate { - private final File requestFile = new File("target/vfs3/req/in").getAbsoluteFile(); - - @Override - protected TransportInDescription createTransportInDescription() { - TransportInDescription trpInDesc = - new TransportInDescription(VFSTransportListener.TRANSPORT_NAME); - trpInDesc.setReceiver(new VFSTransportListener()); - return trpInDesc; - } - - @Override - protected void beforeStartup() throws Exception { - requestFile.getParentFile().mkdirs(); - requestFile.delete(); + public static class TestStrategyImpl extends TestStrategy { + private final File requestFile = new File("target/vfs3/req/in").getAbsoluteFile(); + + @Override + protected TransportInDescription createTransportInDescription() { + TransportInDescription trpInDesc = + new TransportInDescription(VFSTransportListener.TRANSPORT_NAME); + trpInDesc.setReceiver(new VFSTransportListener()); + return trpInDesc; + } + + @Override + protected void beforeStartup() throws Exception { + requestFile.getParentFile().mkdirs(); + requestFile.delete(); + } + + @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; + } + + @Override + protected void sendMessage(String endpointReference, String contentType, byte[] content) throws Exception { + OutputStream out = new FileOutputStream("target/vfs3/req/in"); + out.write(content); + out.close(); + } } - @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; + public static TestSuite suite() { + TestSuite suite = new TestSuite(); + TestStrategy strategy = new TestStrategyImpl(); + addSOAP11Tests(strategy, suite); + // Since VFS has no Content-Type header, SwA is not supported. + addTextPlainTests(strategy, suite); + addBinaryTest(strategy, suite); + return suite; } - - @Override - protected void sendMessage(String endpointReference, String contentType, byte[] content) throws Exception { - OutputStream out = new FileOutputStream("target/vfs3/req/in"); - out.write(content); - out.close(); - } - - // Since VFS has no Content-Type header, SwA is not supported. Skip this test. - @Override public void testSOAPWithAttachments() {} }
