axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject cvs commit: xml-axis-wsif/java/test/util WSIFTestRunner.java
Date Thu, 20 Jun 2002 14:52:10 GMT
antelder    2002/06/20 07:52:10

  Modified:    java/test/util WSIFTestRunner.java
  Added:       java/test/async AsyncTests.java
  Removed:     java/test/async AsyncTest.java
               java/test/jms NativeJMSTest.java
  Log:
  Merge the AsyncTest and NativeJMSTest into a new testcase AsyncTests which does a more thorough
test of all the async providers
  
  Revision  Changes    Path
  1.1                  xml-axis-wsif/java/test/async/AsyncTests.java
  
  Index: AsyncTests.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "WSIF" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, 2002, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package async;
  
  import junit.framework.*;
  
  import addressbook.wsiftypes.AddressBook;
  import addressbook.wsiftypes.Address;
  import addressbook.wsiftypes.Phone;
  import stockquote.wsifservice.StockquotePT;
  import stockquote.wsiftypes.StockQuote;
  
  import org.apache.wsif.*;
  import org.apache.wsif.util.*;
  import org.apache.wsif.base.*;
  import org.apache.wsif.util.jms.*;
  import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
  
  import javax.jms.*;
  import javax.mail.MessagingException;
  
  import org.apache.wsif.providers.jms.*;
  
  import util.TestUtilities;
  
  import com.ibm.mq.jms.MQQueueConnectionFactory;
  
  import java.util.HashMap;
  
  /**
   * Junit test to test the NativeJMSProvider
   * 
   * need to use the wsifjmssetup.bat and wsifmqset.bat 
   * 
   */
  public class AsyncTests extends TestCase {
  
    public static String name1 = "Purdue Boilermaker";
    public static Address addr1 =
      new Address(
        1,
        "University Drive",
        "West Lafayette",
        "IN",
        47907,
        new Phone(765, "494", "4900"));
  
    public AsyncTests(String name) {
      super(name);
    }
  
    public static void main(String[] args) {
      junit.textui.TestRunner.run(suite());
    }
  
    public static Test suite() {
      return new TestSuite(AsyncTests.class);
    }
  
    public void setUp() {
      TestUtilities.setUpExtensionsAndProviders();
    }
  
    public void testSoapJms() {
    	 if ( TestUtilities.areWeTesting("jms") ) {
    		 doitStockquote( "SOAPJMSPort", "soap" );
           doitAddressBook_addEntry( "SOAPJMSPort", "soap" );
    	     doitAddressBook_getAddressFromName( "SOAPJMSPort", "soap" );
       } 
    }
  
    public void testAxisJms() {
    	 if ( TestUtilities.areWeTesting("jms") ) {
    		 doitStockquote( "SOAPJMSPort", "axis" );
           doitAddressBook_addEntry( "SOAPJMSPort", "axis" );
    	     doitAddressBook_getAddressFromName( "SOAPJMSPort", "axis" );
       } 
    }
  
    public void testNativeJms() {
    	 if ( TestUtilities.areWeTesting("jms") ) {
    		 doitStockquote( "NativeJmsPort", "" );
           doitAddressBook_addEntry( "NativeJmsPort", "" );
    	     doitAddressBook_getAddressFromName( "NativeJmsPort", "" ); 
    	 }
    }
  
    /**
     * Query Stockquote sample
     */
    public void doitStockquote(String portName, String protocol) {
      if ( portName.indexOf( "JMS" ) != -1 && !TestUtilities.areWeTesting("jms") )
{ 
         return;
      }
  
      if ( protocol.equals("axis") ) {
         WSIFServiceImpl.setDynamicWSIFProvider(
            "http://schemas.xmlsoap.org/wsdl/soap/", 
            new WSIFDynamicProvider_ApacheAxis());
      }
  
      String portType = "StockquotePT";
      String operationName = "getQuote";
  
      String wsdlLocation =
        TestUtilities.getWsdlPath("java\\samples\\stockquote\\wsifservice") + "StockQuote.wsdl";
  
      System.out.println("\n=== StockQuote");
      try {
        WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
          WSIFService service = factory.getService(wsdlLocation, 
          	null, // serviceNS
      		null, // serviceName
              "http://wsifservice.stockquote/", // portTypeNS
    			portType); // portTypeName
  
        WSIFPort port = service.getPort(portName);
  
        // Executing synchronous executeRequestResponseOperation(input, output, fault )
        WSIFOperation operation = port.createOperation(operationName);
  
        WSIFMessage context = new WSIFDefaultMessage();
        context.setObjectPart( WSIFConstants.CONTEXT_JMS_PREFIX + "JMSReplyTo", 
                               TestUtilities.getWsifProperty("wsif.nativejms.responseq") );
        operation.setContext( context );
  
        WSIFMessage input = operation.createInputMessage();
        input.setName("GetQuoteInput");
        input.setObjectPart("symbol", "" );
  
        WSIFMessage output = operation.createOutputMessage();
        WSIFMessage fault = operation.createFaultMessage();
  
        doSyncOp( operation, input, output, context );
        float value = ((Float)output.getObjectPart( "quote" )).floatValue();
        System.out.println("sync stockquote found value = " + value);
        assertTrue( "doSyncOp stockquote value incorrect!", 
                    value == -1.0F );
  
        // Executing executeRequestResponseAsync(input, handler)
        operation = port.createOperation(operationName);
  
        operation.setContext( context );
  
        input = operation.createInputMessage();
        input.setName("GetQuoteInput");
        input.setObjectPart("symbol", "" );
        
        output = doAsyncOp( operation, input, context );
        value = ((Float)output.getObjectPart( "quote" )).floatValue();
        System.out.println("async stockquote found value = " + value);
        assertTrue( "doAsyncOp stockquote value incorrect!", 
                    value == -1.0F );
  
        // Executing executeRequestResponseAsync(input)
        operation = port.createOperation(operationName);
  
        operation.setContext( context );
  
        input = operation.createInputMessage();
        input.setName("GetQuoteInput");
        input.setObjectPart("symbol", "" );
        
        output = doAsyncOpNoHandler( operation, input, context );
        value = ((Float)output.getObjectPart( "quote" )).floatValue();
        System.out.println("async stockquote found value = " + value);
        assertTrue( "doAsyncOpNoHandler stockquote value incorrect!", 
                    value == -1.0F );
  
      } catch (Exception e) {
          e.printStackTrace();
          assertTrue("exception during stockquote test: " + e.getMessage(), false);
      }
    }
  
    /**
     * AddressBook sample - addEntry 
     */
    public void doitAddressBook_addEntry(String portName, String protocol) {
  
      if ( portName.indexOf( "JMS" ) != -1 && !TestUtilities.areWeTesting("jms") )
{ 
         return;
      }
  
      if ( protocol.equals("axis") ) {
         WSIFServiceImpl.setDynamicWSIFProvider(
            "http://schemas.xmlsoap.org/wsdl/soap/", 
            new WSIFDynamicProvider_ApacheAxis());
      }
  
      String portType = "AddressBook";
      String operationName = "addEntry";
  
      String wsdlLocation =
        TestUtilities.getWsdlPath("java\\samples\\addressbook\\wsifservice")
          + "AddressBook.wsdl";
  
      System.out.println("\n=== AddressBook_addEntry");
  
      try {
        WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
          WSIFService service = factory.getService(wsdlLocation, 
          	null, // serviceNS
      		null, // serviceName
              "http://wsifservice.addressbook/", // portTypeNS
    			portType); // portTypeName
  
        service.mapType(
           new javax.wsdl.QName("http://wsiftypes.addressbook/", "address"),
           Class.forName("addressbook.wsiftypes.Address"));
  
        service.mapType(
           new javax.wsdl.QName("http://wsiftypes.addressbook/", "phone"),
           Class.forName("addressbook.wsiftypes.Phone"));
  
        WSIFPort port = service.getPort(portName);
  
        WSIFOperation operation = port.createOperation(operationName,
                                    "AddEntryWholeNameRequest", null);
  
        WSIFMessage input = operation.createInputMessage();
        input.setObjectPart("name", name1);
        input.setObjectPart("address", addr1); 
  
        operation.executeInputOnlyOperation(input);
  
      } catch (Exception e) {
        e.printStackTrace();
        assertTrue("exception during addressbook addEntry: " + e.getMessage(),
                   false);
      }
  
    }
  
    /**
     * AddressBook sample - getAddressFromName
     */
    public void doitAddressBook_getAddressFromName(String portName, String protocol) {
  
      if ( portName.indexOf( "JMS" ) != -1 && !TestUtilities.areWeTesting("jms") )
{ 
         return;
      }
  
      if ( protocol.equals("axis") ) {
         WSIFServiceImpl.setDynamicWSIFProvider(
            "http://schemas.xmlsoap.org/wsdl/soap/", 
            new WSIFDynamicProvider_ApacheAxis());
      }
  
      String portType = "AddressBook";
      String operationName = "getAddressFromName";
  
      String wsdlLocation =
        TestUtilities.getWsdlPath("java\\samples\\addressbook\\wsifservice")
          + "AddressBook.wsdl";
  
      System.out.println("\n=== AddressBook_getAddressFromName");
  
      try {
        WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
          WSIFService service = factory.getService(wsdlLocation, 
          	null, // serviceNS
      		null, // serviceName
              "http://wsifservice.addressbook/", // portTypeNS
    			portType); // portTypeName
  
        service.mapType(
           new javax.wsdl.QName("http://wsiftypes.addressbook/", "address"),
           Class.forName("addressbook.wsiftypes.Address"));
  
        service.mapType(
           new javax.wsdl.QName("http://wsiftypes.addressbook/", "phone"),
           Class.forName("addressbook.wsiftypes.Phone"));
  
        WSIFPort port = service.getPort(portName);
  
        // Executing synchronous executeRequestResponseOperation(input, output, fault )
        String inputMsgName = "GetAddressFromNameRequest";
        String outputMsgName = "GetAddressFromNameResponse";
        WSIFOperation operation =
          port.createOperation(operationName, inputMsgName, outputMsgName);
  
        WSIFMessage context = new WSIFDefaultMessage();
        context.setObjectPart( WSIFConstants.CONTEXT_JMS_PREFIX + "JMSReplyTo", 
                               TestUtilities.getWsifProperty("wsif.nativejms.responseq") );
        operation.setContext( context );
      
        WSIFMessage input = operation.createInputMessage();
        input.setObjectPart("name", name1);
  
        WSIFMessage output = operation.createOutputMessage();
        WSIFMessage fault = operation.createFaultMessage();
  
        doSyncOp( operation, input, output, context );
        
        Address addressResponse = (Address) output.getObjectPart("address");
        System.out.println("Found address = " + addressResponse);
        assertTrue( "doSyncOp addresses not equal!", addr1.equals(addressResponse) );
  
        // Executing executeRequestResponseOperation(input, output, fault )
        operation =
          port.createOperation(operationName, inputMsgName, outputMsgName);
  
        operation.setContext( context );
      
        input = operation.createInputMessage();
        input.setObjectPart("name", name1);
  
        output = operation.createOutputMessage();
  
        output = doAsyncOp( operation, input, context );
        
        addressResponse = (Address) output.getObjectPart("address");
        System.out.println("Found address = " + addressResponse);
        assertTrue( "doAsyncOp addresses not equal!", addr1.equals(addressResponse) );
  
        // Executing executeRequestResponseAsync(input)
        operation =
          port.createOperation(operationName, inputMsgName, outputMsgName);
  
        operation.setContext( context );
      
        input = operation.createInputMessage();
        input.setObjectPart("name", name1);
  
        output = doAsyncOpNoHandler( operation, input, context );
        addressResponse = (Address) output.getObjectPart("address");
        System.out.println("Found address = " + addressResponse);
        assertTrue( "doAsyncOpNoHandler addresses not equal!", addr1.equals(addressResponse)
);
  
      } catch (Exception e) {
        e.printStackTrace();
        assertTrue("exception during addressbook getAddressFromName test: " + e.getMessage(),
false);
      }
  
    }
  
    private void doSyncOp(WSIFOperation op, 
                                  WSIFMessage input, WSIFMessage output, WSIFMessage context)
{
        try {
           op.setContext( context );
        	 WSIFMessage fault = op.createFaultMessage();
           boolean ok = op.executeRequestResponseOperation(input, output, fault );
           assertTrue( "executeRequestResponseOperation returned false!", ok );
        } catch (Exception ex) {
         	 ex.printStackTrace();
      	 assertTrue( "exception executing request: " + ex.getMessage(), false );
        }
    }
  
    private WSIFMessage doAsyncOp(WSIFOperation op, WSIFMessage input, WSIFMessage context)
{
        AsyncResponseHandler handler = new AsyncResponseHandler(1); // 2 async calls
        try {
           context.setObjectPart( WSIFConstants.CONTEXT_JMS_PREFIX + "JMSReplyTo", 
                                  TestUtilities.getWsifProperty("wsif.async.replytoq") );
           op.setContext( context );
           WSIFCorrelationId id = op.executeRequestResponseAsync(input, handler);
           System.out.println( "async operation done, correlation id=" + id.getCorrelationId()
);
        } catch (Exception ex) {
      	 ex.printStackTrace();
      	 assertTrue( "exception executing async op: " + ex.getMessage(), false );
        }
        int i = 5;  // 15 seconds timout
        while ( i-- > 0 && !handler.isDone() ) {
           System.out.println( "async requests sent, waiting for responses - " + i );
      	 try {
      		Thread.sleep(3000);
      	 } catch (InterruptedException ex) {}
        }
        assertTrue( "no response to async operation!", i > 0 ); // no responses in time
        return handler.getOutputs()[0];
    }
  
    private WSIFMessage doAsyncOpNoHandler(WSIFOperation op, WSIFMessage input, WSIFMessage
context) {
        WSIFMessage output = null;
        try {
           context.setObjectPart( WSIFConstants.CONTEXT_JMS_PREFIX + "JMSReplyTo", 
                                  TestUtilities.getWsifProperty("wsif.async.replytoq2") );
           context.setObjectPart( "testJMSnoHandler", "true" ); 
           op.setContext( context );
           WSIFCorrelationId id = op.executeRequestResponseAsync( input );
           System.out.println( "async operation done, correlation id=" + id.getCorrelationId()
);
           op = null;
           
           Object jmsResponse = getJMSResponse( id.getCorrelationId() );
           WSIFCorrelationService cs = 
              WSIFCorrelationServiceLocator.getCorrelationService();
           Object o;
           synchronized( cs ) { 
              o = cs.get( id ); 
           }
           if ( o != null && o instanceof WSIFOperation ) {      
              cs.remove( id ); 
              op = (WSIFOperation)o;
           } else {
           	assertTrue( "stored correlation object not as expected: " + o, false );
           }
           output = op.createOutputMessage();
           WSIFMessage fault = op.createFaultMessage();
           op.processAsyncResponse( jmsResponse, output, fault );
        } catch (Exception ex) {
      	 ex.printStackTrace();
      	 assertTrue( "exception executing async op: " + ex.getMessage(), false );
        }
        return output;
    }
  
    private Message getJMSResponse(String id) throws JMSException {
       QueueConnectionFactory factory = new MQQueueConnectionFactory();
       MQQueueConnectionFactory mqfactory = (MQQueueConnectionFactory) factory;
       QueueConnection connection = factory.createQueueConnection();
       connection.start();
       QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
       Queue readQ = session.createQueue( TestUtilities.getWsifProperty("wsif.async.replytoq2")
);
       QueueReceiver receiver = session.createReceiver( readQ, "JMSCorrelationID='"+id+"'"
);
       return receiver.receive( WSIFProperties.getAsyncTimeout() );
    }
  
  }
  
  
  1.9       +3 -4      xml-axis-wsif/java/test/util/WSIFTestRunner.java
  
  Index: WSIFTestRunner.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/util/WSIFTestRunner.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- WSIFTestRunner.java	20 Jun 2002 11:14:06 -0000	1.8
  +++ WSIFTestRunner.java	20 Jun 2002 14:52:10 -0000	1.9
  @@ -61,7 +61,6 @@
   import invocation.DynamicInvokerTest;
   
   import jms.JmsTest;
  -import jms.NativeJMSTest;
   import jndi.JNDIAddressBookTest;
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -79,9 +78,10 @@
   import stockquote.StockquoteTest;
   import wsdl.WsdlLoadingTest;
   import zipcode.ZIPCodeTest;
  +import jrom.JROMTests;
   
   import addressbook.AddressBookTest;
  -import async.AsyncTest;
  +import async.AsyncTests;
   import headers.HeadersTest;
   import faults.FaultMsgTest;
   
  @@ -179,8 +179,7 @@
           suite.addTest(new TestSuite(ProvidersInitialisationTest.class));
           
           suite.addTest(new TestSuite(ShoppingCartTest.class));
  -        suite.addTest(new TestSuite(AsyncTest.class));
  -        suite.addTest(new TestSuite(NativeJMSTest.class));
  +        suite.addTest(new TestSuite(AsyncTests.class));
           suite.addTest(new TestSuite(HeadersTest.class));
           suite.addTest(new TestSuite(FaultMsgTest.class));
           suite.addTest(new TestSuite(StockquoteTest.class));
  
  
  

Mime
View raw message