You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/07/29 15:27:07 UTC
svn commit: r1366849 - in
/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb: pom.xml
src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java
src/test/java/org/apache/axiom/om/ds/jaxb/beans/MyBean.java
Author: veithen
Date: Sun Jul 29 13:27:07 2012
New Revision: 1366849
URL: http://svn.apache.org/viewvc?rev=1366849&view=rev
Log:
Increased test coverage.
Added:
webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/MyBean.java (with props)
Modified:
webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/pom.xml
webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java
Modified: webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/pom.xml?rev=1366849&r1=1366848&r2=1366849&view=diff
==============================================================================
--- webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/pom.xml (original)
+++ webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/pom.xml Sun Jul 29 13:27:07 2012
@@ -62,6 +62,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
Modified: webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java?rev=1366849&r1=1366848&r2=1366849&view=diff
==============================================================================
--- webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java (original)
+++ webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java Sun Jul 29 13:27:07 2012
@@ -30,9 +30,11 @@ import javax.activation.DataHandler;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamWriter;
import org.apache.axiom.attachments.Attachments;
import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMDataSource;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMOutputFormat;
@@ -40,8 +42,11 @@ import org.apache.axiom.om.OMSourcedElem
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.ds.jaxb.beans.DocumentBean;
+import org.apache.axiom.om.ds.jaxb.beans.MyBean;
+import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
+import org.apache.commons.io.IOUtils;
import org.example.identity.LinkIdentitiesType;
import org.example.identity.ObjectFactory;
import org.junit.Test;
@@ -73,11 +78,40 @@ public class JAXBOMDataSourceTest {
}
/**
- * Tests that an {@link OMSourcedElement} backed by a {@link JAXBOMDataSource} is correctly
- * serialized to MTOM. The test uses a bean containing a {@link DataHandler}.
+ * Tests that an {@link OMSourcedElement} backed by a {@link JAXBOMDataSource} with a bean
+ * containing a {@link DataHandler} is correctly serialized.
*/
@Test
- public void testMTOM() throws Exception {
+ public void testDataHandlerSerializationWithoutMTOM() throws Exception{
+ SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+ JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
+
+ // Construct the original message
+ DocumentBean orgObject = new DocumentBean();
+ orgObject.setId("123456");
+ orgObject.setContent(new DataHandler("some content", "text/plain; charset=utf-8"));
+ SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
+ OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, orgObject));
+ orgEnvelope.getBody().addChild(element);
+
+ // Serialize the message
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ orgEnvelope.serialize(out);
+ assertFalse(element.isExpanded());
+
+ SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(
+ new ByteArrayInputStream(out.toByteArray()), null).getSOAPEnvelope();
+ DocumentBean object = (DocumentBean)context.createUnmarshaller().unmarshal(
+ envelope.getBody().getFirstElement().getXMLStreamReader(false));
+ assertEquals("some content", IOUtils.toString(object.getContent().getInputStream(), "utf-8"));
+ }
+
+ /**
+ * Tests that an {@link OMSourcedElement} backed by a {@link JAXBOMDataSource} with a bean
+ * containing a {@link DataHandler} is correctly serialized to MTOM.
+ */
+ @Test
+ public void testDataHandlerSerializationWithMTOM() throws Exception {
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
@@ -110,6 +144,25 @@ public class JAXBOMDataSourceTest {
}
/**
+ * Tests serialization using {@link OMDataSource#serialize(XMLStreamWriter)} to a standard
+ * {@link XMLStreamWriter}.
+ */
+ @Test
+ public void testSerializeDirect() throws Exception {
+ JAXBContext context = JAXBContext.newInstance(MyBean.class);
+ MyBean orgBean = new MyBean(3, 5);
+ JAXBOMDataSource ds = new JAXBOMDataSource(context, orgBean);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(out);
+ ds.serialize(writer);
+ writer.close();
+ MyBean bean = (MyBean)context.createUnmarshaller().unmarshal(
+ new ByteArrayInputStream(out.toByteArray()));
+ assertEquals(orgBean.getA(), bean.getA());
+ assertEquals(orgBean.getB(), bean.getB());
+ }
+
+ /**
* Tests that {@link JAXBOMDataSource} backed by a plain Java bean is able to determine the
* namespace URI and local name of the element without expansion.
*/
Added: webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/MyBean.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/MyBean.java?rev=1366849&view=auto
==============================================================================
--- webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/MyBean.java (added)
+++ webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/MyBean.java Sun Jul 29 13:27:07 2012
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+package org.apache.axiom.om.ds.jaxb.beans;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement(name="test")
+@XmlType(propOrder={ "a", "b" })
+public class MyBean {
+ private int a;
+ private int b;
+
+ public MyBean() {
+ }
+
+ public MyBean(int a, int b) {
+ this.a = a;
+ this.b = b;
+ }
+
+ public int getA() {
+ return a;
+ }
+
+ public void setA(int a) {
+ this.a = a;
+ }
+
+ public int getB() {
+ return b;
+ }
+
+ public void setB(int b) {
+ this.b = b;
+ }
+}
Propchange: webservices/axiom/branches/JAXB2_DS/modules/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/beans/MyBean.java
------------------------------------------------------------------------------
svn:eol-style = native