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/docStyle/wsifservice Mime.wsdl
Date Tue, 07 Jan 2003 17:39:46 GMT
antelder    2003/01/07 09:39:45

  Modified:    java/test/util WSIFTestRunner.java
               java/test/docStyle/wsifservice Mime.wsdl
  Added:       java/test/docStyle MessagingAttachmentsTest.java
  Removed:     java/test/docStyle MessagingRcvAttTest.java
  Log:
  New testcases for sending/recieving attachments when using messaging with the AXIS provider
  
  Revision  Changes    Path
  1.1                  xml-axis-wsif/java/test/docStyle/MessagingAttachmentsTest.java
  
  Index: MessagingAttachmentsTest.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 docStyle;
  
  import java.io.BufferedInputStream;
  import java.io.ByteArrayInputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.StringReader;
  import java.io.StringWriter;
  import java.util.Arrays;
  
  import javax.activation.DataHandler;
  import javax.activation.FileDataSource;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  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.xerces.parsers.DOMParser;
  import org.apache.xml.serialize.OutputFormat;
  import org.apache.xml.serialize.XMLSerializer;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.xml.sax.InputSource;
  import util.TestUtilities;
  
  /**
   * Junit test to test out the AXIS provider docstyle support
   */
  public class MessagingAttachmentsTest extends TestCase {
  	String wsdlLocation =
  		TestUtilities.getWsdlPath("java\\test\\docStyle\\wsifservice")
              + "mime.wsdl";
  
      private final static String IMAGE_LOCATION = 
          TestUtilities.getWsdlPath("java\\test\\mime")
          + "axis.jpg";
  
  	public MessagingAttachmentsTest(String name) {
  		super(name);
  	}
  
      public static void main(String[] args) {
  //        TestUtilities.startListeners(
  //            TestUtilities.ADDRESSBOOK_LISTENER
  //                | TestUtilities.ASYNC_LISTENER
  //                | TestUtilities.NATIVEJMS_LISTENER);
          junit.textui.TestRunner.run(suite());
  //        TestUtilities.stopListeners();
      }
  
  	public static Test suite() {
  		return new TestSuite(MessagingAttachmentsTest.class);
  	}
  
  	public void setUp() {
  		TestUtilities.setUpExtensionsAndProviders();
  	}
  
  	public void testMsgAxisRcvAtt() {
  		doitMsgRcvAtt("SOAPPort", "axis");
  	}
  	public void testMsgAxisSendAtt() {
  		doitMsgSendAtt("SOAPPort", "axis");
  	}
  
  	private void doitMsgRcvAtt(String portName, String protocol) {
  		if (portName.toUpperCase().indexOf("JMS") != -1
  			&& !TestUtilities.areWeTesting("jms"))
  			return;
  
  		TestUtilities.setProviderForProtocol(protocol);
  
  		try {
  			WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
  			WSIFService service =
  				factory.getService(
  					wsdlLocation,
  					null,
  					null,
                      "http://mime/",
                      "Mime");
  
  			WSIFPort port = service.getPort(portName);
  			WSIFOperation operation = port.createOperation("stringToDataHandler");
  			WSIFMessage inMsg = operation.createInputMessage();
  			WSIFMessage outMsg = operation.createOutputMessage();
  			WSIFMessage faultMsg = operation.createFaultMessage();
  
              String content = "The owl and the pussy cat went to sea in a beautiful pea-green
boat,";
  
              String inputDoc = 
                  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                  "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
+
                  " <soapenv:Body>" +
                  "    <ns1:stringToDataHandler soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"
xmlns:ns1=\"http://mime/\">" +
                  "       <ns1:buff xsi:type=\"xsd:string\">" + 
                  content + 
                  "</ns1:buff>" +
                  "    </ns1:stringToDataHandler>" +
                  " </soapenv:Body>" +
                  "</soapenv:Envelope>";            
  
  			DOMParser parser = new DOMParser();
  
  			parser.parse(new InputSource(new StringReader(inputDoc)));
  			Element element = parser.getDocument().getDocumentElement();
  			NodeList l = element.getChildNodes();
  			Element e1 = (Element)l.item(1);
  			l = e1.getChildNodes();
  			element = (Element)l.item(1);
  			Node n = e1.getFirstChild();
  			n = n.getNextSibling();
              element = (Element) n;
  //			printElement(element);
              			
  			inMsg.setObjectPart("buff", element);
  
  			boolean ok =
  				operation.executeRequestResponseOperation(
  					inMsg,
  					outMsg,
  					faultMsg);
  			assertTrue("operation returned false!!", ok);
  			
  			Object o = outMsg.getObjectPart("return");
              assertTrue(
                  "return part not a DataHandler!!",
                  (o instanceof DataHandler));
                  
              DataHandler dh = (DataHandler) o;
              assertTrue("response Datahandler content wrong!!", compareFiles(dh, content));
  
  		} catch (Exception ex) {
  			ex.printStackTrace();
  			assertTrue(
  				"AddressBookTest("
  					+ portName
  					+ ") caught exception "
  					+ ex.getLocalizedMessage(),
  				false);
  		}
  	}
  
  	private void doitMsgSendAtt(String portName, String protocol) {
  		if (portName.toUpperCase().indexOf("JMS") != -1
  			&& !TestUtilities.areWeTesting("jms"))
  			return;
  
  		TestUtilities.setProviderForProtocol(protocol);
  
  		try {
  			WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
  			WSIFService service =
  				factory.getService(
  					wsdlLocation,
  					null,
  					null,
                      "http://mime/",
                      "Mime");
  
  			WSIFPort port = service.getPort(portName);
  			WSIFOperation operation = port.createOperation("bounceImage4");
  			WSIFMessage inMsg = operation.createInputMessage();
  			WSIFMessage outMsg = operation.createOutputMessage();
  			WSIFMessage faultMsg = operation.createFaultMessage();
  
              String inputDoc = 
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                    "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
+
                    " <soapenv:Body>" +
                    "  <ns1:bounceImage4 soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"
xmlns:ns1=\"http://mime/\">" +
                    "   <ns1:shouldBounce xsi:type=\"xsd:boolean\">true</ns1:shouldBounce>"
+
                    "   <ns1:file href=\"cid:413B07CE410E48EB9D89DC0A4DDD715D\"/>" +
                    "  </ns1:bounceImage4>" +
                    " </soapenv:Body>" +
                    "</soapenv:Envelope>";
  
  			DOMParser parser = new DOMParser();
  
  			parser.parse(new InputSource(new StringReader(inputDoc)));
  			Element element = parser.getDocument().getDocumentElement();
  			NodeList l = element.getChildNodes();
  			Element e1 = (Element)l.item(1);
  			l = e1.getChildNodes();
  			element = (Element)l.item(1);
  			Node n = e1.getFirstChild();
  			n = n.getNextSibling();
              element = (Element) n;
  //			printElement(element);
              			
  			inMsg.setObjectPart("shouldBounce", element);
  			
              DataHandler dh1 = new DataHandler(new FileDataSource(IMAGE_LOCATION));
  			inMsg.setObjectPart("file", dh1);
  
  			boolean ok =
  				operation.executeRequestResponseOperation(
  					inMsg,
  					outMsg,
  					faultMsg);
  			assertTrue("operation returned false!!", ok);
  			
  			Object o = outMsg.getObjectPart("return");
              assertTrue(
                  "return part not a DataHandler!!",
                  (o instanceof DataHandler));
                  
              DataHandler dhResponse = (DataHandler) o;
              assertTrue("response Datahandler content wrong!!", compareFiles(dhResponse,
dh1));
  
  		} catch (Exception ex) {
  			ex.printStackTrace();
  			assertTrue(
  				"AddressBookTest("
  					+ portName
  					+ ") caught exception "
  					+ ex.getLocalizedMessage(),
  				false);
  		}
  	}
  
  	private void printElement(Element e) throws Exception {
  		OutputFormat of = new OutputFormat(e.getOwnerDocument(), "UTF-8", true);
  		XMLSerializer xmls = new XMLSerializer(of);
  		StringWriter sw = new StringWriter();
  		xmls.setOutputCharStream(sw);
  		xmls.serialize(e);
  		System.err.println("element=" + sw.toString());
  	}
  
      private boolean compareFiles(DataHandler dh1, DataHandler dh2)
          throws FileNotFoundException, IOException {
          InputStream is1 = dh1.getInputStream();
          InputStream is2 = dh2.getInputStream();
          boolean success = false;
          try {
              success = compareFiles(is1, is2);
          } finally {
              if (null != is1)
                  is1.close();
              if (null != is2)
                  is2.close();
          }
          return success;
      }
  
      private boolean compareFiles(DataHandler dh, String buff)
          throws FileNotFoundException, IOException {
          InputStream is = dh.getInputStream();
          boolean success = false;
          try {
              success = compareFiles(is, buff);
          } finally {
              if (null != is)
                  is.close();
          }
          return success;
      }
  
      private boolean compareFiles(String one, String buff)
          throws FileNotFoundException, IOException {
          BufferedInputStream oneStream = null;
          File f1 = new File(one);
  
          boolean success = false;
          try {
              oneStream =
                  new BufferedInputStream(
                      new FileInputStream(one),
                      buff.length());
              success = compareFiles(oneStream, buff);
          } finally {
              if (null != oneStream)
                  oneStream.close();
          }
          return success;
      }
  
      private boolean compareFiles(InputStream is, String buff)
          throws FileNotFoundException, IOException {
          return compareFiles(is, new ByteArrayInputStream(buff.getBytes()));
      }
      
      private boolean compareFiles(InputStream is1, InputStream is2) 
          throws FileNotFoundException, IOException {
  
          int avail1 = is1.available();
          int avail2 = is2.available();
          if (avail1 != avail2) return false;
          if (avail1==0) return true;
  
          byte[] buff1 = new byte[avail1];
          byte[] buff2 = new byte[avail2];
  
          Arrays.fill(buff1, (byte) 0);
          Arrays.fill(buff2, (byte) 0);
  
          int bread1 = -1;
          int bread2 = -1;
          bread1 = is1.read(buff1, 0, avail1);
          bread2 = is2.read(buff2, 0, avail2);
          String s1 = new String(buff1);
          String s2 = new String(buff2);
          if (!s1.equals(s2))
              return false;
          return true;
      }
      
      private String concat(String one, String two)
          throws FileNotFoundException, IOException {
          InputStream is1 = null;
          InputStream is2 = null;
          try {
              is1 = (new DataHandler(new FileDataSource(one))).getInputStream();
              is2 = (new DataHandler(new FileDataSource(two))).getInputStream();
              int avail1 = is1.available();
              int avail2 = is2.available();
  
              byte[] buff1 = new byte[avail1];
              byte[] buff2 = new byte[avail2];
  
              Arrays.fill(buff1, (byte) 0);
              Arrays.fill(buff2, (byte) 0);
  
              int bread1 = -1;
              int bread2 = -1;
              bread1 = is1.read(buff1, 0, avail1);
              bread2 = is2.read(buff2, 0, avail2);
              String s1 = new String(buff1);
              String s2 = new String(buff2);
              return s1 + s2;
  
          } finally {
              if (null != is1)
                  is1.close();
              if (null != is2)
                  is2.close();
          }
      }
  
  }
  
  
  
  1.29      +2 -2      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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- WSIFTestRunner.java	7 Jan 2003 12:18:37 -0000	1.28
  +++ WSIFTestRunner.java	7 Jan 2003 17:39:45 -0000	1.29
  @@ -84,7 +84,7 @@
   
   import addressbook.AddressBookTest;
   import async.AsyncTests;
  -import docStyle.MessagingRcvAttTest;
  +import docStyle.MessagingAttachmentsTest;
   import docStyle.NWBankTest;
   import docStyle.ZipCodeAxisTest;
   
  @@ -138,7 +138,7 @@
           suite.addTest(new TestSuite(NWBankTest.class));
           suite.addTest(new TestSuite(InteropDocTest.class));
           suite.addTest(new TestSuite(InteropDocWrappedTest.class));
  -        suite.addTest(new TestSuite(MessagingRcvAttTest.class));
  +        suite.addTest(new TestSuite(MessagingAttachmentsTest.class));
   
           if (TestUtilities.areWeTesting("mime"))
               suite.addTest(new TestSuite(MimeTest.class));
  
  
  
  1.2       +3 -3      xml-axis-wsif/java/test/docStyle/wsifservice/Mime.wsdl
  
  Index: Mime.wsdl
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/docStyle/wsifservice/Mime.wsdl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Mime.wsdl	7 Jan 2003 12:18:37 -0000	1.1
  +++ Mime.wsdl	7 Jan 2003 17:39:45 -0000	1.2
  @@ -34,7 +34,7 @@
     </message>
   
     <message name="DataHandler2Message">
  -    <part name="file2" type="tns:datahandler"/>
  +    <part name="return" type="tns:datahandler"/>
     </message>
   
     <message name="PlainTextMessage">
  @@ -58,8 +58,8 @@
     </message>
   
     <message name="BounceImage4Message">
  -    <part name="file" type="tns:datahandler"/>
       <part name="shouldBounce" type="xsd:boolean"/>
  +    <part name="file" type="tns:datahandler"/>
     </message>
   
     <message name="MultiMimePartsMessage">
  @@ -274,7 +274,7 @@
         <output>
           <mime:multipartRelated>
             <mime:part>
  -            <mime:content part="file2" type="image/jpeg"/>
  +            <mime:content part="return" type="image/jpeg"/>
             </mime:part>
           </mime:multipartRelated> 
         </output>
  
  
  

Mime
View raw message