001: package org.objectweb.celtix.systest.jms;
002:
003: import java.lang.reflect.InvocationHandler;
004: import java.lang.reflect.Proxy;
005: import java.lang.reflect.UndeclaredThrowableException;
006: import java.net.URL;
007: import java.util.HashMap;
008: import java.util.Map;
009:
010: import javax.xml.namespace.QName;
011: import javax.xml.ws.BindingProvider;
012:
013: import junit.framework.Test;
014: import junit.framework.TestSuite;
015:
016: import org.objectweb.celtix.bus.transports.jms.JMSConstants;
017: import org.objectweb.celtix.hello_world_jms.HelloWorldOneWayPort;
018: import org.objectweb.celtix.hello_world_jms.HelloWorldOneWayQueueService;
019: import org.objectweb.celtix.hello_world_jms.HelloWorldPortType;
020: import org.objectweb.celtix.hello_world_jms.HelloWorldPubSubPort;
021: import org.objectweb.celtix.hello_world_jms.HelloWorldPubSubService;
022: import org.objectweb.celtix.hello_world_jms.HelloWorldService;
023: import org.objectweb.celtix.systest.common.ClientServerSetupBase;
024: import org.objectweb.celtix.systest.common.ClientServerTestBase;
025: import org.objectweb.celtix.transports.jms.context.JMSMessageHeadersType;
026: import org.objectweb.celtix.transports.jms.context.JMSPropertyType;
027:
028: public class JMSClientServerTest extends ClientServerTestBase {
029:
030: private QName serviceName;
031: private QName portName;
032:
033: public static Test suite() throws Exception {
034: TestSuite suite = new TestSuite(JMSClientServerTest.class);
035: return new ClientServerSetupBase(suite) {
036: public void startServers() throws Exception {
037: Map<String, String> props = new HashMap<String, String>();
038: if (System.getProperty("activemq.store.dir") != null) {
039: props.put("activemq.store.dir", System
040: .getProperty("activemq.store.dir"));
041: }
042: props.put("java.util.logging.config.file", System
043: .getProperty("java.util.logging.config.file"));
044:
045: assertTrue("server did not launch correctly",
046: launchServer(EmbeddedJMSBrokerLauncher.class,
047: props, null));
048:
049: assertTrue("server did not launch correctly",
050: launchServer(Server.class, false));
051: }
052: };
053: }
054:
055: public void testBasicConnection() throws Exception {
056: serviceName = new QName(
057: "http://celtix.objectweb.org/hello_world_jms",
058: "HelloWorldService");
059: portName = new QName(
060: "http://celtix.objectweb.org/hello_world_jms",
061: "HelloWorldPort");
062: URL wsdl = getClass().getResource("/wsdl/jms_test.wsdl");
063: assertNotNull(wsdl);
064:
065: HelloWorldService service = new HelloWorldService(wsdl,
066: serviceName);
067: assertNotNull(service);
068:
069: String response1 = new String("Hello Milestone-");
070: String response2 = new String("Bonjour");
071: try {
072: HelloWorldPortType greeter = service.getPort(portName,
073: HelloWorldPortType.class);
074: for (int idx = 0; idx < 5; idx++) {
075: String greeting = greeter.greetMe("Milestone-" + idx);
076: assertNotNull("no response received from service",
077: greeting);
078: String exResponse = response1 + idx;
079: assertEquals(exResponse, greeting);
080:
081: String reply = greeter.sayHi();
082: assertNotNull("no response received from service",
083: reply);
084: assertEquals(response2, reply);
085: }
086: } catch (UndeclaredThrowableException ex) {
087: throw (Exception) ex.getCause();
088: }
089: }
090:
091: public void testOneWayTopicConnection() throws Exception {
092: serviceName = new QName(
093: "http://celtix.objectweb.org/hello_world_jms",
094: "HelloWorldPubSubService");
095: portName = new QName(
096: "http://celtix.objectweb.org/hello_world_jms",
097: "HelloWorldPubSubPort");
098: URL wsdl = getClass().getResource("/wsdl/jms_test.wsdl");
099: assertNotNull(wsdl);
100:
101: HelloWorldPubSubService service = new HelloWorldPubSubService(
102: wsdl, serviceName);
103: assertNotNull(service);
104:
105: try {
106: HelloWorldPubSubPort greeter = service.getPort(portName,
107: HelloWorldPubSubPort.class);
108: for (int idx = 0; idx < 5; idx++) {
109: greeter.greetMeOneWay("JMS:PubSub:Milestone-" + idx);
110: }
111: //Give some time to complete one-way calls.
112: Thread.sleep(100L);
113: } catch (UndeclaredThrowableException ex) {
114: throw (Exception) ex.getCause();
115: }
116: }
117:
118: public void testOneWayQueueConnection() throws Exception {
119: serviceName = new QName(
120: "http://celtix.objectweb.org/hello_world_jms",
121: "HelloWorldOneWayQueueService");
122: portName = new QName(
123: "http://celtix.objectweb.org/hello_world_jms",
124: "HelloWorldOneWayPort");
125: URL wsdl = getClass().getResource("/wsdl/jms_test.wsdl");
126: assertNotNull(wsdl);
127:
128: HelloWorldOneWayQueueService service = new HelloWorldOneWayQueueService(
129: wsdl, serviceName);
130: assertNotNull(service);
131:
132: try {
133: HelloWorldOneWayPort greeter = service.getPort(portName,
134: HelloWorldOneWayPort.class);
135: for (int idx = 0; idx < 5; idx++) {
136: greeter.greetMeOneWay("JMS:Queue:Milestone-" + idx);
137: }
138: //Give some time to complete one-way calls.
139: Thread.sleep(100L);
140: } catch (UndeclaredThrowableException ex) {
141: throw (Exception) ex.getCause();
142: }
143: }
144:
145: public void testContextPropogation() throws Exception {
146: serviceName = new QName(
147: "http://celtix.objectweb.org/hello_world_jms",
148: "HelloWorldService");
149: portName = new QName(
150: "http://celtix.objectweb.org/hello_world_jms",
151: "HelloWorldPort");
152: URL wsdl = getClass().getResource("/wsdl/jms_test.wsdl");
153: assertNotNull(wsdl);
154:
155: HelloWorldService service = new HelloWorldService(wsdl,
156: serviceName);
157: assertNotNull(service);
158:
159: try {
160: HelloWorldPortType greeter = service.getPort(portName,
161: HelloWorldPortType.class);
162: InvocationHandler handler = Proxy
163: .getInvocationHandler(greeter);
164: BindingProvider bp = null;
165:
166: if (handler instanceof BindingProvider) {
167: bp = (BindingProvider) handler;
168: //System.out.println(bp.toString());
169: Map<String, Object> requestContext = bp
170: .getRequestContext();
171: JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();
172: requestHeader
173: .setJMSCorrelationID("JMS_SAMPLE_CORRELATION_ID");
174: requestHeader.setJMSExpiration(3600000L);
175: JMSPropertyType propType = new JMSPropertyType();
176: propType.setName("Test.Prop");
177: propType.setValue("mustReturn");
178: requestHeader.getProperty().add(propType);
179: requestContext.put(
180: JMSConstants.JMS_CLIENT_REQUEST_HEADERS,
181: requestHeader);
182: }
183:
184: String greeting = greeter.greetMe("Milestone-");
185: assertNotNull("no response received from service", greeting);
186:
187: assertEquals("Hello Milestone-", greeting);
188:
189: if (bp != null) {
190: Map<String, Object> responseContext = bp
191: .getResponseContext();
192: JMSMessageHeadersType responseHdr = (JMSMessageHeadersType) responseContext
193: .get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
194: if (responseHdr == null) {
195: fail("response Header should not be null");
196: }
197:
198: assertTrue("CORRELATION ID should match :",
199: "JMS_SAMPLE_CORRELATION_ID".equals(responseHdr
200: .getJMSCorrelationID()));
201: assertTrue(
202: "response Headers must conain the app specific property set by request context.",
203: responseHdr.getProperty() != null);
204: }
205: } catch (UndeclaredThrowableException ex) {
206: throw (Exception) ex.getCause();
207: }
208: }
209:
210: public static void main(String[] args) {
211: junit.textui.TestRunner.run(JMSClientServerTest.class);
212: }
213: }
|