You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by th...@apache.org on 2005/06/28 06:10:00 UTC
svn commit: r202123 - in /webservices/axis/trunk/java/modules/xml: ./
test/org/apache/axis/attachments/ test/org/apache/axis/om/impl/llom/
test/org/apache/axis/om/impl/llom/mtom/
Author: thilina
Date: Mon Jun 27 21:09:58 2005
New Revision: 202123
URL: http://svn.apache.org/viewcvs?rev=202123&view=rev
Log:
Attachments & MTOM Testcases.
Tests that need JavaMail & Activation are excluded
Added:
webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/
webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/Base64Test.java
webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/ImageSampleTest.java
webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/MIMEHelperTest.java
webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/
webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/OMOutputTest.java
webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/mtom/
webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/mtom/MTOMStAXSOAPModelBuilderTest.java
Modified:
webservices/axis/trunk/java/modules/xml/project.xml
Modified: webservices/axis/trunk/java/modules/xml/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/project.xml?rev=202123&r1=202122&r2=202123&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/project.xml (original)
+++ webservices/axis/trunk/java/modules/xml/project.xml Mon Jun 27 21:09:58 2005
@@ -30,46 +30,34 @@
<sourceDirectory>src</sourceDirectory>
<unitTestSourceDirectory>test</unitTestSourceDirectory>
- <sourceModifications>
- <sourceModification>
- <className>javax.activation.DataHandler</className>
- <excludes>
- <exclude>**/mtom/**.java</exclude>
- </excludes>
- </sourceModification>
- <sourceModification>
- <className>javax.mail.internet.MimeMessage</className>
- <excludes>
- <exclude>**/mtom/**.java</exclude>
- </excludes>
- </sourceModification>
- </sourceModifications>
-
-
-
<unitTest>
- <includes>
- <include>**/*Test.java</include>
- </includes>
+ <excludes>
+ <exclude>**/*OMOutputTest.java</exclude>
+ <exclude>**/*MTOMStAXSOAPModelBuilderTest.java</exclude>
+ <exclude>**/*ImageSampleTest.java</exclude>
+ </excludes>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
- <resources>
- <resource>
- <directory>${basedir}/test-resources</directory>
- </resource>
- <resource>
+ <resources>
+ <resource>
+ <directory>${basedir}/test-resources</directory>
+ </resource>
+ <resource>
<directory>conf</directory>
- <includes>
+ <includes>
<include>**/*.properties</include>
</includes>
- </resource>
- <resource>
- <directory>src</directory>
- <includes>
- <include>**/*.properties</include>
- <include>**/*.xml</include>
- </includes>
- </resource>
- </resources>
+ </resource>
+ <resource>
+ <directory>src</directory>
+ <includes>
+ <include>**/*.properties</include>
+ <include>**/*.xml</include>
+ </includes>
+ </resource>
+ </resources>
</unitTest>
<resources>
Added: webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/Base64Test.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/Base64Test.java?rev=202123&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/Base64Test.java (added)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/Base64Test.java Mon Jun 27 21:09:58 2005
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+package org.apache.axis.attachments;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
+ */
+public class Base64Test extends TestCase {
+
+ Object expectedObject;
+
+ ByteArrayInputStream byteStream;
+
+ /*
+ * Class under test for String encode(byte[])
+ */
+
+ public void testEncodebyteArray() throws Exception {
+ Object actualObject;
+ String expectedBase64;
+ expectedObject = new String("Lanka Software Foundation");
+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectOutStream = new ObjectOutputStream(byteStream);
+ objectOutStream.writeObject(expectedObject);
+ expectedBase64 = Base64.encode(byteStream.toByteArray());
+ byte[] tempa = Base64.decode(expectedBase64);
+ ObjectInputStream objectInStream = new ObjectInputStream(
+ new ByteArrayInputStream(tempa));
+ actualObject = objectInStream.readObject();
+ assertEquals("Base64 Encoding Check", expectedObject, actualObject);
+ }
+}
\ No newline at end of file
Added: webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/ImageSampleTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/ImageSampleTest.java?rev=202123&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/ImageSampleTest.java (added)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/ImageSampleTest.java Mon Jun 27 21:09:58 2005
@@ -0,0 +1,158 @@
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+package org.apache.axis.attachments;
+
+import java.awt.Image;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import javax.activation.DataHandler;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axis.om.AbstractTestCase;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMText;
+import org.apache.axis.om.impl.llom.OMElementImpl;
+import org.apache.axis.om.impl.llom.OMNamespaceImpl;
+import org.apache.axis.om.impl.llom.OMOutput;
+import org.apache.axis.om.impl.llom.OMTextImpl;
+import org.apache.axis.om.impl.llom.mtom.MTOMStAXSOAPModelBuilder;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
+ */
+
+public class ImageSampleTest extends AbstractTestCase {
+
+ public ImageSampleTest(String testName) {
+ super(testName);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ Image expectedImage;
+
+ MTOMStAXSOAPModelBuilder builder;
+
+ DataHandler expectedDH;
+
+ File outMTOMFile;
+
+ File outBase64File;
+
+ String outFileName = "mtom/OMSerializeMTOMOut.txt";
+
+ String outBase64FileName = "mtom/OMSerializeBase64Out.xml";
+
+ String imageInFileName = "mtom/img/Waterlilies.jpg";
+
+ String imageOutFileName = "mtom/img/WaterliliesOut.jpg";
+
+ String inMimeFileName = "mtom/ImageMTOMOut.bin";
+
+ String contentTypeString = "multipart/Related; type=\"application/xop+xml\";start=\"<http://example.org/my.hsh>\"; boundary=\"----=_Part_0_2628939.1119398330392\"";
+
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ }
+
+ public void testImageSampleSerialize() throws Exception {
+
+ outMTOMFile = getTestResourceFile(outFileName);
+ outBase64File = getTestResourceFile(outBase64FileName);
+ OMOutput mtomOutput = new OMOutput(new FileOutputStream(outMTOMFile),true);
+ OMOutput baseOutput = new OMOutput(new FileOutputStream(outBase64File),false);
+
+ OMNamespaceImpl soap = new OMNamespaceImpl(
+ "http://schemas.xmlsoap.org/soap/envelope/", "soap");
+ OMElement envelope = new OMElementImpl("Envelope", soap);
+ OMElement body = new OMElementImpl("Body", soap);
+
+ OMNamespaceImpl dataName = new OMNamespaceImpl(
+ "http://www.example.org/stuff", "m");
+ OMElement data = new OMElementImpl("data", dataName);
+
+ expectedImage = new JDK13IO().loadImage(new FileInputStream(
+ getTestResourceFile(imageInFileName)));
+ ImageDataSource dataSource = new ImageDataSource("WaterLilies.jpg",
+ expectedImage);
+ expectedDH = new DataHandler(dataSource);
+ OMText binaryNode = new OMTextImpl(expectedDH);
+
+ envelope.addChild(body);
+ body.addChild(data);
+ data.addChild(binaryNode);
+
+ envelope.serialize(baseOutput);
+ baseOutput.flush();
+
+ envelope.serialize(mtomOutput);
+ mtomOutput.flush();
+ mtomOutput.complete();
+ }
+
+ public void testImageSampleDeserialize() throws Exception {
+ InputStream inStream = new FileInputStream(
+ getTestResourceFile(inMimeFileName));
+ MIMEHelper mimeHelper = new MIMEHelper(inStream, contentTypeString);
+ XMLStreamReader reader = XMLInputFactory.newInstance()
+ .createXMLStreamReader(
+ new BufferedReader(new InputStreamReader(mimeHelper
+ .getSOAPPartInputStream())));
+ builder = new MTOMStAXSOAPModelBuilder(reader, mimeHelper);
+ OMElement root = (OMElement) builder.getDocumentElement();
+ // System.out.println(root.getLocalName() + " : "
+ // + root.getNamespaceName());
+ OMElement body = (OMElement) root.getFirstChild();
+ // System.out.println(body.getLocalName() + " : "
+ // + body.getNamespaceName());
+ OMElement data = (OMElement) body.getFirstChild();
+ // System.out.println(data.getLocalName() + " : "
+ // + data.getNamespaceName());
+
+ OMText blob = (OMText) data.getFirstChild();
+ /*
+ * Following is the procedure the user has to follow to read objects in
+ * OBBlob User has to know the object type & whether it is serializable.
+ * If it is not he has to use a Custom Defined DataSource to get the
+ * Object.
+ */
+
+ DataHandler actualDH;
+ actualDH = blob.getDataHandler();
+ Image actualObject = new JDK13IO().loadImage(actualDH.getDataSource()
+ .getInputStream());
+ FileOutputStream imageOutStream = new FileOutputStream(
+ getTestResourceFile(imageOutFileName));
+ new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream);
+
+ System.out.println(data.getLocalName() + ":-\t" + actualObject);
+
+ }
+
+}
\ No newline at end of file
Added: webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/MIMEHelperTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/MIMEHelperTest.java?rev=202123&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/MIMEHelperTest.java (added)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis/attachments/MIMEHelperTest.java Mon Jun 27 21:09:58 2005
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+package org.apache.axis.attachments;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
+ */
+
+public class MIMEHelperTest extends TestCase {
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testMIMEHelper() {
+ }
+
+ public void testGetAttachmentSpecType() {
+ }
+
+ public void testGetSOAPPartInputStream() {
+ }
+
+ public void testGetDataHandler() {
+ }
+
+}
\ No newline at end of file
Added: webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/OMOutputTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/OMOutputTest.java?rev=202123&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/OMOutputTest.java (added)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/OMOutputTest.java Mon Jun 27 21:09:58 2005
@@ -0,0 +1,119 @@
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+package org.apache.axis.om.impl.llom;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import javax.activation.DataHandler;
+
+import org.apache.axis.attachments.ByteArrayDataSource;
+import org.apache.axis.om.AbstractTestCase;
+import org.apache.axis.om.OMAttribute;
+import org.apache.axis.om.OMElement;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
+ */
+
+public class OMOutputTest extends AbstractTestCase {
+
+ /**
+ * @param testName
+ */
+ public OMOutputTest(String testName) {
+ super(testName);
+ }
+
+ String outFileName;
+
+ String outBase64FileName;
+
+ OMElement envelope;
+
+ File outMTOMFile;
+
+ File outBase64File;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ Object object;
+ DataHandler dataHandler;
+
+ outFileName = "mtom/OMSerializeMTOMOut.txt";
+ outBase64FileName = "mtom/OMSerializeBase64Out.xml";
+ outMTOMFile = getTestResourceFile(outFileName);
+ outBase64File = getTestResourceFile(outBase64FileName);
+
+ OMNamespaceImpl soap = new OMNamespaceImpl(
+ "http://schemas.xmlsoap.org/soap/envelope/", "soap");
+ envelope = new OMElementImpl("Envelope", soap);
+ OMElement body = new OMElementImpl("Body", soap);
+
+ OMNamespaceImpl dataName = new OMNamespaceImpl(
+ "http://www.example.org/stuff", "m");
+ OMElement data = new OMElementImpl("data", dataName);
+
+ OMNamespaceImpl mime = new OMNamespaceImpl(
+ "http://www.w3.org/2003/06/xmlmime", "m");
+
+ OMElement text = new OMElementImpl("name", dataName);
+ OMAttribute cType1 = new OMAttributeImpl("contentType", mime,
+ "text/plain");
+ text.addAttribute(cType1);
+ byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1,
+ 98 };
+ dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));
+ OMTextImpl textData = new OMTextImpl(dataHandler);
+
+ envelope.addChild(body);
+ body.addChild(data);
+ data.addChild(text);
+ text.addChild(textData);
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (this.outMTOMFile.exists()) {
+ this.outMTOMFile.delete();
+ }
+ if (this.outBase64File.exists()) {
+ this.outBase64File.delete();
+ }
+ }
+
+ public void testComplete() throws Exception {
+
+ OMOutput mtomOutput = new OMOutput(new FileOutputStream(
+ outMTOMFile), true);
+ OMOutput baseOutput = new OMOutput(new FileOutputStream(
+ outBase64File), false);
+
+ envelope.serialize(baseOutput);
+ baseOutput.flush();
+
+ envelope.serialize(mtomOutput);
+
+ mtomOutput.complete();
+ }
+}
\ No newline at end of file
Added: webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/mtom/MTOMStAXSOAPModelBuilderTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/mtom/MTOMStAXSOAPModelBuilderTest.java?rev=202123&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/mtom/MTOMStAXSOAPModelBuilderTest.java (added)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis/om/impl/llom/mtom/MTOMStAXSOAPModelBuilderTest.java Mon Jun 27 21:09:58 2005
@@ -0,0 +1,105 @@
+/**
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ * <p/>
+ */
+package org.apache.axis.om.impl.llom.mtom;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axis.attachments.MIMEHelper;
+import org.apache.axis.om.AbstractTestCase;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMText;
+import org.apache.axis.om.OMXMLParserWrapper;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
+ */
+
+public class MTOMStAXSOAPModelBuilderTest extends AbstractTestCase {
+ MIMEHelper mimeHelper;
+
+ String inFileName;
+
+ OMXMLParserWrapper builder;
+
+ /**
+ * @param testName
+ */
+ public MTOMStAXSOAPModelBuilderTest(String testName) {
+ super(testName);
+ }
+
+ String contentTypeString = "multipart/Related; type=\"application/xop+xml\"; boundary=\"----=_Part_0_9971081.1119397256753\"; start=\"<SOAP part>\"";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ inFileName = "mtom/MTOMBuilderTestIn.txt";
+ InputStream inStream = new FileInputStream(
+ getTestResourceFile(inFileName));
+ mimeHelper = new MIMEHelper(inStream, contentTypeString);
+ XMLStreamReader reader = XMLInputFactory.newInstance()
+ .createXMLStreamReader(
+ new BufferedReader(new InputStreamReader(mimeHelper
+ .getSOAPPartInputStream())));
+ builder = new MTOMStAXSOAPModelBuilder(reader, mimeHelper);
+
+ }
+
+ public void testCreateOMElement() throws Exception {
+ OMElement root = (OMElement) builder.getDocumentElement();
+ System.out.println(root.getLocalName() + " : "
+ + root.getNamespace().getName());
+ OMElement body = (OMElement) root.getFirstChild();
+ System.out.println(body.getLocalName() + " : "
+ + body.getNamespace().getName());
+ OMElement data = (OMElement) body.getFirstChild();
+ System.out.println(data.getLocalName() + " : "
+ + data.getNamespace().getName());
+ Iterator childIt = data.getChildren();
+ //while (childIt.hasNext()) {
+ OMElement child = (OMElement) childIt.next();
+ OMText blob = (OMText) child.getFirstChild();
+ /*
+ * Following is the procedure the user has to follow to read objects in
+ * OBBlob User has to know the object type & whether it is serializable.
+ * If it is not he has to use a Custom Defined DataSource to get the
+ * Object.
+ */
+ byte[] expectedObject = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2,
+ -1, 98 };
+ DataHandler actualDH;
+ actualDH = blob.getDataHandler();
+ ByteArrayInputStream object = (ByteArrayInputStream) actualDH
+ .getContent();
+ //byte[] actualObject= null;
+ // object.read(actualObject,0,10);
+
+ // assertEquals("Object check", expectedObject[5],actualObject[5] );
+ }
+
+ public void testGetDataHandler() {
+ }
+
+}
\ No newline at end of file