antelder    2002/06/07 01:25:45

  Added:       java/test/headers HeadersTest.java
  Removed:     java/test/async HeadersTest.java
  Log:
  Move headers testcase to its own package
  
  Revision  Changes    Path
  1.1                  xml-axis-wsif/java/test/headers/HeadersTest.java
  
  Index: HeadersTest.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 [EMAIL PROTECTED]
   *
   * 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 headers;
  
  import javax.wsdl.Definition;
  import javax.wsdl.PortType;
  import javax.wsdl.Service;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  import org.apache.wsif.WSIFConstants;
  import org.apache.wsif.WSIFMessage;
  import org.apache.wsif.WSIFOperation;
  import org.apache.wsif.WSIFPort;
  import org.apache.wsif.WSIFService;
  import org.apache.wsif.WSIFServiceFactory;
  import org.apache.wsif.WSIFServiceImpl;
  import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
  import org.apache.wsif.stub.WSIFUtils;
  import org.apache.wsif.util.WSIFDefaultMessage;
  import util.TestUtilities;
  
  /**
   * Junit test to test out the Asynchronous requests.
   *
   * Tests the get/setContext methods using the stockquote sample
   * the context allows seting HTTP and SOAP headers, HTTP headers
   * are currently only uid/pswd for basic authentication.
   * Currently all this does is set them so you can see thme in 
   * the packets using TCPMON.
   * You should see this at the top of the out going packet:
   *    Authorization: Basic cGV0cmE6d2FzaGVyZQ==
   */
  public class HeadersTest extends TestCase {
  
      String wsdlLocation =
          TestUtilities.getWsdlPath("java\\samples\\stockquote\\wsifservice") + 
"Stockquote.wsdl";
  
      public HeadersTest(String name) {
          super(name);
      }
  
      public static void main(String[] args) {
          junit.textui.TestRunner.run(suite());
      }
  
      public static Test suite() {
          return new TestSuite(HeadersTest.class);
      }
  
      public void setUp() {
          TestUtilities.setUpExtensionsAndProviders();
      }
  
      public void testAxis() {
          doit("SOAPPort", "axis");
      }
      //public void testSoap          () { doit("SOAPPort"   ,"soap"); }
      //public void testJava          () { doit("JavaPort"   ,"java"); }
      //public void testSoapJms       () { if (TestUtilities.areWeTesting("jms")) 
doit("SOAPJMSPort","soap"); }
      //public void testAxisJms       () { if (TestUtilities.areWeTesting("jms")) 
doit("SOAPJMSPort","axis"); }
  
      private void doit(String portName, String protocol) {
  
          try {
              invokeMethod(
                  wsdlLocation,
                  "getQuote",
                  null,
                  null,
                  portName,
                  protocol,
                  new String[] { "" },
                  0);
          } catch (Exception e) {
              System.err.println("AsyncTest(" + portName + ") caught exception " + e);
              e.printStackTrace();
              assertTrue(false);
          } finally {
          }
  
      }
  
      public static void invokeMethod(
          String wsdlLocation,
          String operationName,
          String inputName,
          String outputName,
          String portName,
          String protocol,
          String[] args,
          int argShift)
          throws Exception {
  
          String serviceNS = null;
          String serviceName = null;
          String portTypeNS = null;
          String portTypeName = null;
  
          if ("axis".equals(protocol)) {
              WSIFServiceImpl.setDynamicWSIFProvider(
                  "http://schemas.xmlsoap.org/wsdl/soap/";,
                  new WSIFDynamicProvider_ApacheAxis());
          }
  
          System.out.println("Reading WSDL document from '" + wsdlLocation + "'");
          Definition def = WSIFUtils.readWSDL(null, wsdlLocation);
  
          Service service = WSIFUtils.selectService(def, serviceNS, serviceName);
          PortType portType = WSIFUtils.selectPortType(def, portTypeNS, portTypeName);
  
          WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
          WSIFService dpf = factory.getService(def, service, portType);
          WSIFPort port = (portName == null) ? dpf.getPort() : dpf.getPort(portName);
  
          System.out.println("HeadersTest executing getQuote for \"\"" + 
operationName);
          WSIFOperation operation =
              port.createOperation("getQuote", inputName, outputName);
          WSIFMessage input = operation.createInputMessage();
          WSIFMessage output = operation.createOutputMessage();
          WSIFMessage fault = operation.createFaultMessage();
          input.setObjectPart("symbol", "");
  
          // set a basic authentication header
          WSIFMessage headers = new WSIFDefaultMessage();
          headers.setObjectPart(WSIFConstants.CONTEXT_HTTP_USER, "petra");
          headers.setObjectPart(WSIFConstants.CONTEXT_HTTP_PSWD, "washere");
          operation.setContext(headers);
  
          boolean ok = operation.executeRequestResponseOperation(input, output, fault);
          System.out.println("operation returned " + ok);
  
          float q = ((Float) output.getObjectPart("quote")).floatValue();
  
          if (q == -1.0F) {
              assertTrue(true);
          } else {
              assertTrue(false);
          }
  
          // do it agian without context so you can see the difference 
          System.out.println(
              "HeadersTest no headers executing getQuote for \"\"" + operationName);
          operation = port.createOperation("getQuote", inputName, outputName);
          input = operation.createInputMessage();
          output = operation.createOutputMessage();
          fault = operation.createFaultMessage();
          input.setObjectPart("symbol", "");
          ok = operation.executeRequestResponseOperation(input, output, fault);
          q = ((Float) output.getObjectPart("quote")).floatValue();
          if (q == -1.0F) {
              assertTrue(true);
          } else {
              assertTrue(false);
          }
  
          if ("axis".equals(protocol)) {
              WSIFServiceImpl.setDynamicWSIFProvider(
                  "http://schemas.xmlsoap.org/wsdl/soap/";,
                  null);
          }
  
      }
  
  }
  
  
  


Reply via email to