Author: veithen
Date: Sat Jul 19 16:52:07 2008
New Revision: 678243
URL: http://svn.apache.org/viewvc?rev=678243&view=rev
Log:
JMSListenerTest: added tests with topic as destination type
Modified:
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
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=678243&r1=678242&r2=678243&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 16:52:07 2008
@@ -71,6 +71,16 @@
*/
public abstract class TransportListenerTestTemplate extends TestCase {
public static abstract class TestStrategy {
+ private final String name;
+
+ public TestStrategy() {
+ name = null;
+ }
+
+ public TestStrategy(String name) {
+ this.name = name;
+ }
+
/**
* Create a TransportInDescription for the transport under test.
*
@@ -112,6 +122,14 @@
* @throws Exception
*/
protected abstract void sendMessage(String endpointReference, String
contentType, byte[] content) throws Exception;
+
+ public String getTestName(String baseName) {
+ if (name == null) {
+ return "test" + baseName;
+ } else {
+ return "test" + name + baseName;
+ }
+ }
}
private static final String testString = "\u00e0 peine arriv\u00e9s nous
entr\u00e2mes dans sa chambre";
@@ -196,19 +214,19 @@
}
public static void addSOAP11Tests(final TestStrategy strategy, TestSuite
suite) {
- suite.addTest(new TestCase("testSOAP11ASCII") {
+ suite.addTest(new TestCase(strategy.getTestName("SOAP11ASCII")) {
@Override
protected void runTest() throws Throwable {
testSOAP11(strategy, "test string", "us-ascii");
}
});
- suite.addTest(new TestCase("testSOAP11UTF8") {
+ suite.addTest(new TestCase(strategy.getTestName("SOAP11UTF8")) {
@Override
protected void runTest() throws Throwable {
testSOAP11(strategy, testString, "UTF-8");
}
});
- suite.addTest(new TestCase("testSOAP11Latin1") {
+ suite.addTest(new TestCase(strategy.getTestName("SOAP11Latin1")) {
@Override
protected void runTest() throws Throwable {
testSOAP11(strategy, testString, "ISO-8859-1");
@@ -218,7 +236,7 @@
// TODO: this test actually only makes sense if the transport supports a
Content-Type header
public static void addSwATests(final TestStrategy strategy, TestSuite
suite) {
- suite.addTest(new TestCase("testSOAPWithAttachments") {
+ suite.addTest(new
TestCase(strategy.getTestName("SOAPWithAttachments")) {
@Override
protected void runTest() throws Throwable {
SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
@@ -258,19 +276,19 @@
}
public static void addTextPlainTests(final TestStrategy strategy,
TestSuite suite) {
- suite.addTest(new TestCase("testTextPlainASCII") {
+ suite.addTest(new TestCase(strategy.getTestName("TextPlainASCII")) {
@Override
public void runTest() throws Exception {
testTextPlain(strategy, "test string", "us-ascii");
}
});
- suite.addTest(new TestCase("testTextPlainUTF8") {
+ suite.addTest(new TestCase(strategy.getTestName("TextPlainUTF8")) {
@Override
public void runTest() throws Exception {
testTextPlain(strategy, testString, "UTF-8");
}
});
- suite.addTest(new TestCase("testTextPlainLatin1") {
+ suite.addTest(new TestCase(strategy.getTestName("TextPlainLatin1")) {
@Override
public void runTest() throws Exception {
testTextPlain(strategy, testString, "ISO-8859-1");
@@ -279,7 +297,7 @@
}
public static void addBinaryTest(final TestStrategy strategy, TestSuite
suite) {
- suite.addTest(new TestCase("testBinary") {
+ suite.addTest(new TestCase(strategy.getTestName("Binary")) {
@Override
public void runTest() throws Exception {
byte[] content = new byte[8192];
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=678243&r1=678242&r2=678243&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 16:52:07 2008
@@ -19,6 +19,7 @@
package org.apache.synapse.transport.jms;
+import java.util.LinkedList;
import java.util.List;
import javax.jms.BytesMessage;
@@ -28,6 +29,11 @@
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
+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;
import javax.xml.namespace.QName;
@@ -46,11 +52,19 @@
import com.mockrunner.jms.ConfigurationManager;
import com.mockrunner.jms.DestinationManager;
import com.mockrunner.mock.jms.MockQueueConnectionFactory;
+import com.mockrunner.mock.jms.MockTopicConnectionFactory;
public class JMSListenerTest extends TransportListenerTestTemplate {
public static class TestStrategyImpl extends TestStrategy {
private final OMFactory factory = OMAbstractFactory.getOMFactory();
+ private final boolean useTopic;
+
+ public TestStrategyImpl(boolean useTopic) {
+ super(useTopic ? "Topic" : "Queue");
+ this.useTopic = useTopic;
+ }
+
private OMElement createParameterElement(String name, String value) {
OMElement element = factory.createOMElement(new
QName("parameter"));
element.addAttribute("name", name, null);
@@ -66,14 +80,24 @@
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"));
+ if (useTopic) {
+ context.bind("ConnectionFactory",
+ new MockTopicConnectionFactory(destinationManager,
configurationManager));
+ context.bind("TestService",
destinationManager.createTopic("TestService"));
+ } else {
+ context.bind("ConnectionFactory",
+ 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"));
+
element.addChild(createParameterElement(Context.INITIAL_CONTEXT_FACTORY,
+ MockContextFactory.class.getName()));
+
element.addChild(createParameterElement(JMSConstants.CONFAC_JNDI_NAME_PARAM,
+ "ConnectionFactory"));
+ element.addChild(createParameterElement(JMSConstants.CONFAC_TYPE,
+ useTopic ? "topic" : "queue"));
trpInDesc.addParameter(new
Parameter(JMSConstants.DEFAULT_CONFAC_NAME, element));
trpInDesc.setReceiver(new JMSListener());
return trpInDesc;
@@ -81,7 +105,11 @@
@Override
protected List<Parameter> getServiceParameters(String contentType)
throws Exception {
- return null;
+ List<Parameter> params = new LinkedList<Parameter>();
+ params.add(new Parameter(JMSConstants.DEST_PARAM_TYPE,
+ useTopic ? JMSConstants.DESTINATION_TYPE_TOPIC
+ : JMSConstants.DESTINATION_TYPE_QUEUE));
+ return params;
}
@Override
@@ -89,27 +117,44 @@
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);
+ 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();
+ message.setStringProperty(BaseConstants.CONTENT_TYPE,
contentType);
+ message.writeBytes(content);
+ publisher.send(message);
+ } 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();
+ 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);
+ for (boolean useTopic : new boolean[] { false, true }) {
+ TestStrategy strategy = new TestStrategyImpl(useTopic);
+ addSOAP11Tests(strategy, suite);
+ addSwATests(strategy, suite);
+ // TODO: these tests are temporarily disabled because of
SYNAPSE-304
+ // addTextPlainTests(strategy, suite);
+ addBinaryTest(strategy, suite);
+ }
return suite;
}
}