You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-dev@ws.apache.org by wi...@apache.org on 2005/08/12 22:45:46 UTC
svn commit: r232376 [10/112] - in
/webservices/muse/trunk/src/examples/client: ./ bin/ bin/axis/
bin/axis/com/ bin/axis/com/xyz/ bin/org/ bin/org/apache/ bin/org/apache/ws/
bin/org/apache/ws/client/ bin/org/apache/ws/client/async/
bin/org/apache/ws/cli...
Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/Disk.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/Disk.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/Disk.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/Disk.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,309 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.resource.example;
+
+import org.apache.xmlbeans.GDuration;
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.Calendar;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Example bean representing a "backend" managed resource.
+ *
+ * NOTE: Here's a high-level algo for mapping resource prop XSD types to member var types:
+ * <pre>
+ * if ( minOccurs == "1" && maxOccurs == "1" )
+ * type = single object or primitive
+ * elif ( maxOccurs != "unbounded" )
+ * type = array of objects or primitives w/ size=maxOccurs
+ * elif
+ * type = java.util.List
+ * fi
+ * </pre>
+ *
+ * @author Ian P. Springer
+ */
+public class Disk
+ implements Serializable
+{
+ private BigInteger m_number_of_blocks = ExampleConstants.INITIAL_PROP_VALUE__NUMBER_OF_BLOCKS;
+ private Set m_filesystems = buildFileSystemSet( );
+ private Set m_state_info_set = buildStateInfoSet( );
+ private String m_manufacturer = ExampleConstants.INITIAL_PROP_VALUE__MANUFACTURER;
+ private int m_block_size = ExampleConstants.INITIAL_PROP_VALUE__BLOCK_SIZE;
+ private boolean m_isStarted;
+ private final String m_serialNumber;
+ private GDuration m_activeTime = ExampleConstants.INITIAL_PROP_VALUE__ACTIVE_TIME;
+
+ /**
+ * Creates a new {@link Disk} object with the specified serial number.
+ */
+ public Disk( String serialNumber )
+ {
+ m_serialNumber = serialNumber;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param activeTime DOCUMENT_ME
+ */
+ public void setActiveTime( GDuration activeTime )
+ {
+ m_activeTime = activeTime;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public GDuration getActiveTime( )
+ {
+ return m_activeTime;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param blockSize DOCUMENT_ME
+ */
+ public void setBlockSize( int blockSize )
+ {
+ m_block_size = blockSize;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public int getBlockSize( )
+ {
+ return m_block_size;
+ }
+
+ /**
+ * Returns the current capacity, computed via the formula: NumberOfBlocks * BlockSize
+ */
+ public BigInteger getCapacity( )
+ {
+ return computeCapacity( m_number_of_blocks, m_block_size );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getSerialNumber( )
+ {
+ return m_serialNumber;
+ }
+
+ /**
+ * Computes the capacity of a disk with the specified number of blocks and block size.
+ *
+ * @param numberOfBlocks number of blocks
+ * @param blockSize block size
+ *
+ * @return the capacity of a disk with specified number of blocks and block size
+ */
+ public static BigInteger computeCapacity( BigInteger numberOfBlocks,
+ int blockSize )
+ {
+ return numberOfBlocks.multiply( new BigInteger( String.valueOf( blockSize ) ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String[] getFilesystems( )
+ {
+ return (String[]) m_filesystems.toArray( new String[0] );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param manufacturer DOCUMENT_ME
+ */
+ public void setManufacturer( String manufacturer )
+ {
+ m_manufacturer = manufacturer;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getManufacturer( )
+ {
+ return m_manufacturer;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param numberOfBlocks DOCUMENT_ME
+ */
+ public void setNumberOfBlocks( BigInteger numberOfBlocks )
+ {
+ m_number_of_blocks = numberOfBlocks;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public BigInteger getNumberOfBlocks( )
+ {
+ return m_number_of_blocks;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public boolean isStarted( )
+ {
+ return m_isStarted;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public StateInfo[] getStateInfoList( )
+ {
+ return (StateInfo[]) m_state_info_set.toArray( new StateInfo[0] );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param filesystem DOCUMENT_ME
+ */
+ public void addFilesystem( String filesystem )
+ {
+ m_filesystems.add( filesystem );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param stateInfo DOCUMENT_ME
+ */
+ public void addStateInfo( StateInfo stateInfo )
+ {
+ m_state_info_set.add( stateInfo );
+ }
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void removeAllFilesystems( )
+ {
+ m_filesystems = new HashSet( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void removeAllStateInfos( )
+ {
+ m_state_info_set.clear( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param filesystem DOCUMENT_ME
+ */
+ public void removeFilesystem( String filesystem )
+ {
+ m_filesystems.remove( filesystem );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param stateInfo DOCUMENT_ME
+ */
+ public void removeStateInfo( StateInfo stateInfo )
+ {
+ m_state_info_set.remove( stateInfo );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @throws Exception DOCUMENT_ME
+ */
+ public void start( )
+ throws Exception
+ {
+ if ( !m_isStarted )
+ {
+ m_isStarted = true;
+ System.out.println( "Backend disk with serial # " + m_serialNumber + " has been started." );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @throws Exception DOCUMENT_ME
+ */
+ public void stop( )
+ throws Exception
+ {
+ if ( m_isStarted )
+ {
+ m_isStarted = false;
+ System.out.println( "Backend disk with serial # " + m_serialNumber + " has been stopped." );
+ }
+ }
+
+ private Set buildFileSystemSet( )
+ {
+ Set set = new HashSet( );
+ set.add( "/" );
+ return set;
+ }
+
+ private Set buildStateInfoSet( )
+ {
+ Set set = new HashSet( );
+ StateInfo stateInfo1 = new StateInfo( );
+ stateInfo1.setState( "http://stopped" );
+ stateInfo1.setTimeEntered( Calendar.getInstance( ) );
+ set.add( stateInfo1 );
+ StateInfo stateInfo2 = new StateInfo( );
+ stateInfo2.setState( "http://starting" );
+ stateInfo2.setTimeEntered( Calendar.getInstance( ) );
+ set.add( stateInfo2 );
+ return set;
+ }
+}
\ No newline at end of file
Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/ExampleConstants.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/ExampleConstants.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/ExampleConstants.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/ExampleConstants.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,83 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.resource.example;
+
+import org.apache.xmlbeans.GDuration;
+import javax.xml.namespace.QName;
+import java.math.BigInteger;
+
+/**
+ * Example-related constants.
+ *
+ * @author Ian P. Springer
+ */
+public interface ExampleConstants
+{
+ /** DOCUMENT_ME */
+ BigInteger INITIAL_PROP_VALUE__NUMBER_OF_BLOCKS = new BigInteger( "20000000000" );
+
+ /** Target namespace prefix for the disk WSDL */
+ String NSPREFIX_XYZ = "xyz";
+
+ /** Target namespace URI of the disk WSDL */
+ String NSURI_XYZ = "http://xyz.com/";
+
+ /** QNames */
+ QName RESOURCE_PROP_QNAME_ACTIVE_TIME = new QName( NSURI_XYZ, "ActiveTime", NSPREFIX_XYZ );
+
+ /** DOCUMENT_ME */
+ QName RESOURCE_PROP_QNAME_BLOCK_SIZE = new QName( NSURI_XYZ, "BlockSize", NSPREFIX_XYZ );
+
+ /** DOCUMENT_ME */
+ QName RESOURCE_PROP_QNAME_CAPACITY = new QName( NSURI_XYZ, "Capacity", NSPREFIX_XYZ );
+
+ /** DOCUMENT_ME */
+ QName RESOURCE_PROP_QNAME_FILE_SYSTEM = new QName( NSURI_XYZ, "FileSystem", NSPREFIX_XYZ );
+
+ /** DOCUMENT_ME */
+ QName RESOURCE_PROP_QNAME_MANUFACTURER = new QName( NSURI_XYZ, "Manufacturer", NSPREFIX_XYZ );
+
+ /** DOCUMENT_ME */
+ QName RESOURCE_PROP_QNAME_NUMBER_OF_BLOCKS = new QName( NSURI_XYZ, "NumberOfBlocks", NSPREFIX_XYZ );
+
+ /** DOCUMENT_ME */
+ QName RESOURCE_PROP_QNAME_STATE_INFO = new QName( NSURI_XYZ, "StateInfo", NSPREFIX_XYZ );
+
+ /** DOCUMENT_ME */
+ QName RESOURCE_PROP_QNAME_TOPIC_SPACE = new QName( NSURI_XYZ, "TopicSpace", NSPREFIX_XYZ );
+
+ /** DOCUMENT_ME */
+ String INITIAL_PROP_VALUE__MANUFACTURER = "Hewlett-Packard Company";
+
+ /** Name of the deployed disk Web service */
+ String SERVICE_NAME = "disk";
+
+ /** Qualified name of the deployed disk Web service */
+ QName SERVICE_QNAME = new QName( NSURI_XYZ, SERVICE_NAME );
+
+ /** URL path of the disk Web service */
+ String SERVICE_URL_PATH = "/axis/services/" + SERVICE_NAME;
+
+ /** DOCUMENT_ME */
+ int INITIAL_PROP_VALUE__BLOCK_SIZE = 1024;
+
+ /** DOCUMENT_ME */
+ BigInteger INITIAL_PROP_VALUE__CAPACITY =
+ Disk.computeCapacity( INITIAL_PROP_VALUE__NUMBER_OF_BLOCKS, INITIAL_PROP_VALUE__BLOCK_SIZE );
+
+ /** DOCUMENT_ME */
+ GDuration INITIAL_PROP_VALUE__ACTIVE_TIME = new GDuration( "P0M" );
+}
\ No newline at end of file
Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/StateInfo.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/StateInfo.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/StateInfo.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/StateInfo.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,69 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.resource.example;
+
+import java.io.Serializable;
+import java.util.Calendar;
+
+/**
+ * @author Ian P. Springer
+ */
+public class StateInfo
+ implements Serializable
+{
+ private Calendar m_timeEntered;
+ private String m_state;
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param state DOCUMENT_ME
+ */
+ public void setState( String state )
+ {
+ m_state = state;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getState( )
+ {
+ return m_state;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param timeEntered DOCUMENT_ME
+ */
+ public void setTimeEntered( Calendar timeEntered )
+ {
+ m_timeEntered = timeEntered;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Calendar getTimeEntered( )
+ {
+ return ( m_timeEntered );
+ }
+}
\ No newline at end of file
Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/discovery/DiskDiscoveryAgent.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/discovery/DiskDiscoveryAgent.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/discovery/DiskDiscoveryAgent.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/resource/example/discovery/DiskDiscoveryAgent.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,100 @@
+package org.apache.ws.resource.example.discovery;
+
+
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.resource.discovery.DiscoveryAgent;
+import org.apache.ws.resource.discovery.RegistrationManager;
+import org.apache.ws.resource.discovery.faults.RegistrationFailureException;
+import org.apache.ws.resource.discovery.impl.DiscoveryAgentProperty;
+
+import axis.com.xyz.DiskWsdmServiceWSResource;
+
+/**
+ * This is a sample discovery agent that will add one new instance of a
+ * disk resource for each Agent property with an id of ResourceID.
+ * Its value will be the resource id to be used.
+ * <p/>
+ * Below is a sample of how to instantiate 2 instances of
+ * disk resource, one with the id of 1234 and another with one
+ * of 5678.
+ * <p/>
+ * <pre>
+ * <agent-list >
+ * <agent>
+ * <name>Disk Resource Discovery Agent</name>
+ * <class>org.apache.ws.resource.example.discovery.DiskDiscoveryAgent</class>
+ * <properties>
+ * <property id="ResourceID">1234</property>
+ * <property id="ResourceID">5678</property>
+ * </properties>
+ * </agent>
+ * </agent-list>
+ * </pre>
+ *
+ * @author wire
+ * @version $Revision: 1.1 $
+ */
+public class DiskDiscoveryAgent
+ implements DiscoveryAgent
+{
+ /**
+ * Provides log access for this class.
+ */
+ private static final Log LOG = LogFactory.getLog( DiskDiscoveryAgent.class );
+
+ /**
+ * @see DiscoveryAgent#discover(String, RegistrationManager, DiscoveryAgentProperty[])
+ */
+ public void discover( String agentname,
+ RegistrationManager registrationManager,
+ DiscoveryAgentProperty[] agentProps )
+ {
+ // See how many agentProps there are with ResourceID
+ // For each one, create a DiskResource and register it
+ int discoveredCount = 0;
+ for ( int i = 0; i < agentProps.length; i++ )
+ {
+ DiscoveryAgentProperty agentProp = agentProps[i];
+ if ( agentProp.getId( ).equals( "ResourceID" ) )
+ {
+ DiskWsdmServiceWSResource resource = null;
+ try
+ {
+ String resourceId = agentProp.getValue( );
+ resource = new DiskWsdmServiceWSResource( resourceId );
+ resource.getPropertiesManager( ).setReadOnly(new QName( "http://xyz.com/", "Capacity", "xyz" ), true );
+ discoveredCount++;
+ }
+ catch ( Throwable t )
+ {
+ LOG.error( "Discovery failed for DiskWsdmServiceWSResource with Id " + agentProp.getId( ), t );
+ continue;
+ }
+
+ LOG.info( "Attempting to register an instance of DiskWsdmServiceWSResource ResourceID="
+ + agentProp.getValue( ) );
+ try
+ {
+ registrationManager.register( resource );
+ }
+ catch ( RegistrationFailureException rfe )
+ {
+ LOG.error( "Discovery failed to register " + agentProp.getId( ), rfe );
+ }
+ }
+ }
+
+ //Just for conveniance, if nothing was discovered, write that to the log.
+ if ( discoveredCount == 0 )
+ {
+ LOG.warn( "Discovery completed on agent " + agentname + " but no new resources where added." );
+ }
+ else
+ {
+ LOG.info( "Discovery agent <" + agentname + "> finished." );
+ }
+ }
+}
\ No newline at end of file
Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractAxisTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractAxisTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractAxisTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractAxisTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,239 @@
+/*=============================================================================*
+ * Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P. *
+ *=============================================================================*/
+package org.apache.ws.test;
+
+import org.apache.ws.http.NotSoSimpleAxisServer;
+import org.apache.ws.rpc.JaxRpcConstants;
+import org.apache.ws.soap.SaajConstants;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.apache.axis.configuration.FileProvider;
+
+import java.net.MalformedURLException;
+import java.net.ServerSocket;
+import java.net.URL;
+
+/**
+ * Provides some conviencence functionality for easier testing of web services.
+ * Methods provided by this JUnit test case superclass will allow an embedded
+ * Axis server to be started and stopped.
+ *
+ * @author mazz
+ */
+public abstract class AbstractAxisTestCase
+ extends TestCase
+{
+ private static final int ANY_FREE_PORT = 0;
+
+ /*
+ * Make sure JAX-RPC and SAAJ factories all are set to Axis' impls.
+ */
+ static
+ {
+ System.setProperty( JaxRpcConstants.SYSPROP_SERVICE_FACTORY, JaxRpcConstants.IMPL_SERVICE_FACTORY_AXIS );
+ System.setProperty( SaajConstants.SYSPROP_SOAP_FACTORY, SaajConstants.IMPL_SOAP_FACTORY_AXIS );
+ System.setProperty( SaajConstants.SYSPROP_MESSAGE_FACTORY, SaajConstants.IMPL_MESSAGE_FACTORY_AXIS );
+ System.setProperty( SaajConstants.SYSPROP_SOAP_CONNECTION_FACTORY,
+ SaajConstants.IMPL_SOAP_CONNECTION_FACTORY_AXIS );
+ System.setProperty( SaajConstants.SYSPROP_SOAP_ELEMENT_FACTORY, SaajConstants.IMPL_SOAP_ELEMENT_FACTORY_AXIS );
+ }
+
+ /**
+ * the embedded Axis server
+ */
+ private NotSoSimpleAxisServer m_simpleAxisServer;
+
+
+ /**
+ * @see TestCase#TestCase()
+ */
+ public AbstractAxisTestCase( )
+ {
+ super( );
+ }
+
+ /**
+ * @see TestCase#TestCase(String)
+ */
+ public AbstractAxisTestCase( String name )
+ {
+ super( name );
+ }
+
+ /**
+ * Returns the base URL used to contact the Axis server. To access a web service hosted inside
+ * of the embedded Axis server, append the name of the web service to this base URL.
+ * <p/>
+ * Subclasses may override this method if the default is not acceptable. The
+ * default is <code>http://127.0.0.1:####/axis/services/</code> where <code>####</code>
+ * is the {@link #getAxisServerSocketPort() Axis port number} and <code>axis</code> is
+ * the {@link #getAxisContextName() Axis context name}.
+ *
+ * @return base URL for all web services hosted in the embedded Axis server
+ */
+ protected URL getAxisBaseUrl( )
+ {
+ try
+ {
+ return new URL( "http",
+ "127.0.0.1",
+ m_simpleAxisServer.getServerSocket().getLocalPort(),
+ "/" + getAxisContextName( ) + "/services/" );
+ }
+ catch ( MalformedURLException murle )
+ { // should never occur - throw error so as not to force a throws clause in signature
+ throw new AssertionFailedError( murle.toString( ) );
+ }
+ }
+
+ /**
+ * Returns the full directory path containing the WSDD configuration file(s).
+ * This is the base path that is prepended to the
+ * {@link #getAxisConfigFileName() configuration file name}.
+ * <p/>
+ * Subclasses may override this method if the default is not acceptable. The
+ * default is the current directory as defined by the system property
+ * <code>user.dir</code>.
+ *
+ * @return filename of the WSDD configuration file
+ */
+ protected String getAxisConfigBasePath( )
+ {
+ return System.getProperty( "user.dir" );
+ }
+
+ /**
+ * Returns the filename of the actual Axis WSDD configuration file, excluding
+ * all directory paths.
+ * <p/>
+ * Subclasses may override this method if the default is not acceptable. The
+ * default is <code>server-config.wsdd</code>.
+ *
+ * @return filename of the WSDD configuration file
+ */
+ protected String getAxisConfigFileName( )
+ {
+ return "server-config.wsdd";
+ }
+
+ /**
+ * Returns the context name of the Axis servlet for use within an endpoint URL.
+ *
+ * @return context name of the Axis servlet
+ */
+ protected String getAxisContextName( )
+ {
+ return "axis";
+ }
+
+ /**
+ * This setter is to allow subclasses to tell us if we should use an already existing Axis server.
+ *
+ * @param server the embedded Axis server to be used by the tests
+ */
+ protected void setAxisServer( NotSoSimpleAxisServer server )
+ {
+ m_simpleAxisServer = server;
+ }
+
+ /**
+ * @return the embedded Axis server to be used by the tests
+ */
+ protected NotSoSimpleAxisServer getAxisServer( )
+ {
+ return m_simpleAxisServer;
+ }
+
+ /**
+ * Returns the number of the port that the embedded Axis server will accept
+ * requests on.
+ * <p/>
+ * Subclasses may override this method if the default is not acceptable. The
+ * default is <code>8080</code>.
+ *
+ * @return port number that the Axis server will listen to
+ */
+ protected int getAxisServerSocketPort( )
+ {
+ return ANY_FREE_PORT;
+ }
+
+
+ /**
+ * Returns a URL used to request a WSDL document for a web service with the given name.
+ * This method uses {@link #getAxisBaseUrl()} to determine the base URL.
+ *
+ * @param serviceName the name of the web service
+ *
+ * @return URL used to request a web service WSDL document
+ *
+ * @see #getAxisBaseUrl()
+ */
+ protected URL getAxisWebServiceUrl( String serviceName )
+ {
+ try
+ {
+ return new URL( getAxisBaseUrl( ), serviceName );
+ }
+ catch ( MalformedURLException murle )
+ { // should never occur - throw error so as not to force a throws clause in signature
+ throw new AssertionFailedError( murle.toString( ) );
+ }
+ }
+
+ /**
+ * Returns a URL used to request a WSDL document for a web service with the given name.
+ * This method uses {@link #getAxisBaseUrl()} to determine the base URL.
+ *
+ * @param serviceName the name of the web service
+ *
+ * @return URL used to request a web service WSDL document
+ *
+ * @see #getAxisBaseUrl()
+ */
+ protected URL getAxisWebServiceWsdlUrl( String serviceName )
+ {
+ try
+ {
+ return new URL( getAxisBaseUrl( ).toString( ) + serviceName + "?wsdl" );
+ }
+ catch ( MalformedURLException murle )
+ { // should never occur - throw error so as not to force a throws clause in signature
+ throw new AssertionFailedError( murle.toString( ) );
+ }
+ }
+
+ /**
+ * Reads in the Axis configuration file, creates a server socket to accept
+ * requests and then starts the embedded Axis server.
+ *
+ * @throws Exception if failed to get the configuration file, failed to start
+ * the server socket or failed to start the server
+ */
+ protected void startAxisServer( )
+ throws Exception
+ {
+ FileProvider config = new FileProvider( getAxisConfigBasePath( ),
+ getAxisConfigFileName( ) );
+ ServerSocket ss = new ServerSocket( getAxisServerSocketPort( ) );
+ m_simpleAxisServer = new NotSoSimpleAxisServer( );
+ m_simpleAxisServer.setServerSocket( ss );
+ m_simpleAxisServer.setMyConfig( config );
+ m_simpleAxisServer.start( );
+ }
+
+ /**
+ * Stops the embedded Axis server if it is running.
+ */
+ protected void stopAxisServer( )
+ {
+ if ( m_simpleAxisServer != null )
+ {
+ m_simpleAxisServer.stop( );
+ m_simpleAxisServer = null;
+ }
+ }
+}
\ No newline at end of file
Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractMultipleAxisTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractMultipleAxisTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractMultipleAxisTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractMultipleAxisTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,55 @@
+/*=============================================================================*
+ * Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P. *
+ *=============================================================================*/
+package org.apache.ws.test;
+
+import junit.framework.TestCase;
+
+/**
+ * A JUnit test case superclass that will setup each individual test with its own
+ * Axis server. Multiple Axis servers will be started/stopped - one per test method.
+ *
+ * @author mazz
+ */
+public abstract class AbstractMultipleAxisTestCase
+ extends AbstractAxisTestCase
+{
+ /**
+ * @see AbstractAxisTestCase#AbstractAxisTestCase()
+ */
+ public AbstractMultipleAxisTestCase( )
+ {
+ }
+
+ /**
+ * @see AbstractAxisTestCase#AbstractAxisTestCase(String)
+ */
+ public AbstractMultipleAxisTestCase( String name )
+ {
+ super( name );
+ }
+
+ /**
+ * Starts the embedded Axis server.
+ *
+ * @see TestCase#setUp()
+ */
+ protected void setUp( )
+ throws Exception
+ {
+ super.setUp( );
+ startAxisServer( );
+ }
+
+ /**
+ * Stops the embedded Axis server.
+ *
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown( )
+ throws Exception
+ {
+ super.tearDown( );
+ stopAxisServer( );
+ }
+}
Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractNoAxisTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractNoAxisTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractNoAxisTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractNoAxisTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,23 @@
+/*=============================================================================*
+ * Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P. *
+ *=============================================================================*/
+package org.apache.ws.test;
+
+/**
+ * For running tests against an Axis instance running in another JVM (i.e. under Tomcat).
+ *
+ * @author Ian P. Springer
+ */
+public abstract class AbstractNoAxisTestCase
+ extends AbstractAxisTestCase
+{
+ /**
+ * Context is wsdm when not running under a {@link org.apache.axis.transport.http.SimpleAxisServer}.
+ *
+ * @return "wsdm"
+ */
+ protected String getAxisContextName( )
+ {
+ return "wsdm";
+ }
+}
\ No newline at end of file
Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractOneAxisTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractOneAxisTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractOneAxisTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractOneAxisTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,167 @@
+/*=============================================================================*
+ * Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P. *
+ *=============================================================================*/
+package org.apache.ws.test;
+
+import org.apache.ws.http.NotSoSimpleAxisServer;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Vector;
+
+/**
+ * A JUnit test case superclass that will setup one global Axis server for use across all
+ * individual test methods. An embedded Axis server is started before the
+ * first test is run and that one Axis server remains running until the last test completes
+ * its run at which time the Axis server is stopped.
+ *
+ * @author Ian P. Springer
+ */
+public abstract class AbstractOneAxisTestCase
+ extends AbstractAxisTestCase
+{
+ /** number of test methods that have been run (static since JUnit creates one instance of this class per test method) */
+ private static int s_testsRun = 0;
+
+ /** total number of test methods found in the test case (static since JUnit creates one instance of this class per test method) */
+ private static int s_testCount = 0;
+
+ /** axis server for use across all tests in the test case (static since JUnit creates one instance of this class per test method) */
+ private static NotSoSimpleAxisServer s_simpleAxisServer;
+
+ /**
+ * @see AbstractAxisTestCase#AbstractAxisTestCase()
+ */
+ public AbstractOneAxisTestCase( )
+ {
+ super( );
+ }
+
+ /**
+ * @see AbstractAxisTestCase#AbstractAxisTestCase(String)
+ */
+ public AbstractOneAxisTestCase( String name )
+ {
+ super( name );
+ }
+
+ /**
+ * Starts the embedded Axis server iff this is the first test being run within this test case.
+ *
+ * @see TestCase#setUp()
+ */
+ protected void setUp( )
+ throws Exception
+ {
+ super.setUp( );
+
+ if ( s_testsRun++ == 0 )
+ {
+ startAxisServer( );
+ s_simpleAxisServer = getAxisServer( );
+ }
+ else
+ {
+ // a prior test method was run so the Axis server is already started, reuse it
+ setAxisServer( s_simpleAxisServer );
+ }
+ }
+
+ /**
+ * Stops the embedded Axis server after the last test within this test case has finished running.
+ *
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown( )
+ throws Exception
+ {
+ super.tearDown( );
+ if ( s_testsRun == getTestCount( ) )
+ {
+ stopAxisServer( );
+ s_simpleAxisServer = null;
+
+ // reset the counters to prepare for the next test case
+ s_testsRun = 0;
+ s_testCount = 0;
+ }
+ }
+
+ /**
+ * Returns the number of tests in this TestCase.
+ *
+ * @return the number of tests in this TestCase
+ */
+ private int getTestCount( )
+ {
+ if ( s_testCount == 0 )
+ {
+ s_testCount = countTests( this.getClass( ) );
+ }
+ return s_testCount;
+ }
+
+ /**
+ * Examines the given <code>Method</code> and returns <code>true</code> if it is a JUnit test method.
+ *
+ * A method is considered a test method if all of the following are <code>true</code>:
+ * <ol>
+ * <li>The method's name starts with "test"</li>
+ * <li>The method takes 0 parameters</li>
+ * <li>The method returns "void"</li>
+ * <li>The method is public</li>
+ * </ol>
+ *
+ * @param m the method to check
+ *
+ * @return <code>true</code> if the given method is a JUnit test method; <code>false</code> otherwise
+ */
+ private boolean isTestMethod( Method m )
+ {
+ String name = m.getName( );
+ Class[] parameters = m.getParameterTypes( );
+ Class returnType = m.getReturnType( );
+ boolean is_public = Modifier.isPublic( m.getModifiers( ) );
+
+ return ( parameters.length == 0 ) && name.startsWith( "test" ) && returnType.equals( Void.TYPE )
+ && is_public;
+ }
+
+ /**
+ * Counts the test methods in the specified JUnit TestCase class.
+ *
+ * @param testCaseClass a JUnit TestCase class
+ *
+ * @return the number of test methods in the specified TestCase class
+ *
+ * @see #isTestMethod(Method)
+ */
+ private int countTests( final Class testCaseClass )
+ {
+ Class superClass = testCaseClass;
+ Vector tests = new Vector( );
+
+ while ( Test.class.isAssignableFrom( superClass ) )
+ {
+ Method[] methods = superClass.getDeclaredMethods( );
+
+ for ( int i = 0; i < methods.length; i++ )
+ {
+ if ( !tests.contains( methods[i].getName( ) ) )
+ {
+ if ( isTestMethod( methods[i] ) )
+ {
+ tests.add( methods[i].getName( ) );
+ }
+ }
+ }
+
+ superClass = superClass.getSuperclass( );
+ }
+
+ return tests.size( );
+ }
+}
\ No newline at end of file
Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractSerializationTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractSerializationTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractSerializationTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/test/AbstractSerializationTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,96 @@
+/*=============================================================================*
+ * Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P. *
+ *=============================================================================*/
+package org.apache.ws.test;
+
+import junit.framework.TestCase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * Superclass test case for use if a test case wants to perform serialization checks.
+ *
+ * @author mazz
+ */
+public abstract class AbstractSerializationTestCase
+ extends TestCase
+{
+ private static final Log LOG = LogFactory.getLog( AbstractSerializationTestCase.class );
+
+ /**
+ * De-Serializes the given string into an object.
+ *
+ * @param s bytes to de-serialize
+ *
+ * @return de-serialized object
+ */
+ protected Object deSerializeObject( byte[] s )
+ {
+ Object ret_obj;
+
+ try
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream( s );
+ ObjectInputStream ois = new ObjectInputStream( bais );
+
+ ret_obj = ois.readObject( );
+
+ assertNotNull( ret_obj );
+
+ LOG.debug( "DeserializedObject.toString(): " + ret_obj ); // just to see what the de-serialized data looks like
+
+ return ret_obj;
+ }
+ catch ( Exception e )
+ {
+ fail( "Cannot de-serialize object: " + e );
+
+ return null; // never gets here
+ }
+ }
+
+ /**
+ * Serializes the given object then immediately de-serializes it.
+ *
+ * @param o object to serialize then de-serialize
+ *
+ * @return the de-serialized object - should be equal to the input though will not be the same
+ */
+ protected Object roundTrip( Object o )
+ {
+ return deSerializeObject( serializeObject( o ) );
+ }
+
+ /**
+ * Serializes the given object.
+ *
+ * @param o object to serialize
+ *
+ * @return serialized data
+ */
+ protected byte[] serializeObject( Object o )
+ {
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream( );
+ ObjectOutputStream oos = new ObjectOutputStream( baos );
+
+ oos.writeObject( o );
+
+ //System.out.println( baos.toString( ) ); // just to see what the serialized data looks like
+ return baos.toByteArray( );
+ }
+ catch ( IOException ioe )
+ {
+ fail( "Cannot serialize object '" + o.getClass( ) + "': " + ioe );
+
+ return null; // never gets here
+ }
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org