001: package org.objectweb.celtix.bus.transports.jms;
002:
003: import java.net.URL;
004:
005: import javax.xml.namespace.QName;
006:
007: import junit.framework.TestCase;
008:
009: import org.objectweb.celtix.Bus;
010: import org.objectweb.celtix.bus.configuration.spring.ConfigurationProviderImpl;
011: import org.objectweb.celtix.configuration.Configuration;
012: import org.objectweb.celtix.configuration.ConfigurationBuilder;
013: import org.objectweb.celtix.configuration.ConfigurationBuilderFactory;
014: import org.objectweb.celtix.configuration.impl.TypeSchemaHelper;
015: import org.objectweb.celtix.transports.jms.JMSAddressPolicyType;
016: import org.objectweb.celtix.transports.jms.JMSClientBehaviorPolicyType;
017: import org.objectweb.celtix.transports.jms.JMSServerBehaviorPolicyType;
018: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
019: import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
020:
021: public class JMSConfigTest extends TestCase {
022:
023: Bus bus;
024:
025: public JMSConfigTest(String name) {
026: super (name);
027: }
028:
029: public static void main(String[] args) {
030: junit.textui.TestRunner.run(JMSConfigTest.class);
031: }
032:
033: public void setUp() throws Exception {
034: TypeSchemaHelper.clearCache();
035: ConfigurationProviderImpl.clearBeanFactoriesMap();
036: ConfigurationBuilderFactory.clearBuilder();
037: bus = Bus.init();
038: }
039:
040: public void tearDown() throws Exception {
041: bus.shutdown(true);
042: if (System.getProperty("celtix.config.file") != null) {
043: System.clearProperty("celtix.config.file");
044: }
045:
046: TypeSchemaHelper.clearCache();
047: ConfigurationProviderImpl.clearBeanFactoriesMap();
048: ConfigurationBuilderFactory.clearBuilder();
049: }
050:
051: private void createNecessaryConfig(URL wsdlUrl, QName serviceName,
052: String portName) throws Exception {
053: assert bus != null;
054: EndpointReferenceType ref = EndpointReferenceUtils
055: .getEndpointReference(wsdlUrl, serviceName, portName);
056: Configuration busCfg = bus.getConfiguration();
057: assert null != busCfg;
058: Configuration endpointCfg = null;
059: Configuration portCfg = null;
060:
061: String id = EndpointReferenceUtils.getServiceName(ref)
062: .toString();
063: ConfigurationBuilder cb = ConfigurationBuilderFactory
064: .getBuilder(null);
065:
066: // Server Endpoint Config
067: endpointCfg = cb.buildConfiguration(
068: JMSConstants.ENDPOINT_CONFIGURATION_URI, id, busCfg);
069:
070: // Client Service Endpoint Port config.
071: portCfg = cb.buildConfiguration(
072: JMSConstants.PORT_CONFIGURATION_URI, id
073: + "/"
074: + EndpointReferenceUtils.getPortName(ref)
075: .toString(), busCfg);
076: // Server Transport Config.
077: cb.buildConfiguration(
078: JMSConstants.JMS_SERVER_CONFIGURATION_URI,
079: JMSConstants.JMS_SERVER_CONFIG_ID, endpointCfg);
080: //Client Transport Config.
081: cb.buildConfiguration(
082: JMSConstants.JMS_CLIENT_CONFIGURATION_URI,
083: JMSConstants.JMS_CLIENT_CONFIG_ID, portCfg);
084: }
085:
086: public void testDefaultClientConfig() throws Exception {
087:
088: QName serviceName = new QName(
089: "http://celtix.objectweb.org/hello_world_jms",
090: "HelloWorldService");
091: URL wsdlUrl = getClass().getResource("/wsdl/jms_test.wsdl");
092: assertNotNull(wsdlUrl);
093:
094: EndpointReferenceType ref = EndpointReferenceUtils
095: .getEndpointReference(wsdlUrl, serviceName,
096: "HelloWorldPort");
097:
098: createNecessaryConfig(wsdlUrl, serviceName, "HelloWorldPort");
099:
100: JMSClientTransport clientTransport = new JMSClientTransport(
101: bus, ref, null);
102:
103: checkDefaultAddressFields(clientTransport
104: .getJmsAddressDetails());
105:
106: JMSClientBehaviorPolicyType clientPolicy = clientTransport
107: .getJMSClientBehaviourPolicy();
108: assertTrue("JMSClientBehaviourPolicy cannot be null ",
109: null != clientPolicy);
110:
111: assertTrue("JMSClientPolicy messageType should be text ",
112: JMSConstants.TEXT_MESSAGE_TYPE.equals(clientPolicy
113: .getMessageType().value()));
114: }
115:
116: public void testDefaultServerConfig() throws Exception {
117:
118: QName serviceName = new QName(
119: "http://celtix.objectweb.org/hello_world_jms",
120: "HelloWorldService");
121: URL wsdlUrl = getClass().getResource("/wsdl/jms_test.wsdl");
122: assertNotNull(wsdlUrl);
123:
124: EndpointReferenceType ref = EndpointReferenceUtils
125: .getEndpointReference(wsdlUrl, serviceName,
126: "HelloWorldPort");
127:
128: createNecessaryConfig(wsdlUrl, serviceName, "HelloWorldPort");
129:
130: JMSServerTransport serverTransport = new JMSServerTransport(
131: bus, ref);
132:
133: checkDefaultAddressFields(serverTransport
134: .getJmsAddressDetails());
135:
136: JMSServerBehaviorPolicyType serverPolicy = serverTransport
137: .getJMSServerBehaviourPolicy();
138:
139: assertTrue("JMSServerPolicy messageSelector should be null ",
140: serverPolicy.getMessageSelector() == null);
141: assertTrue(
142: "JMSServerPolicy useMessageIDAsCorrelationID should be false ",
143: !serverPolicy.isUseMessageIDAsCorrelationID());
144: assertTrue(
145: "JMSServerPolicy useMessageIDAsCorrelationID should be false ",
146: !serverPolicy.isTransactional());
147: assertTrue(
148: "JMSServerPolicy durableSubscriberName should be null ",
149: serverPolicy.getDurableSubscriberName() == null);
150: }
151:
152: public void testClientConfig() throws Exception {
153:
154: bus.shutdown(true);
155: URL clientConfigFileUrl = getClass().getResource(
156: "/wsdl/jms_test_config.xml");
157: System.setProperty("celtix.config.file", clientConfigFileUrl
158: .toString());
159:
160: bus = Bus.init();
161: QName serviceName = new QName(
162: "http://celtix.objectweb.org/jms_conf_test",
163: "HelloWorldQueueBinMsgService");
164: URL wsdlUrl = getClass().getResource(
165: "/wsdl/jms_test_no_addr.wsdl");
166: assertNotNull(wsdlUrl);
167:
168: EndpointReferenceType ref = EndpointReferenceUtils
169: .getEndpointReference(wsdlUrl, serviceName,
170: "HelloWorldQueueBinMsgPort");
171:
172: createNecessaryConfig(wsdlUrl, serviceName,
173: "HelloWorldQueueBinMsgPort");
174:
175: JMSClientTransport clientTransport = new JMSClientTransport(
176: bus, ref, null);
177:
178: checkNonDefaultAddressFields(clientTransport
179: .getJmsAddressDetails());
180:
181: JMSClientBehaviorPolicyType clientPolicy = clientTransport
182: .getJMSClientBehaviourPolicy();
183: assertTrue("JMSClientBehaviourPolicy cannot be null ",
184: null != clientPolicy);
185: assertTrue("JMSClientPolicy messageType should be text ",
186: JMSConstants.BINARY_MESSAGE_TYPE.equals(clientPolicy
187: .getMessageType().value()));
188:
189: System.setProperty("celtix.config.file", "");
190: }
191:
192: public void testServerConfig() throws Exception {
193:
194: URL clientConfigFileUrl = getClass().getResource(
195: "/wsdl/jms_test_config.xml");
196: System.setProperty("celtix.config.file", clientConfigFileUrl
197: .toString());
198:
199: QName serviceName = new QName(
200: "http://celtix.objectweb.org/jms_conf_test",
201: "HelloWorldQueueBinMsgService");
202: URL wsdlUrl = getClass().getResource(
203: "/wsdl/jms_test_no_addr.wsdl");
204: assertNotNull(wsdlUrl);
205:
206: EndpointReferenceType ref = EndpointReferenceUtils
207: .getEndpointReference(wsdlUrl, serviceName,
208: "HelloWorldQueueBinMsgPort");
209:
210: createNecessaryConfig(wsdlUrl, serviceName,
211: "HelloWorldQueueBinMsgPort");
212:
213: JMSServerTransport serverTransport = new JMSServerTransport(
214: bus, ref);
215:
216: checkNonDefaultAddressFields(serverTransport
217: .getJmsAddressDetails());
218:
219: JMSServerBehaviorPolicyType serverPolicy = serverTransport
220: .getJMSServerBehaviourPolicy();
221:
222: assertTrue(
223: "JMSServerPolicy messageSelector should be Celtix_message_selector ",
224: "Celtix_message_selector".equals(serverPolicy
225: .getMessageSelector()));
226: assertTrue(
227: "JMSServerPolicy useMessageIDAsCorrelationID should be true ",
228: serverPolicy.isUseMessageIDAsCorrelationID());
229: assertTrue(
230: "JMSServerPolicy useMessageIDAsCorrelationID should be true ",
231: serverPolicy.isTransactional());
232: assertTrue(
233: "JMSServerPolicy durableSubscriberName should be Celtix_subscriber ",
234: "Celtix_subscriber".equals(serverPolicy
235: .getDurableSubscriberName()));
236: }
237:
238: public void checkDefaultAddressFields(
239: JMSAddressPolicyType addrPolicy) throws Exception {
240: assertNotNull("JMSAddress cannot be null ", addrPolicy);
241:
242: assertNull("JMSAddress: connectionUserName should be null",
243: addrPolicy.getConnectionUserName());
244: assertNull("JMSAddress: connectionPassword should be null",
245: addrPolicy.getConnectionPassword());
246: assertNull(
247: "JMSAddress: JndiReplyDestinationName should be null",
248: addrPolicy.getJndiReplyDestinationName());
249: assertNotNull(
250: "JMSAddress: JndiDestinationName should not be null",
251: addrPolicy.getJndiDestinationName());
252: assertNotNull(
253: "JMSAddress: jndiConnectionFactoryName should not be null",
254: addrPolicy.getJndiConnectionFactoryName());
255: assertEquals(addrPolicy.getDestinationStyle().value(),
256: JMSConstants.JMS_QUEUE);
257:
258: assertNotNull("JMSAddress: jmsNaming should not be null ",
259: addrPolicy.getJMSNamingProperty());
260: }
261:
262: public void checkNonDefaultAddressFields(
263: JMSAddressPolicyType addrPolicy) throws Exception {
264:
265: assertNotNull("JMSAddress cannot be null ", addrPolicy);
266:
267: assertEquals(
268: "JMSAddress: connectionUserName should be testUser",
269: "testUser", addrPolicy.getConnectionUserName());
270: assertEquals(
271: "JMSAddress: connectionPassword should be testPassword",
272: "testPassword", addrPolicy.getConnectionPassword());
273: assertEquals(
274: "JMSAddress: JndiReplyDestinationName should be myOwnReplyDestination",
275: "myOwnReplyDestination", addrPolicy
276: .getJndiReplyDestinationName());
277: assertEquals(
278: "JMSAddress: JndiDestinationName should be myOwnDestination",
279: "myOwnDestination", addrPolicy.getJndiDestinationName());
280: assertEquals(
281: "JMSAddress: jndiConnectionFactoryName should be MockConnectionFactory",
282: "MockConnectionFactory", addrPolicy
283: .getJndiConnectionFactoryName());
284: assertEquals("JMSAddress: destinationStyle should be queue",
285: addrPolicy.getDestinationStyle().value(),
286: JMSConstants.JMS_QUEUE);
287:
288: assertNotNull("JMSAddress: jmsNaming should not be null ",
289: addrPolicy.getJMSNamingProperty());
290: }
291:
292: }
|