You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2008/06/08 17:30:55 UTC
svn commit: r664514 - in
/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws:
client/dispatch/DynamicPortCachingTests.java spi/ClientMetadataTest.java
Author: dims
Date: Sun Jun 8 08:30:55 2008
New Revision: 664514
URL: http://svn.apache.org/viewvc?rev=664514&view=rev
Log:
cleanup test, reuse code for install/remove a caching factory
Modified:
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DynamicPortCachingTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/spi/ClientMetadataTest.java
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DynamicPortCachingTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DynamicPortCachingTests.java?rev=664514&r1=664513&r2=664514&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DynamicPortCachingTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/client/dispatch/DynamicPortCachingTests.java Sun Jun 8 08:30:55 2008
@@ -18,26 +18,18 @@
*/
package org.apache.axis2.jaxws.client.dispatch;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.jaxws.ClientConfigurationFactory;
+import junit.framework.TestCase;
import org.apache.axis2.jaxws.description.DescriptionTestUtils2;
import org.apache.axis2.jaxws.description.ServiceDescription;
+import org.apache.axis2.jaxws.spi.ClientMetadataTest;
import org.apache.axis2.jaxws.spi.ServiceDelegate;
-import org.apache.axis2.metadata.registry.MetadataFactoryRegistry;
-import org.apache.axis2.engine.AxisConfigurator;
-import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.axis2.AxisFault;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
-
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import junit.framework.TestCase;
-
/**
* Tests the caching and isolation of dynamic ports,i.e. those created with
* Service.addPort(...). Dynamic ports should
@@ -63,7 +55,7 @@
*/
public void _testSamePortsSameService() {
try {
- installCachingFactory();
+ ClientMetadataTest.installCachingFactory();
QName svcQN = new QName(namespaceURI, svcLocalPart);
Service svc1 = Service.create(svcQN);
@@ -103,18 +95,15 @@
} finally {
- restoreOriginalFactory();
+ ClientMetadataTest.restoreOriginalFactory();
}
}
public void testAddPortOOM() {
- System.out.println("testAddPortOOM");
-
- ClientConfigurationFactory oldFactory = setClientConfigurationFactory();
QName svcQN = new QName(namespaceURI, svcLocalPart);
-
try {
+ ClientMetadataTest.installCachingFactory();
for (int i = 0; i < 5000 ; i++) {
Service svc1 = Service.create(svcQN);
System.out.println("Port number " + i);
@@ -125,31 +114,10 @@
} catch (Throwable t) {
fail("Caught throwable " + t);
} finally {
- MetadataFactoryRegistry.setFactory(ClientConfigurationFactory.class, oldFactory);
+ ClientMetadataTest.restoreOriginalFactory();
}
}
- private ClientConfigurationFactory setClientConfigurationFactory() {
- ClientConfigurationFactory oldFactory = (ClientConfigurationFactory) MetadataFactoryRegistry.getFactory(ClientConfigurationFactory.class);
- ClientConfigurationFactory factory = new ClientConfigurationFactory(new AxisConfigurator() {
- public AxisConfiguration getAxisConfiguration() {
- try {
- return ConfigurationContextFactory.createDefaultConfigurationContext().getAxisConfiguration();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- public void loadServices() {
- }
- public void engageGlobalModules() throws AxisFault {
- }
- public void cleanup() {
- }
- });
- MetadataFactoryRegistry.setFactory(ClientConfigurationFactory.class, factory);
- return oldFactory;
- }
-
private List getList(Iterator it) {
List returnList = new ArrayList();
while (it != null && it.hasNext()) {
@@ -157,63 +125,4 @@
}
return returnList;
}
-
- /**
- * Methods to install a client configuration factory that will return the same AxisConfiguration
- * each time. This is used so that the ServiceDescriptions will be cached in the DescriptionFactory.
- *
- * IMPORTANT!!!
- * If you install a caching factory, you MUST restore the original factory before your test
- * exits, otherwise it will remain installed when subsequent tests run and cause REALLY STRANGE
- * failures. Use restoreOriginalFactory() INSIDE A finally() block to restore the factory.
- */
- static private ClientConfigurationFactory originalFactory = null;
- static void installCachingFactory() {
- // install caching factory
- if (originalFactory != null) {
- throw new UnsupportedOperationException("Attempt to install the caching factory when the original factory has already been overwritten");
- }
- originalFactory =
- (ClientConfigurationFactory)MetadataFactoryRegistry.getFactory(ClientConfigurationFactory.class);
- DynamicPortCachingClientContextFactory newFactory = new DynamicPortCachingClientContextFactory();
- MetadataFactoryRegistry.setFactory(ClientConfigurationFactory.class, newFactory);
- resetClientConfigFactory();
- }
- static void restoreOriginalFactory() {
- if (originalFactory == null) {
- throw new UnsupportedOperationException("Attempt to restore original factory to a null value");
- }
- MetadataFactoryRegistry.setFactory(ClientConfigurationFactory.class, originalFactory);
- resetClientConfigFactory();
- originalFactory = null;
- }
- static void resetClientConfigFactory() {
-// Field field;
-// try {
-// field = DescriptionFactoryImpl.class.getDeclaredField("clientConfigFactory");
-// field.setAccessible(true);
-// field.set(null, null);
-// } catch (Exception e) {
-// throw new UnsupportedOperationException("Unable to reset client config factory; caught " + e);
-// }
- }
-
-}
-
-class DynamicPortCachingClientContextFactory extends ClientConfigurationFactory {
- ConfigurationContext context;
-
- public ConfigurationContext getClientConfigurationContext() {
- if (context == null) {
- context = super.getClientConfigurationContext();
- }
- System.out.println("Test version of DynamicPortCachingClientContextFactory: " + context);
- return context;
- }
-
- public void reset() {
- context = null;
- }
-}
-
-
+}
\ No newline at end of file
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/spi/ClientMetadataTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/spi/ClientMetadataTest.java?rev=664514&r1=664513&r2=664514&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/spi/ClientMetadataTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/spi/ClientMetadataTest.java Sun Jun 8 08:30:55 2008
@@ -1047,7 +1047,7 @@
* failures. Use restoreOriginalFactory() INSIDE A finally() block to restore the factory.
*/
static private ClientConfigurationFactory originalFactory = null;
- static void installCachingFactory() {
+ public static void installCachingFactory() {
// install caching factory
if (originalFactory != null) {
throw new UnsupportedOperationException("Attempt to install the caching factory when the original factory has already been overwritten");
@@ -1058,7 +1058,7 @@
MetadataFactoryRegistry.setFactory(ClientConfigurationFactory.class, newFactory);
resetClientConfigFactory();
}
- static void restoreOriginalFactory() {
+ public static void restoreOriginalFactory() {
if (originalFactory == null) {
throw new UnsupportedOperationException("Attempt to restore original factory to a null value");
}