001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package providers;
059:
060: import junit.framework.Test;
061: import junit.framework.TestCase;
062: import junit.framework.TestSuite;
063:
064: import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
065: import org.apache.wsif.providers.soap.apachesoap.WSIFDynamicProvider_ApacheSOAP;
066: import org.apache.wsif.spi.WSIFProvider;
067: import org.apache.wsif.util.WSIFPluggableProviders;
068: import util.TestUtilities;
069:
070: /**
071: * Junit test to test the plugable providers facility for WSIFDynamicProviders
072: */
073: public class PlugableProvidersTest extends TestCase {
074:
075: private static final Class DEFAULT_SOAP_PROVIDER = TestUtilities.DEFAULT_SOAP_PROVIDER_CLASS;
076: private static final Class NON_DEFAULT_SOAP_PROVIDER = TestUtilities.NON_DEFAULT_SOAP_PROVIDER_CLASS;
077:
078: private static final String DEFAULT_PROVIDER_NAME = DEFAULT_SOAP_PROVIDER
079: .getName();
080: private static final String NON_DEFAULT_PROVIDER_NAME = NON_DEFAULT_SOAP_PROVIDER
081: .getName();
082:
083: public PlugableProvidersTest(String name) {
084: super (name);
085: }
086:
087: public static void main(String[] args) {
088: junit.textui.TestRunner.run(suite());
089: }
090:
091: public static Test suite() {
092: return new TestSuite(PlugableProvidersTest.class);
093: }
094:
095: public void setUp() {
096: TestUtilities.setUpExtensionsAndProviders();
097: }
098:
099: public void testEJBProvider() {
100: reset();
101: assertTrue(
102: "testEJBProvider doit failed!",
103: 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(
110: "testJavaProvider doit failed!",
111: doit("http://schemas.xmlsoap.org/wsdl/java/",
112: "org.apache.wsif.providers.java.WSIFDynamicProvider_Java"));
113: }
114:
115: public void testDefaultSoapProvider() {
116: reset();
117:
118: assertTrue("testDefaultSoapProvider doit failed!", 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: "
130: + ex.getMessage(), false);
131: }
132: WSIFPluggableProviders.overrideDefaultProvider(
133: "http://schemas.xmlsoap.org/wsdl/soap/", p);
134: assertTrue("testSetDefaultSoapProvider", doit(
135: "http://schemas.xmlsoap.org/wsdl/soap/",
136: NON_DEFAULT_PROVIDER_NAME));
137: // set null so uses default next time
138: WSIFPluggableProviders.overrideDefaultProvider(
139: "http://schemas.xmlsoap.org/wsdl/soap/", null);
140:
141: }
142:
143: //public void testSoapRMIProvider() {
144: // assertTrue( doit("http://schemas.xmlsoap.org/wsdl/soap/xxx",
145: // "org.apache.wsif.providers.soap.soaprmi.WSIFDynamicProvider_SoapRMI") );
146: //}
147:
148: public void testPPMethods() {
149:
150: reset();
151:
152: // test isProviderAvailable method
153: assertTrue("isProviderAvailable 1", WSIFPluggableProviders
154: .isProviderAvailable(
155: "http://schemas.xmlsoap.org/wsdl/soap/",
156: "http://schemas.xmlsoap.org/wsdl/soap/"));
157: assertTrue("isProviderAvailable 2", WSIFPluggableProviders
158: .isProviderAvailable(
159: "http://schemas.xmlsoap.org/wsdl/soap/",
160: "http://schemas.xmlsoap.org/wsdl/jms/"));
161: assertTrue("isProviderAvailable 3", !WSIFPluggableProviders
162: .isProviderAvailable(
163: "http://schemas.xmlsoap.org/wsdl/soap/",
164: "http://schemas.xmlsoap.org/wsdl/xxx/"));
165: assertTrue("isProviderAvailable 4", !WSIFPluggableProviders
166: .isProviderAvailable(
167: "http://schemas.xmlsoap.org/wsdl/xxx/",
168: "http://schemas.xmlsoap.org/wsdl/jms/"));
169: assertTrue("isProviderAvailable 5", !WSIFPluggableProviders
170: .isProviderAvailable(
171: "http://schemas.xmlsoap.org/wsdl/xxx/",
172: "http://schemas.xmlsoap.org/wsdl/xxx/"));
173: assertTrue(
174: "isProviderAvailable 6",
175: WSIFPluggableProviders
176: .isProviderAvailable("http://schemas.xmlsoap.org/wsdl/java/"));
177: assertTrue(
178: "isProviderAvailable 7",
179: !WSIFPluggableProviders
180: .isProviderAvailable("http://schemas.xmlsoap.org/wsdl/xxx/"));
181:
182: // test the default SOAP provider
183: WSIFProvider p1 = WSIFPluggableProviders
184: .getProvider("http://schemas.xmlsoap.org/wsdl/soap/");
185: Class c1 = p1.getClass();
186: assertTrue("defaultprovider 0", DEFAULT_SOAP_PROVIDER
187: .equals(c1));
188:
189: // test changing the default provider
190: WSIFProvider p = null;
191: try {
192: p = (WSIFProvider) NON_DEFAULT_SOAP_PROVIDER.newInstance();
193: } catch (Exception ex) {
194: assertTrue("exception instantiating non default provider: "
195: + ex.getMessage(), false);
196: }
197: WSIFPluggableProviders.overrideDefaultProvider(
198: "http://schemas.xmlsoap.org/wsdl/soap/", p);
199:
200: WSIFProvider p2 = WSIFPluggableProviders
201: .getProvider("http://schemas.xmlsoap.org/wsdl/soap/");
202: Class c2 = p2.getClass();
203: assertTrue("defaultprovider 1", NON_DEFAULT_SOAP_PROVIDER
204: .equals(c2));
205:
206: WSIFPluggableProviders.overrideDefaultProvider(
207: "http://schemas.xmlsoap.org/wsdl/soap/", null);
208: WSIFProvider p3 = WSIFPluggableProviders
209: .getProvider("http://schemas.xmlsoap.org/wsdl/soap/");
210: Class c3 = p3.getClass();
211: assertTrue("defaultprovider 2", c1.equals(c3));
212: assertTrue("defaultprovider 3", p1 == p3);
213:
214: WSIFPluggableProviders.overrideDefaultProvider(
215: "http://schemas.xmlsoap.org/wsdl/soap/", p1);
216: p2 = WSIFPluggableProviders
217: .getProvider("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/", null);
224: p2 = WSIFPluggableProviders
225: .getProvider("http://schemas.xmlsoap.org/wsdl/soap/");
226: c2 = p2.getClass();
227: assertTrue("defaultprovider 6", c1.equals(c2));
228: assertTrue("defaultprovider 7", p1 == p2);
229:
230: // test provider auto loading
231: WSIFPluggableProviders.setAutoLoadProviders(false);
232: assertTrue("AutoLoadProviders 1", !WSIFPluggableProviders
233: .isAutoLoadProviders());
234: assertTrue("AutoLoadProviders 2", !WSIFPluggableProviders
235: .isProviderAvailable(
236: "http://schemas.xmlsoap.org/wsdl/soap/",
237: "http://schemas.xmlsoap.org/wsdl/soap/"));
238: WSIFPluggableProviders.overrideDefaultProvider(
239: "http://schemas.xmlsoap.org/wsdl/soap/",
240: new WSIFDynamicProvider_ApacheAxis());
241: assertTrue("AutoLoadProviders 3", WSIFPluggableProviders
242: .isProviderAvailable(
243: "http://schemas.xmlsoap.org/wsdl/soap/",
244: "http://schemas.xmlsoap.org/wsdl/soap/"));
245: WSIFPluggableProviders.setAutoLoadProviders(true);
246: assertTrue("AutoLoadProviders 4", WSIFPluggableProviders
247: .isAutoLoadProviders());
248:
249: assertTrue("AutoLoadProviders 5", doit(
250: "http://schemas.xmlsoap.org/wsdl/soap/",
251: DEFAULT_PROVIDER_NAME));
252:
253: }
254:
255: private boolean doit(String namespaceURI, String providerClassName) {
256: WSIFProvider provider = WSIFPluggableProviders
257: .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: }
|