CVS: ivory/src/java/org/codehaus/ivory/axis/plexus IvoryTestCase.java,1.2,1.3

[email protected] Mon, 5 May 2003 09:19:12 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/ivory/src/java/org/codehaus/ivory/axis/plexus
In directory eng.werken.com:/tmp/cvs-serv1379/src/java/org/codehaus/ivory/axis/plexus

Modified Files:
	IvoryTestCase.java 
Log Message:
Ivory is really coming along now...

There is now an IvoryProvider which loads the IvoryServiceDesc
instead of Axis's ServiceDesc. The IvoryServiceDesc has 
metadata capabilities.  Currently you can specify to not expose
certain methods as a web service and also specify what type of
array a List should be serialized to (hooray!).

NOTE: You now need commons-attributes installed in your maven
repo! This is only available from apache CVS currently.  See:
http://jakarta.apache.org/commons/sandbox/attributes

Also, there are a bunch of documentation improvements, with
more coming.

Index: IvoryTestCase.java
===================================================================
RCS file: /cvsroot/plexus/ivory/src/java/org/codehaus/ivory/axis/plexus/IvoryTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- IvoryTestCase.java	4 May 2003 20:51:18 -0000	1.2
+++ IvoryTestCase.java	5 May 2003 14:19:10 -0000	1.3
@@ -92,33 +92,39 @@
 public class IvoryTestCase extends PlexusTestCase
 {
     private ServletRunner sr;
-
+    
     private ServiceManager manager;
-
+    
     private String services = "http://localhost/services/";
-
+    
+    private boolean verbose = false;
+    
+    public final static String VERBOSE_KEY = 
+    	"IvoryTestCase.verbose";
+    
     public IvoryTestCase(String name)
     {
         super(name);
     }
-
+    
     public void setUp() throws Exception
     {
         super.setUp();
-
+        setVerbose( Boolean.getBoolean( VERBOSE_KEY ) );
+    
         HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
-
+    
         manager =
             new AvalonServiceManager(getContainer().getComponentRepository());
-
+    
         InputStream is =
             getClass().getResourceAsStream(
                 "/org/codehaus/ivory/axis/plexus/web.xml");
-
+    
         sr = new ServletRunner(is);
-
+    
         ServletUnitClient client = newClient();
-
+    
         // There must be a better way to do this.
         InvocationContext ic =
             client.newInvocation("http://localhost/servlet/AxisServlet");
@@ -126,53 +132,77 @@
             ic.getServlet().getServletConfig().getServletContext();
         context.setAttribute(PlexusServlet.SERVICE_MANAGER_KEY, manager);
     }
-
+    
     protected ServletUnitClient newClient() throws Exception
     {
         return sr.newClient();
     }
-
-	/**
-	 * Assert that the response contains a string.
-	 * @param response
-	 * @param searchfor
-	 * @throws IOException
-	 */
-	public void assertStringInBody(
-		String body,
-		String searchfor)
-		throws IOException
-	{
-		boolean found = body.indexOf(searchfor) >= 0;
-		if (!found)
-		{
-			String message;
-			message = "failed to find [" + searchfor + "].\nBody:\n" + body;
-			fail(message);
-		}
-	}
-	
-	/**
-	 * Assert that the response contains a string.
-	 * @param response
-	 * @param searchfor
-	 * @throws IOException
-	 */
-	public void assertStringInBody(
-		WebResponse response,
-		String searchfor)
-		throws IOException
-	{
-		String body = response.getText();
-		boolean found = body.indexOf(searchfor) >= 0;
-		if (!found)
-		{
-			String message;
-			message = "failed to find [" + searchfor + "].\nBody:\n" + body;
-			fail(message);
-		}
-	}
-	
+    
+    /**
+     * @return
+     */
+    public boolean isVerbose()
+    {
+    	return verbose;
+    }
+    
+    /**
+     * @param b
+     */
+    public void setVerbose(boolean b)
+    {
+    	verbose = b;
+    }
+    
+    /**
+     * Assert that the response contains a string.
+     * @param response
+     * @param searchfor
+     * @throws IOException
+     */
+    public void assertStringInBody(
+    	String body,
+    	String searchfor)
+    	throws IOException
+    {
+    	boolean found = body.indexOf(searchfor) >= 0;
+    	if (!found)
+    	{
+    		String message;
+    		message = "failed to find [" + searchfor + "].\n";
+    		
+    		if ( isVerbose() )
+    			 message += "Body:\n" + body;
+    			 
+    		fail(message);
+    	}
+    }
+    
+    /**
+     * Assert that the response contains a string.
+     * @param response
+     * @param searchfor
+     * @throws IOException
+     */
+    public void assertStringInBody(
+    	WebResponse response,
+    	String searchfor)
+    	throws IOException
+    {
+    	String body = response.getText();
+    	boolean found = body.indexOf(searchfor) >= 0;
+    	if (!found)
+    	{
+    		String message;
+    		message = "failed to find [" + searchfor + "]";
+    		
+    		if ( isVerbose() )
+    			 message += "Body:\n" + body;
+    			 
+    		fail(message);
+    	}
+    }
+    
     /**
      * Assert that the response contains a string.
      * @param response
@@ -191,12 +221,15 @@
         if (!found)
         {
             String message;
-            message = "failed to find [" + searchfor + "] at " + url
-            	      + "\nBody:\n" + body;
+            message = "failed to find [" + searchfor + "] at " + url;
+    		
+    		if ( isVerbose() )
+    			 message += "Body:\n" + body;
+    			 
             fail(message);
         }
     }
-
+    
     /**
      * Assert that a named string is in the request body of the.
      * 
@@ -212,7 +245,7 @@
         WebResponse response = makeRequest(request);
         assertStringInBody(response, searchfor, request.getURL().toString());
     }
-
+    
     /**
      * Make a request in a new session.
      * @param request   request to make
@@ -227,50 +260,58 @@
         WebResponse response = session.getResponse(request);
         return response;
     }
-
-	/**
-	 * Assert that a string is not in a response.
-	 * @param response
-	 * @param searchfor
-	 * @param url
-	 * @throws IOException
-	 */
-	protected void assertStringNotInBody(
-		String body,
-		String searchfor)
-		throws IOException
-	{
-		boolean found = body.indexOf(searchfor) >= 0;
-		if (found)
-		{
-			String message;
-			message = "unexpectedly found [" + searchfor + "].";
-			fail(message);
-		}
-	}
-
-	/**
-	 * Assert that a string is not in a response.
-	 * @param response
-	 * @param searchfor
-	 * @param url
-	 * @throws IOException
-	 */
-	protected void assertStringNotInBody(
-		WebResponse response,
-		String searchfor)
-		throws IOException
-	{
-		String body = response.getText();
-		boolean found = body.indexOf(searchfor) >= 0;
-		if (found)
-		{
-			String message;
-			message = "unexpectedly found [" + searchfor + "].";
-			fail(message);
-		}
-	}
-
+    
+    /**
+     * Assert that a string is not in a response.
+     * @param response
+     * @param searchfor
+     * @param url
+     * @throws IOException
+     */
+    protected void assertStringNotInBody(
+    	String body,
+    	String searchfor)
+    	throws IOException
+    {
+    	boolean found = body.indexOf(searchfor) >= 0;
+    	if (found)
+    	{
+    		String message;
+    		message = "unexpectedly found [" + searchfor + "].";
+    		
+    		if ( isVerbose() )
+    			 message += "Body:\n" + body;
+    			 
+    		fail(message);
+    	}
+    }
+    
+    /**
+     * Assert that a string is not in a response.
+     * @param response
+     * @param searchfor
+     * @param url
+     * @throws IOException
+     */
+    protected void assertStringNotInBody(
+    	WebResponse response,
+    	String searchfor)
+    	throws IOException
+    {
+    	String body = response.getText();
+    	boolean found = body.indexOf(searchfor) >= 0;
+    	if (found)
+    	{
+    		String message;
+    		message = "unexpectedly found [" + searchfor + "].";
+    		
+    		if ( isVerbose() )
+    			 message += "Body:\n" + body;
+    			 
+    		fail(message);
+    	}
+    }
+    
     /**
      * Assert that a string is not in a response.
      * @param response
@@ -290,11 +331,15 @@
         {
             String message;
             message = "unexpectedly found [" + searchfor + "] at " + url;
+    		
+    		if ( isVerbose() )
+    			 message += "Body:\n" + body;
+    			 
             fail(message);
         }
-
+    
     }
-
+    
     /**
      * Assert that a string is not in the response to a request.
      * @param request
@@ -309,7 +354,7 @@
         WebResponse response = session.getResponse(request);
         assertStringNotInBody(response, searchfor, request.getURL().toString());
     }
-
+    
     protected void assertIsXml(String response)
     {
         if(  response.indexOf("<?xml") != 0 )
@@ -317,7 +362,7 @@
         	fail( "Invalid XML:\n" + response );
         } 
     }
-
+    
     /**
      * Here we expect an errorCode other than 200, and look for it
      * checking for text is omitted as it doesnt work. It would never work on
@@ -339,7 +384,7 @@
         WebConversation session = new WebConversation();
         String failureText =
             "Expected error " + errorCode + " from " + request.getURL();
-
+    
         try
         {
             session.getResponse(request);
@@ -357,60 +402,71 @@
             */
         }
     }
