Source code: providers/PlugableProvidersTest.java
1 /*
2 * The Apache Software License, Version 1.1
3 *
4 *
5 * Copyright (c) 2002 The Apache Software Foundation. All rights
6 * reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. The end-user documentation included with the redistribution,
21 * if any, must include the following acknowledgment:
22 * "This product includes software developed by the
23 * Apache Software Foundation (http://www.apache.org/)."
24 * Alternately, this acknowledgment may appear in the software itself,
25 * if and wherever such third-party acknowledgments normally appear.
26 *
27 * 4. The names "WSIF" and "Apache Software Foundation" must
28 * not be used to endorse or promote products derived from this
29 * software without prior written permission. For written
30 * permission, please contact apache@apache.org.
31 *
32 * 5. Products derived from this software may not be called "Apache",
33 * nor may "Apache" appear in their name, without prior written
34 * permission of the Apache Software Foundation.
35 *
36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This software consists of voluntary contributions made by many
51 * individuals on behalf of the Apache Software Foundation and was
52 * originally based on software copyright (c) 2001, 2002, International
53 * Business Machines, Inc., http://www.apache.org. For more
54 * information on the Apache Software Foundation, please see
55 * <http://www.apache.org/>.
56 */
57
58 package providers;
59
60 import junit.framework.Test;
61 import junit.framework.TestCase;
62 import junit.framework.TestSuite;
63
64 import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
65 import org.apache.wsif.providers.soap.apachesoap.WSIFDynamicProvider_ApacheSOAP;
66 import org.apache.wsif.spi.WSIFProvider;
67 import org.apache.wsif.util.WSIFPluggableProviders;
68 import util.TestUtilities;
69
70 /**
71 * Junit test to test the plugable providers facility for WSIFDynamicProviders
72 */
73 public class PlugableProvidersTest extends TestCase {
74
75 private static final Class DEFAULT_SOAP_PROVIDER =
76 TestUtilities.DEFAULT_SOAP_PROVIDER_CLASS;
77 private static final Class NON_DEFAULT_SOAP_PROVIDER =
78 TestUtilities.NON_DEFAULT_SOAP_PROVIDER_CLASS;
79
80 private static final String DEFAULT_PROVIDER_NAME =
81 DEFAULT_SOAP_PROVIDER.getName();
82 private static final String NON_DEFAULT_PROVIDER_NAME =
83 NON_DEFAULT_SOAP_PROVIDER.getName();
84
85 public PlugableProvidersTest(String name) {
86 super(name);
87 }
88
89 public static void main(String[] args) {
90 junit.textui.TestRunner.run (suite());
91 }
92
93 public static Test suite() {
94 return new TestSuite(PlugableProvidersTest.class);
95 }
96
97 public void setUp() {
98 TestUtilities.setUpExtensionsAndProviders();
99 }
100
101 public void testEJBProvider() {
102 reset();
103 assertTrue( "testEJBProvider doit failed!", doit("http://schemas.xmlsoap.org/wsdl/ejb/",
104 "org.apache.wsif.providers.ejb.WSIFDynamicProvider_EJB") );
105 }
106
107 public void testJavaProvider() {
108 reset();
109 assertTrue( "testJavaProvider doit failed!", doit("http://schemas.xmlsoap.org/wsdl/java/",
110 "org.apache.wsif.providers.java.WSIFDynamicProvider_Java") );
111 }
112
113 public void testDefaultSoapProvider() {
114 reset();
115
116 assertTrue(
117 "testDefaultSoapProvider doit failed!",
118 doit(
119 "http://schemas.xmlsoap.org/wsdl/soap/",
120 DEFAULT_PROVIDER_NAME ) );
121 }
122
123 public void testSetDefaultSoapProvider() {
124 reset();
125 WSIFProvider p = null;
126 try {
127 p = (WSIFProvider)NON_DEFAULT_SOAP_PROVIDER.newInstance();
128 } catch (Exception ex) {
129 assertTrue( "exception instantiating non default provider: " + ex.getMessage(), false );
130 }
131 WSIFPluggableProviders.overrideDefaultProvider(
132 "http://schemas.xmlsoap.org/wsdl/soap/",
133 p );
134 assertTrue(
135 "testSetDefaultSoapProvider",
136 doit(
137 "http://schemas.xmlsoap.org/wsdl/soap/",
138 NON_DEFAULT_PROVIDER_NAME ) );
139 // set null so uses default next time
140 WSIFPluggableProviders.overrideDefaultProvider(
141 "http://schemas.xmlsoap.org/wsdl/soap/", null );
142
143 }
144
145 //public void testSoapRMIProvider() {
146 // assertTrue( doit("http://schemas.xmlsoap.org/wsdl/soap/xxx",
147 // "org.apache.wsif.providers.soap.soaprmi.WSIFDynamicProvider_SoapRMI") );
148 //}
149
150 public void testPPMethods() {
151
152 reset();
153
154 // test isProviderAvailable method
155 assertTrue( "isProviderAvailable 1",
156 WSIFPluggableProviders.isProviderAvailable(
157 "http://schemas.xmlsoap.org/wsdl/soap/",
158 "http://schemas.xmlsoap.org/wsdl/soap/") );
159 assertTrue( "isProviderAvailable 2",
160 WSIFPluggableProviders.isProviderAvailable(
161 "http://schemas.xmlsoap.org/wsdl/soap/",
162 "http://schemas.xmlsoap.org/wsdl/jms/") );
163 assertTrue( "isProviderAvailable 3",
164 !WSIFPluggableProviders.isProviderAvailable(
165 "http://schemas.xmlsoap.org/wsdl/soap/",
166 "http://schemas.xmlsoap.org/wsdl/xxx/") );
167 assertTrue( "isProviderAvailable 4",
168 !WSIFPluggableProviders.isProviderAvailable(
169 "http://schemas.xmlsoap.org/wsdl/xxx/",
170 "http://schemas.xmlsoap.org/wsdl/jms/") );
171 assertTrue( "isProviderAvailable 5",
172 !WSIFPluggableProviders.isProviderAvailable(
173 "http://schemas.xmlsoap.org/wsdl/xxx/",
174 "http://schemas.xmlsoap.org/wsdl/xxx/") );
175 assertTrue( "isProviderAvailable 6",
176 WSIFPluggableProviders.isProviderAvailable(
177 "http://schemas.xmlsoap.org/wsdl/java/") );
178 assertTrue( "isProviderAvailable 7",
179 !WSIFPluggableProviders.isProviderAvailable(
180 "http://schemas.xmlsoap.org/wsdl/xxx/") );
181
182 // test the default SOAP provider
183 WSIFProvider p1 = WSIFPluggableProviders.getProvider(
184 "http://schemas.xmlsoap.org/wsdl/soap/" );
185 Class c1 = p1.getClass();
186 assertTrue( "defaultprovider 0", DEFAULT_SOAP_PROVIDER.equals( c1 ) );
187
188 // test changing the default provider
189 WSIFProvider p = null;
190 try {
191 p = (WSIFProvider)NON_DEFAULT_SOAP_PROVIDER.newInstance();
192 } catch (Exception ex) {
193 assertTrue( "exception instantiating non default provider: " + ex.getMessage(), false );
194 }
195 WSIFPluggableProviders.overrideDefaultProvider(
196 "http://schemas.xmlsoap.org/wsdl/soap/",
197 p );
198
199 WSIFProvider p2 = WSIFPluggableProviders.getProvider(
200 "http://schemas.xmlsoap.org/wsdl/soap/" );
201 Class c2 = p2.getClass();
202 assertTrue( "defaultprovider 1", NON_DEFAULT_SOAP_PROVIDER.equals( c2 ) );
203
204 WSIFPluggableProviders.overrideDefaultProvider(
205 "http://schemas.xmlsoap.org/wsdl/soap/",
206 null );
207 WSIFProvider p3 = WSIFPluggableProviders.getProvider(
208 "http://schemas.xmlsoap.org/wsdl/soap/" );
209 Class c3 = p3.getClass();
210 assertTrue( "defaultprovider 2", c1.equals( c3 ) );
211 assertTrue( "defaultprovider 3", p1 == p3 );
212
213 WSIFPluggableProviders.overrideDefaultProvider(
214 "http://schemas.xmlsoap.org/wsdl/soap/",
215 p1 );
216 p2 = WSIFPluggableProviders.getProvider(
217 "http://schemas.xmlsoap.org/wsdl/soap/" );
218 c2 = p2.getClass();
219 assertTrue( "defaultprovider 4", c1.equals( c2 ) );
220 assertTrue( "defaultprovider 5", p1 == p2 );
221
222 WSIFPluggableProviders.overrideDefaultProvider(
223 "http://schemas.xmlsoap.org/wsdl/soap/",
224 null );
225 p2 = WSIFPluggableProviders.getProvider(
226 "http://schemas.xmlsoap.org/wsdl/soap/" );
227 c2 = p2.getClass();
228 assertTrue( "defaultprovider 6", c1.equals( c2 ) );
229 assertTrue( "defaultprovider 7", p1 == p2 );
230
231 // test provider auto loading
232 WSIFPluggableProviders.setAutoLoadProviders( false );
233 assertTrue( "AutoLoadProviders 1",
234 !WSIFPluggableProviders.isAutoLoadProviders() );
235 assertTrue( "AutoLoadProviders 2",
236 !WSIFPluggableProviders.isProviderAvailable(
237 "http://schemas.xmlsoap.org/wsdl/soap/",
238 "http://schemas.xmlsoap.org/wsdl/soap/") );
239 WSIFPluggableProviders.overrideDefaultProvider(
240 "http://schemas.xmlsoap.org/wsdl/soap/",
241 new WSIFDynamicProvider_ApacheAxis() );
242 assertTrue( "AutoLoadProviders 3",
243 WSIFPluggableProviders.isProviderAvailable(
244 "http://schemas.xmlsoap.org/wsdl/soap/",
245 "http://schemas.xmlsoap.org/wsdl/soap/") );
246 WSIFPluggableProviders.setAutoLoadProviders( true );
247 assertTrue( "AutoLoadProviders 4",
248 WSIFPluggableProviders.isAutoLoadProviders() );
249
250 assertTrue( "AutoLoadProviders 5", doit(
251 "http://schemas.xmlsoap.org/wsdl/soap/",
252 DEFAULT_PROVIDER_NAME ) );
253
254 }
255
256 private boolean doit (String namespaceURI, String providerClassName) {
257 WSIFProvider provider = WSIFPluggableProviders.getProvider( namespaceURI );
258 String pn = provider.getClass().getName();
259 return pn.equals( providerClassName );
260 }
261
262 private void reset() {
263 // reset and clear loaded providers
264 WSIFPluggableProviders.setAutoLoadProviders( false );
265 WSIFPluggableProviders.setAutoLoadProviders( true );
266 }
267
268 }
269
270
271
272
273