1 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 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 WSIFPluggableProviders.overrideDefaultProvider( 141 "http://schemas.xmlsoap.org/wsdl/soap/", null ); 142 143 } 144 145 150 public void testPPMethods() { 151 152 reset(); 153 154 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 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 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 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 WSIFPluggableProviders.setAutoLoadProviders( false ); 265 WSIFPluggableProviders.setAutoLoadProviders( true ); 266 } 267 268 } 269 270 271 272 273 274
| Popular Tags
|