KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > transports > jms > JMSConfigTest


1 package org.objectweb.celtix.bus.transports.jms;
2
3 import java.net.URL JavaDoc;
4
5 import javax.xml.namespace.QName JavaDoc;
6
7 import junit.framework.TestCase;
8
9 import org.objectweb.celtix.Bus;
10 import org.objectweb.celtix.bus.configuration.spring.ConfigurationProviderImpl;
11 import org.objectweb.celtix.configuration.Configuration;
12 import org.objectweb.celtix.configuration.ConfigurationBuilder;
13 import org.objectweb.celtix.configuration.ConfigurationBuilderFactory;
14 import org.objectweb.celtix.configuration.impl.TypeSchemaHelper;
15 import org.objectweb.celtix.transports.jms.JMSAddressPolicyType;
16 import org.objectweb.celtix.transports.jms.JMSClientBehaviorPolicyType;
17 import org.objectweb.celtix.transports.jms.JMSServerBehaviorPolicyType;
18 import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
19 import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
20
21
22 public class JMSConfigTest extends TestCase {
23
24     Bus bus;
25
26     public JMSConfigTest(String JavaDoc name) {
27         super(name);
28     }
29
30     public static void main(String JavaDoc[] args) {
31         junit.textui.TestRunner.run(JMSConfigTest.class);
32     }
33
34     public void setUp() throws Exception JavaDoc {
35         TypeSchemaHelper.clearCache();
36         ConfigurationProviderImpl.clearBeanFactoriesMap();
37         ConfigurationBuilderFactory.clearBuilder();
38         bus = Bus.init();
39     }
40
41     public void tearDown() throws Exception JavaDoc {
42         bus.shutdown(true);
43         if (System.getProperty("celtix.config.file") != null) {
44             System.clearProperty("celtix.config.file");
45         }
46
47         TypeSchemaHelper.clearCache();
48         ConfigurationProviderImpl.clearBeanFactoriesMap();
49         ConfigurationBuilderFactory.clearBuilder();
50     }
51
52     private void createNecessaryConfig(URL JavaDoc wsdlUrl, QName JavaDoc serviceName,
53                                        String JavaDoc portName) throws Exception JavaDoc {
54         assert bus != null;
55         EndpointReferenceType ref = EndpointReferenceUtils.getEndpointReference(wsdlUrl, serviceName,
56                                                                              portName);
57         Configuration busCfg = bus.getConfiguration();
58         assert null != busCfg;
59         Configuration endpointCfg = null;
60         Configuration portCfg = null;
61
62         String JavaDoc id = EndpointReferenceUtils.getServiceName(ref).toString();
63         ConfigurationBuilder cb = ConfigurationBuilderFactory.getBuilder(null);
64
65         // Server Endpoint Config
66
endpointCfg = cb.buildConfiguration(JMSConstants.ENDPOINT_CONFIGURATION_URI, id, busCfg);
67
68         // Client Service Endpoint Port config.
69
portCfg = cb.buildConfiguration(JMSConstants.PORT_CONFIGURATION_URI,
70                               id + "/" + EndpointReferenceUtils.getPortName(ref).toString(),
71                               busCfg);
72         // Server Transport Config.
73
cb.buildConfiguration(JMSConstants.JMS_SERVER_CONFIGURATION_URI,
74                                                  JMSConstants.JMS_SERVER_CONFIG_ID,
75                                                  endpointCfg);
76         //Client Transport Config.
77
cb.buildConfiguration(JMSConstants.JMS_CLIENT_CONFIGURATION_URI,
78                                     JMSConstants.JMS_CLIENT_CONFIG_ID,
79                                     portCfg);
80     }
81
82     public void testDefaultClientConfig() throws Exception JavaDoc {
83
84         QName JavaDoc serviceName = new QName JavaDoc("http://celtix.objectweb.org/hello_world_jms", "HelloWorldService");
85         URL JavaDoc wsdlUrl = getClass().getResource("/wsdl/jms_test.wsdl");
86         assertNotNull(wsdlUrl);
87
88         EndpointReferenceType ref = EndpointReferenceUtils.getEndpointReference(wsdlUrl, serviceName,
89                                                                                 "HelloWorldPort");
90
91         createNecessaryConfig(wsdlUrl, serviceName, "HelloWorldPort");
92
93         JMSClientTransport clientTransport = new JMSClientTransport(bus, ref, null);
94
95         checkDefaultAddressFields(clientTransport.getJmsAddressDetails());
96
97         JMSClientBehaviorPolicyType clientPolicy = clientTransport.getJMSClientBehaviourPolicy();
98         assertTrue("JMSClientBehaviourPolicy cannot be null ", null != clientPolicy);
99
100         assertTrue("JMSClientPolicy messageType should be text ",
101                    JMSConstants.TEXT_MESSAGE_TYPE.equals(clientPolicy.getMessageType().value()));
102     }
103
104     public void testDefaultServerConfig() throws Exception JavaDoc {
105
106         QName JavaDoc serviceName = new QName JavaDoc("http://celtix.objectweb.org/hello_world_jms", "HelloWorldService");
107         URL JavaDoc wsdlUrl = getClass().getResource("/wsdl/jms_test.wsdl");
108         assertNotNull(wsdlUrl);
109
110         EndpointReferenceType ref = EndpointReferenceUtils.getEndpointReference(wsdlUrl, serviceName,
111                                                                                 "HelloWorldPort");
112
113         createNecessaryConfig(wsdlUrl, serviceName, "HelloWorldPort");
114
115         JMSServerTransport serverTransport = new JMSServerTransport(bus, ref);
116
117         checkDefaultAddressFields(serverTransport.getJmsAddressDetails());
118
119         JMSServerBehaviorPolicyType serverPolicy = serverTransport.getJMSServerBehaviourPolicy();
120
121         assertTrue("JMSServerPolicy messageSelector should be null ",
122                    serverPolicy.getMessageSelector() == null);
123         assertTrue("JMSServerPolicy useMessageIDAsCorrelationID should be false ",
124                    !serverPolicy.isUseMessageIDAsCorrelationID());
125         assertTrue("JMSServerPolicy useMessageIDAsCorrelationID should be false ",
126                    !serverPolicy.isTransactional());
127         assertTrue("JMSServerPolicy durableSubscriberName should be null ",
128                    serverPolicy.getDurableSubscriberName() == null);
129     }
130
131     public void testClientConfig() throws Exception JavaDoc {
132
133
134         bus.shutdown(true);
135         URL JavaDoc clientConfigFileUrl = getClass().getResource("/wsdl/jms_test_config.xml");
136         System.setProperty("celtix.config.file", clientConfigFileUrl.toString());
137
138         bus = Bus.init();
139         QName JavaDoc serviceName = new QName JavaDoc("http://celtix.objectweb.org/jms_conf_test",
140                                        "HelloWorldQueueBinMsgService");
141         URL JavaDoc wsdlUrl = getClass().getResource("/wsdl/jms_test_no_addr.wsdl");
142         assertNotNull(wsdlUrl);
143
144         EndpointReferenceType ref = EndpointReferenceUtils.getEndpointReference(wsdlUrl, serviceName,
145                                                                                 "HelloWorldQueueBinMsgPort");
146
147         createNecessaryConfig(wsdlUrl, serviceName, "HelloWorldQueueBinMsgPort");
148
149         JMSClientTransport clientTransport = new JMSClientTransport(bus, ref, null);
150
151         checkNonDefaultAddressFields(clientTransport.getJmsAddressDetails());
152
153         JMSClientBehaviorPolicyType clientPolicy = clientTransport.getJMSClientBehaviourPolicy();
154         assertTrue("JMSClientBehaviourPolicy cannot be null ", null != clientPolicy);
155         assertTrue("JMSClientPolicy messageType should be text ",
156                    JMSConstants.BINARY_MESSAGE_TYPE.equals(clientPolicy.getMessageType().value()));
157
158         System.setProperty("celtix.config.file", "");
159     }
160
161     public void testServerConfig() throws Exception JavaDoc {
162
163         URL JavaDoc clientConfigFileUrl = getClass().getResource("/wsdl/jms_test_config.xml");
164         System.setProperty("celtix.config.file", clientConfigFileUrl.toString());
165
166         QName JavaDoc serviceName = new QName JavaDoc("http://celtix.objectweb.org/jms_conf_test",
167                                        "HelloWorldQueueBinMsgService");
168         URL JavaDoc wsdlUrl = getClass().getResource("/wsdl/jms_test_no_addr.wsdl");
169         assertNotNull(wsdlUrl);
170
171         EndpointReferenceType ref = EndpointReferenceUtils.getEndpointReference(wsdlUrl, serviceName,
172                                                                                 "HelloWorldQueueBinMsgPort");
173
174         createNecessaryConfig(wsdlUrl, serviceName, "HelloWorldQueueBinMsgPort");
175
176         JMSServerTransport serverTransport = new JMSServerTransport(bus, ref);
177
178         checkNonDefaultAddressFields(serverTransport.getJmsAddressDetails());
179
180         JMSServerBehaviorPolicyType serverPolicy = serverTransport.getJMSServerBehaviourPolicy();
181
182         assertTrue("JMSServerPolicy messageSelector should be Celtix_message_selector ",
183                    "Celtix_message_selector".equals(serverPolicy.getMessageSelector()));
184         assertTrue("JMSServerPolicy useMessageIDAsCorrelationID should be true ",
185                    serverPolicy.isUseMessageIDAsCorrelationID());
186         assertTrue("JMSServerPolicy useMessageIDAsCorrelationID should be true ",
187                    serverPolicy.isTransactional());
188         assertTrue("JMSServerPolicy durableSubscriberName should be Celtix_subscriber ",
189                    "Celtix_subscriber".equals(serverPolicy.getDurableSubscriberName()));
190     }
191
192     public void checkDefaultAddressFields(JMSAddressPolicyType addrPolicy) throws Exception JavaDoc {
193         assertNotNull("JMSAddress cannot be null ", addrPolicy);
194
195         assertNull("JMSAddress: connectionUserName should be null",
196                    addrPolicy.getConnectionUserName());
197         assertNull("JMSAddress: connectionPassword should be null",
198                    addrPolicy.getConnectionPassword());
199         assertNull("JMSAddress: JndiReplyDestinationName should be null",
200                    addrPolicy.getJndiReplyDestinationName());
201         assertNotNull("JMSAddress: JndiDestinationName should not be null",
202                    addrPolicy.getJndiDestinationName());
203         assertNotNull("JMSAddress: jndiConnectionFactoryName should not be null",
204                    addrPolicy.getJndiConnectionFactoryName());
205         assertEquals(addrPolicy.getDestinationStyle().value(), JMSConstants.JMS_QUEUE);
206
207
208         assertNotNull("JMSAddress: jmsNaming should not be null ",
209                    addrPolicy.getJMSNamingProperty());
210     }
211
212     public void checkNonDefaultAddressFields(JMSAddressPolicyType addrPolicy) throws Exception JavaDoc {
213
214         assertNotNull("JMSAddress cannot be null ", addrPolicy);
215
216         assertEquals("JMSAddress: connectionUserName should be testUser",
217                    "testUser", addrPolicy.getConnectionUserName());
218         assertEquals("JMSAddress: connectionPassword should be testPassword",
219                    "testPassword", addrPolicy.getConnectionPassword());
220         assertEquals("JMSAddress: JndiReplyDestinationName should be myOwnReplyDestination",
221                    "myOwnReplyDestination", addrPolicy.getJndiReplyDestinationName());
222         assertEquals("JMSAddress: JndiDestinationName should be myOwnDestination",
223                    "myOwnDestination", addrPolicy.getJndiDestinationName());
224         assertEquals("JMSAddress: jndiConnectionFactoryName should be MockConnectionFactory",
225                    "MockConnectionFactory", addrPolicy.getJndiConnectionFactoryName());
226         assertEquals("JMSAddress: destinationStyle should be queue",
227                    addrPolicy.getDestinationStyle().value(), JMSConstants.JMS_QUEUE);
228
229         assertNotNull("JMSAddress: jmsNaming should not be null ",
230                    addrPolicy.getJMSNamingProperty());
231     }
232
233 }
234
Popular Tags