-	
-	/**
-	 * Verifies that the service generates WSDL.
-	 * 
-	 * @param service
-	 * @param method
-	 */
-	public void assertValidWSDL( String serviceName, String method )
-		throws Exception
-	{
-		assertValidWSDL( serviceName, new String[]{ method } );
-	}
-	
+    
     /**
      * Verifies that the service generates WSDL.
      * 
      * @param service
-     * @param methods
+     * @param method
      */
-    public void assertValidWSDL( String serviceName, String methods[] )
-        throws Exception
+    public void assertValidWSDL( String serviceName, String method )
+    	throws Exception
     {
-		AxisService service = ( AxisService ) getComponent( AxisService.ROLE );
-		AxisServer server = service.getAxisServer();
-
-		LocalTransport transport = new LocalTransport(server);
-
-		MessageContext msgContext = new MessageContext(server);
-		msgContext.setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS);
-		msgContext.setEncodingStyle(SOAPConstants.SOAP12_CONSTANTS.getEncodingURI());
-
-		msgContext.setTargetService( serviceName );
+    	assertValidWSDL( serviceName, new String[]{ method } );
+    }
+    
+    public String getWSDL( String serviceName ) throws Exception
+    {
+    	AxisService service = ( AxisService ) getComponent( AxisService.ROLE );
+    	AxisServer server = service.getAxisServer();
+    
+    	LocalTransport transport = new LocalTransport(server);
+    
+    	MessageContext msgContext = new MessageContext(server);
+    	msgContext.setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS);
+    	msgContext.setEncodingStyle(SOAPConstants.SOAP12_CONSTANTS.getEncodingURI());
+    
+    	msgContext.setTargetService( serviceName );
         
