ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1748027 [2/2] - in /webservices/axiom/trunk: ./ apidocs/ axiom-all/ axiom-compat/src/main/java/org/apache/axiom/om/util/jaxb/ axiom-compat/src/main/java/org/apache/axiom/util/jaxb/ axiom-jaxb/ code-coverage/ distribution/ src/site/markdown...
Date Sun, 12 Jun 2016 16:27:16 GMT
Copied: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestGetNameFromPlainObject.java
(from r1747986, webservices/axiom/trunk/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestGetNameFromPlainObject.java?p2=webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestGetNameFromPlainObject.java&p1=webservices/axiom/trunk/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java&r1=1747986&r2=1748027&rev=1748027&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestGetNameFromPlainObject.java
Sun Jun 12 16:27:16 2016
@@ -16,162 +16,29 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axiom.om.ds.jaxb;
+package org.apache.axiom.ts.om.sourcedelement.jaxb;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import javax.activation.DataHandler;
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-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;
+import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMSourcedElement;
-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;
+import org.apache.axiom.om.ds.jaxb.JAXBOMDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.ts.jaxb.beans.DocumentBean;
 
-public class JAXBOMDataSourceTest {
-    /**
-     * Tests the expansion of an {@link OMSourcedElement} backed by a {@link JAXBOMDataSource}
with
-     * a bean that has a {@link DataHandler}. The expansion should result in an {@link OMText}
node
-     * linked to that {@link DataHandler}.
-     */
-    @Test
-    public void testDataHandlerExpansion() throws Exception {
-        OMFactory factory = OMAbstractFactory.getOMFactory();
-        JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
-        DataHandler dh = new DataHandler("some content", "text/plain");
-        DocumentBean object = new DocumentBean();
-        object.setId("123456");
-        object.setContent(dh);
-        OMElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
-        OMElement child = (OMElement)element.getFirstOMChild();
-        assertEquals("id", child.getLocalName());
-        assertEquals("123456", child.getText());
-        child = (OMElement)child.getNextOMSibling();
-        assertEquals("content", child.getLocalName());
-        OMText content = (OMText)child.getFirstOMChild();
-        assertTrue(content.isBinary());
-        assertTrue(content.isOptimized());
-        assertSame(dh, content.getDataHandler());
-    }
-    
-    /**
-     * Tests that an {@link OMSourcedElement} backed by a {@link JAXBOMDataSource} with a
bean
-     * containing a {@link DataHandler} is correctly serialized.
-     */
-    @Test
-    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);
-        
-        // Construct the original message
-        DocumentBean object = new DocumentBean();
-        object.setId("123456");
-        object.setContent(new DataHandler("some content", "text/plain; charset=utf-8"));
-        SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
-        OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context,
object));
-        orgEnvelope.getBody().addChild(element);
-        
-        // Serialize the message
-        OMOutputFormat format = new OMOutputFormat();
-        format.setDoOptimize(true);
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        orgEnvelope.serialize(out, format);
-        assertFalse(element.isExpanded());
-        
-        // Parse the serialized message
-        Attachments att = new Attachments(new ByteArrayInputStream(out.toByteArray()), format.getContentType());
-        assertEquals(2, att.getAllContentIDs().length);
-        SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(att).getSOAPEnvelope();
-        OMElement contentElement = envelope.getBody().getFirstElement().getFirstChildWithName(
-                new QName("http://ws.apache.org/axiom/test/jaxb", "content"));
-        OMText content = (OMText)contentElement.getFirstOMChild();
-        assertTrue(content.isBinary());
-        assertTrue(content.isOptimized());
-        DataHandler dh = content.getDataHandler();
-        assertEquals("some content", dh.getContent());
-    }
-    
-    /**
-     * 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.
+ */
+public class TestGetNameFromPlainObject extends AxiomTestCase {
+    public TestGetNameFromPlainObject(OMMetaFactory metaFactory) {
+        super(metaFactory);
     }
-    
-    /**
-     * 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.
-     */
-    @Test
-    public void testGetNameFromPlainObject() throws Exception {
-        OMFactory omFactory = OMAbstractFactory.getOMFactory();
+
+    @Override
+    protected void runTest() throws Throwable {
+        OMFactory omFactory = metaFactory.getOMFactory();
         JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
         OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context,
new DocumentBean()));
         assertEquals("http://ws.apache.org/axiom/test/jaxb", element.getNamespaceURI());
@@ -181,44 +48,4 @@ public class JAXBOMDataSourceTest {
         // provided by JAXBOMDataSource with the actual name of the element
         element.getFirstOMChild();
     }
-    
-    /**
-     * Tests that {@link JAXBOMDataSource} backed by a {@link JAXBElement} is able to determine
the
-     * namespace URI and local name of the element without expansion.
-     */
-    @Test
-    public void testGetNameFromJAXBElement() throws Exception {
-        OMFactory omFactory = OMAbstractFactory.getOMFactory();
-        ObjectFactory objectFactory = new ObjectFactory();
-        JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
-        JAXBElement<LinkIdentitiesType> jaxbElement = objectFactory.createLinkIdentities(new
LinkIdentitiesType());
-        OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context,
jaxbElement));
-        assertEquals("http://www.example.org/identity", element.getNamespaceURI());
-        assertEquals("LinkIdentities", element.getLocalName());
-        assertFalse(element.isExpanded());
-        // Force expansion so that OMSourcedElement compares the namespace URI and local
name
-        // provided by JAXBOMDataSource with the actual name of the element
-        element.getFirstOMChild();
-    }
-    
-    /**
-     * Tests that an {@link XMLStreamException} thrown by the {@link XMLStreamWriter} during
-     * serialization is propagated without being wrapped. Note that this implies that the
data must
-     * unwrap {@link JAXBException} to extract the cause.
-     */
-    @Test
-    public void testExceptionDuringSerialization() throws Exception {
-        OMFactory omFactory = OMAbstractFactory.getOMFactory();
-        JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
-        DocumentBean object = new DocumentBean();
-        object.setId("test");
-        OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context,
object));
-        XMLStreamException exception = new XMLStreamException("TEST");
-        try {
-            element.serialize(new ExceptionXMLStreamWriterWrapper(StAXUtils.createXMLStreamWriter(new
ByteArrayOutputStream()), exception));
-            fail("Expected XMLStreamException");
-        } catch (XMLStreamException ex) {
-            assertSame(exception, ex);
-        }
-    }
 }



Mime
View raw message