-		// During a real invocation this is set by the handler, however we
-		// need to set it hear to get the wsdl generation working.
-		msgContext.setProperty( MessageContext.TRANS_URL, 
-								services + serviceName );
-		server.generateWSDL( msgContext );        
+    	// During a real invocation this is set by the handler, however we
+    	// need to set it hear to get the wsdl generation working.
+    	msgContext.setProperty( MessageContext.TRANS_URL, 
+    							services + serviceName );
+    	server.generateWSDL( msgContext );        
         
-		// another one of those undocumented "features"
-		Document doc = (Document) msgContext.getProperty( "WSDL" );
+    	// another one of those undocumented "features"
+    	Document doc = (Document) msgContext.getProperty( "WSDL" );
         
-		StringWriter writer = new StringWriter();
-		XMLUtils.DocumentToWriter(doc, writer);
-		
-		String response = writer.toString();
-		
-		assertIsXml( response );
-		
-		for ( int i = 0; i < methods.length; i++ )
-		{
-			assertStringInBody( response, "<wsdl:operation name=\"" + methods[i] + "\">" );
-			assertStringInBody( response, "<wsdl:input name=\"" + methods[i] + "Request\">" );
-			assertStringInBody( response, "<wsdl:output name=\"" + methods[i] + "Response\">" );
-		}
+    	StringWriter writer = new StringWriter();
+    	XMLUtils.DocumentToWriter(doc, writer);
+    	
+    	return writer.toString();
+    }
+    
+    /**
+     * Verifies that the service generates WSDL.
+     * 
+     * @param service
+     * @param methods
+     */
+    public void assertValidWSDL( String serviceName, String methods[] )
+        throws Exception
+    {
+        String response = getWSDL( serviceName );
+    
+    	if ( isVerbose() )
+    	{
+    		System.out.println( "WSDL for " + serviceName + ":" );
+    		System.out.println( response );
+    	}
+    	
+    	assertIsXml( response );
+    	
+    	for ( int i = 0; i < methods.length; i++ )
+    	{
+    		assertStringInBody( response, "<wsdl:operation name=\"" + methods[i] + "\">" );
+    		assertStringInBody( response, "<wsdl:input name=\"" + methods[i] + "Request\">" );
+    		assertStringInBody( response, "<wsdl:output name=\"" + methods[i] + "Response\">" );
+    	}
     }
 }