AXIOM-506: Move tests for JAXBOMDataSource and JAXBUtils to axiom-jaxb
diff --git a/axiom-jaxb/pom.xml b/axiom-jaxb/pom.xml
index 43370d4..d65e046 100644
--- a/axiom-jaxb/pom.xml
+++ b/axiom-jaxb/pom.xml
@@ -48,6 +48,39 @@
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testutils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>blob-testutils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axiom-impl</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jaxb</groupId>
+ <artifactId>jaxb-runtime</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -58,6 +91,22 @@
<extensions>true</extensions>
</plugin>
<plugin>
+ <groupId>com.github.veithen.maven</groupId>
+ <artifactId>xjc-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-test-sources</goal>
+ </goals>
+ <configuration>
+ <files>
+ <file>src/test/schema/identity.xsd</file>
+ </files>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<executions>
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/jaxb/beans/DocumentBean.java b/axiom-jaxb/src/test/java/org/apache/axiom/jaxb/DocumentBean.java
similarity index 96%
rename from testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/jaxb/beans/DocumentBean.java
rename to axiom-jaxb/src/test/java/org/apache/axiom/jaxb/DocumentBean.java
index 1326992..0bec79f 100644
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/jaxb/beans/DocumentBean.java
+++ b/axiom-jaxb/src/test/java/org/apache/axiom/jaxb/DocumentBean.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.axiom.ts.jaxb.beans;
+package org.apache.axiom.jaxb;
import javax.activation.DataHandler;
import javax.xml.bind.annotation.XmlRootElement;
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/jaxb/beans/DocumentBean2.java b/axiom-jaxb/src/test/java/org/apache/axiom/jaxb/DocumentBean2.java
similarity index 96%
rename from testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/jaxb/beans/DocumentBean2.java
rename to axiom-jaxb/src/test/java/org/apache/axiom/jaxb/DocumentBean2.java
index 8a7e042..e5cf5c9 100644
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/jaxb/beans/DocumentBean2.java
+++ b/axiom-jaxb/src/test/java/org/apache/axiom/jaxb/DocumentBean2.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.axiom.ts.jaxb.beans;
+package org.apache.axiom.jaxb;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/jaxb/beans/package-info.java b/axiom-jaxb/src/test/java/org/apache/axiom/jaxb/package-info.java
similarity index 95%
rename from testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/jaxb/beans/package-info.java
rename to axiom-jaxb/src/test/java/org/apache/axiom/jaxb/package-info.java
index bd91b88..5c0f78b 100644
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/jaxb/beans/package-info.java
+++ b/axiom-jaxb/src/test/java/org/apache/axiom/jaxb/package-info.java
@@ -19,4 +19,4 @@
@javax.xml.bind.annotation.XmlSchema(
namespace = "http://ws.apache.org/axiom/test/jaxb",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
-package org.apache.axiom.ts.jaxb.beans;
+package org.apache.axiom.jaxb;
diff --git a/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/custombuilder/CustomBuilderSupportTest.java b/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/custombuilder/CustomBuilderSupportTest.java
new file mode 100644
index 0000000..4f373e1
--- /dev/null
+++ b/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/custombuilder/CustomBuilderSupportTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.custombuilder;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.OutputStream;
+
+import javax.activation.DataHandler;
+import javax.xml.bind.JAXBContext;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.blob.Blobs;
+import org.apache.axiom.blob.MemoryBlob;
+import org.apache.axiom.mime.MultipartBody;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.util.StAXParserConfiguration;
+import org.apache.axiom.testutils.activation.TestDataSource;
+import org.apache.axiom.testutils.blob.RandomBlob;
+import org.apache.axiom.testutils.io.IOTestUtils;
+import org.apache.axiom.util.activation.DataHandlerUtils;
+import org.junit.jupiter.api.Test;
+
+public class CustomBuilderSupportTest {
+ private OMElement createTestDocument(DataHandler dh) {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMElement document = factory.createOMElement(new QName("urn:test", "document"));
+ OMElement name = factory.createOMElement(new QName("name"));
+ name.setText("some name");
+ document.addChild(name);
+ OMElement content = factory.createOMElement(new QName("content"));
+ content.addChild(factory.createOMText(DataHandlerUtils.toBlob(dh), true));
+ document.addChild(content);
+ return document;
+ }
+
+ private void test(DataHandler dh, OMXMLParserWrapper builder, boolean same) throws Exception {
+ JAXBCustomBuilder customBuilder =
+ new JAXBCustomBuilder(JAXBContext.newInstance(MyDocument.class));
+ ((CustomBuilderSupport) builder)
+ .registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, customBuilder);
+ builder.getDocumentElement().build();
+ MyDocument myDocument = (MyDocument) customBuilder.getJaxbObject();
+ if (same) {
+ assertThat(myDocument.getContent()).isSameAs(dh);
+ } else {
+ assertThat(myDocument.getContent()).isNotSameAs(dh);
+ IOTestUtils.compareStreams(
+ dh.getInputStream(),
+ "expected",
+ myDocument.getContent().getInputStream(),
+ "actual");
+ }
+ }
+
+ @Test
+ public void testRegisterCustomBuilderForPayloadJAXBPlain() throws Exception {
+ DataHandler dh = DataHandlerUtils.toDataHandler(new RandomBlob(10000));
+ MemoryBlob blob = Blobs.createMemoryBlob();
+ OutputStream out = blob.getOutputStream();
+ createTestDocument(dh).serialize(out);
+ out.close();
+ test(dh, OMXMLBuilderFactory.createOMBuilder(blob.getInputStream()), false);
+ }
+
+ @Test
+ public void testRegisterCustomBuilderForPayloadJAXBWithDataHandlerReaderExtension()
+ throws Exception {
+ DataHandler dh = new DataHandler(new TestDataSource('X', Integer.MAX_VALUE));
+ OMElement document = createTestDocument(dh);
+ test(dh, OMXMLBuilderFactory.createStAXOMBuilder(document.getXMLStreamReader()), true);
+ }
+
+ @Test
+ public void testRegisterCustomBuilderForPayloadJAXBWithXOP() throws Exception {
+ DataHandler dh = DataHandlerUtils.toDataHandler(new RandomBlob(10000));
+ MemoryBlob blob = Blobs.createMemoryBlob();
+ OutputStream out = blob.getOutputStream();
+ OMOutputFormat format = new OMOutputFormat();
+ format.setDoOptimize(true);
+ createTestDocument(dh).serialize(out, format);
+ out.close();
+ MultipartBody mb =
+ MultipartBody.builder()
+ .setInputStream(blob.getInputStream())
+ .setContentType(format.getContentType())
+ .build();
+ test(dh, OMXMLBuilderFactory.createOMBuilder(StAXParserConfiguration.DEFAULT, mb), false);
+ }
+}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/JAXBCustomBuilder.java b/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/custombuilder/JAXBCustomBuilder.java
similarity index 94%
rename from testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/JAXBCustomBuilder.java
rename to axiom-jaxb/src/test/java/org/apache/axiom/om/ds/custombuilder/JAXBCustomBuilder.java
index eb9a5da..14ddded 100644
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/JAXBCustomBuilder.java
+++ b/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/custombuilder/JAXBCustomBuilder.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.axiom.ts.om.builder;
+package org.apache.axiom.om.ds.custombuilder;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@@ -25,7 +25,6 @@
import org.apache.axiom.om.OMDataSource;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.ds.custombuilder.CustomBuilder;
import org.apache.axiom.om.ds.jaxb.JAXBOMDataSource;
import org.apache.axiom.om.util.jaxb.JAXBUtils;
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/MyDocument.java b/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/custombuilder/MyDocument.java
similarity index 96%
rename from testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/MyDocument.java
rename to axiom-jaxb/src/test/java/org/apache/axiom/om/ds/custombuilder/MyDocument.java
index 2cc70c7..cb83cf0 100644
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/MyDocument.java
+++ b/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/custombuilder/MyDocument.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.axiom.ts.om.builder;
+package org.apache.axiom.om.ds.custombuilder;
import javax.activation.DataHandler;
import javax.xml.bind.annotation.XmlRootElement;
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/ExceptionXMLStreamWriterWrapper.java b/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/ExceptionXMLStreamWriterWrapper.java
similarity index 95%
rename from testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/ExceptionXMLStreamWriterWrapper.java
rename to axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/ExceptionXMLStreamWriterWrapper.java
index aa9698a..1104ff7 100644
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/ExceptionXMLStreamWriterWrapper.java
+++ b/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/ExceptionXMLStreamWriterWrapper.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.axiom.ts.om.sourcedelement.jaxb;
+package org.apache.axiom.om.ds.jaxb;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
diff --git a/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java b/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java
new file mode 100644
index 0000000..746e732
--- /dev/null
+++ b/axiom-jaxb/src/test/java/org/apache/axiom/om/ds/jaxb/JAXBOMDataSourceTest.java
@@ -0,0 +1,227 @@
+/*
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataHandler;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.blob.Blob;
+import org.apache.axiom.blob.Blobs;
+import org.apache.axiom.blob.MemoryBlob;
+import org.apache.axiom.core.stream.stax.StAX;
+import org.apache.axiom.jaxb.DocumentBean;
+import org.apache.axiom.mime.MultipartBody;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.testutils.activation.TextDataSource;
+import org.apache.axiom.util.activation.DataHandlerUtils;
+import org.apache.commons.io.IOUtils;
+import org.junit.jupiter.api.Test;
+import org.example.identity.LinkIdentitiesType;
+import org.example.identity.ObjectFactory;
+
+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();
+ assertThat(child.getLocalName()).isEqualTo("id");
+ assertThat(child.getText()).isEqualTo("123456");
+ child = (OMElement) child.getNextOMSibling();
+ assertThat(child.getLocalName()).isEqualTo("content");
+ OMText content = (OMText) child.getFirstOMChild();
+ assertThat(content.isBinary()).isTrue();
+ assertThat(content.isOptimized()).isTrue();
+ assertThat(DataHandlerUtils.toDataHandler(content.getBlob())).isSameAs(dh);
+ }
+
+ /**
+ * 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(new TextDataSource("some content", "utf-8", "plain")));
+ 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);
+ MemoryBlob mtom = Blobs.createMemoryBlob();
+ OutputStream out = mtom.getOutputStream();
+ orgEnvelope.serialize(out, format);
+ out.close();
+ assertThat(element.isExpanded()).isFalse();
+
+ // Parse the serialized message
+ MultipartBody mb =
+ MultipartBody.builder()
+ .setInputStream(mtom.getInputStream())
+ .setContentType(format.getContentType())
+ .build();
+ assertThat(mb.getPartCount()).isEqualTo(2);
+ SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(mb).getSOAPEnvelope();
+ OMElement contentElement =
+ envelope.getBody()
+ .getFirstElement()
+ .getFirstChildWithName(
+ new QName("http://ws.apache.org/axiom/test/jaxb", "content"));
+ OMText content = (OMText) contentElement.getFirstOMChild();
+ assertThat(content.isBinary()).isTrue();
+ assertThat(content.isOptimized()).isTrue();
+ Blob blob = content.getBlob();
+ assertThat(IOUtils.toString(blob.getInputStream(), "utf-8")).isEqualTo("some content");
+ }
+
+ /**
+ * 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(new TextDataSource("some content", "utf-8", "plain")));
+ 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);
+ assertThat(element.isExpanded()).isFalse();
+
+ SOAPEnvelope envelope =
+ OMXMLBuilderFactory.createSOAPModelBuilder(
+ new ByteArrayInputStream(out.toByteArray()), null)
+ .getSOAPEnvelope();
+ DocumentBean object =
+ (DocumentBean)
+ context.createUnmarshaller()
+ .unmarshal(
+ envelope.getBody()
+ .getFirstElement()
+ .getXMLStreamReader(false));
+ assertThat(IOUtils.toString(object.getContent().getInputStream(), "utf-8"))
+ .isEqualTo("some content");
+ }
+
+ /**
+ * 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(
+ StAX.createNullXMLStreamWriter(), exception));
+ fail("Expected XMLStreamException");
+ } catch (XMLStreamException ex) {
+ assertThat(ex).isSameAs(exception);
+ }
+ }
+
+ /**
+ * 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));
+ assertThat(element.getNamespaceURI()).isEqualTo("http://www.example.org/identity");
+ assertThat(element.getLocalName()).isEqualTo("LinkIdentities");
+ assertThat(element.isExpanded()).isFalse();
+ // 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 {@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();
+ JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
+ OMSourcedElement element =
+ omFactory.createOMElement(new JAXBOMDataSource(context, new DocumentBean()));
+ assertThat(element.getNamespaceURI()).isEqualTo("http://ws.apache.org/axiom/test/jaxb");
+ assertThat(element.getLocalName()).isEqualTo("document");
+ assertThat(element.isExpanded()).isFalse();
+ // Force expansion so that OMSourcedElement compares the namespace URI and local name
+ // provided by JAXBOMDataSource with the actual name of the element
+ element.getFirstOMChild();
+ }
+}
diff --git a/axiom-jaxb/src/test/java/org/apache/axiom/util/jaxb/JAXBUtilsTest.java b/axiom-jaxb/src/test/java/org/apache/axiom/util/jaxb/JAXBUtilsTest.java
new file mode 100644
index 0000000..a851252
--- /dev/null
+++ b/axiom-jaxb/src/test/java/org/apache/axiom/util/jaxb/JAXBUtilsTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.util.jaxb;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import javax.activation.DataHandler;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.jaxb.DocumentBean;
+import org.apache.axiom.jaxb.DocumentBean2;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.ds.jaxb.JAXBOMDataSource;
+import org.apache.axiom.om.util.jaxb.JAXBUtils;
+import org.apache.axiom.testutils.activation.TextDataSource;
+import org.apache.axiom.util.activation.DataHandlerUtils;
+import org.junit.jupiter.api.Test;
+
+public class JAXBUtilsTest {
+ @Test
+ public void testUnmarshalWithDataHandler() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
+ DocumentBean orgBean = new DocumentBean();
+ orgBean.setId("AB23498");
+ orgBean.setContent(new DataHandler(new TextDataSource("test content", "utf-8", "plain")));
+ OMElement element = factory.createOMElement(new JAXBOMDataSource(context, orgBean));
+ DocumentBean bean = (DocumentBean) JAXBUtils.unmarshal(element, context, null, true);
+ assertThat(bean.getId()).isEqualTo(orgBean.getId());
+ assertThat(bean.getContent()).isEqualTo(orgBean.getContent());
+ }
+
+ @Test
+ public void testUnmarshalWithDataHandlerToByteArray() throws Exception {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMNamespace ns = factory.createOMNamespace("http://ws.apache.org/axiom/test/jaxb", "p");
+ OMElement element = factory.createOMElement("document2", ns);
+ factory.createOMElement("id", ns, element).setText("12345");
+ OMElement content = factory.createOMElement("content", ns, element);
+ content.addChild(
+ factory.createOMText(
+ DataHandlerUtils.toBlob(
+ new DataHandler(
+ new TextDataSource("test content", "utf-8", "plain"))),
+ true));
+ JAXBContext context = JAXBContext.newInstance(DocumentBean2.class);
+ DocumentBean2 bean = (DocumentBean2) JAXBUtils.unmarshal(element, context, null, true);
+ assertThat(bean.getId()).isEqualTo("12345");
+ assertThat(bean.getContent()).isEqualTo("test content".getBytes("utf-8"));
+ }
+
+ @Test
+ public void testUnmarshalWithDeclaredType() throws Exception {
+ OMElement element = OMAbstractFactory.getOMFactory().createOMElement("foo", null);
+ element.setText("bar");
+ JAXBElement<String> result =
+ JAXBUtils.unmarshal(element, JAXBContext.newInstance(), null, String.class, true);
+ assertThat(result.getName()).isEqualTo(new QName("foo"));
+ assertThat(result.getValue()).isEqualTo("bar");
+ }
+}
diff --git a/testing/axiom-testsuite/src/main/schema/identity.xsd b/axiom-jaxb/src/test/schema/identity.xsd
similarity index 100%
rename from testing/axiom-testsuite/src/main/schema/identity.xsd
rename to axiom-jaxb/src/test/schema/identity.xsd
diff --git a/pom.xml b/pom.xml
index 0e7fa31..6632bd0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -332,6 +332,11 @@
<version>1.1.3</version>
</dependency>
<dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.24.2</version>
+ </dependency>
+ <dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.2</version>
diff --git a/testing/axiom-testsuite/pom.xml b/testing/axiom-testsuite/pom.xml
index b301902..1063bbd 100644
--- a/testing/axiom-testsuite/pom.xml
+++ b/testing/axiom-testsuite/pom.xml
@@ -51,11 +51,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>axiom-jaxb</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
@@ -186,22 +181,6 @@
</dependencies>
</plugin>
<plugin>
- <groupId>com.github.veithen.maven</groupId>
- <artifactId>xjc-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>generate-sources</goal>
- </goals>
- <configuration>
- <files>
- <file>src/main/schema/identity.xsd</file>
- </files>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<executions>
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
index 147a7af..87fe4b0 100644
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
+++ b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
@@ -275,16 +275,6 @@
addTest(
new org.apache.axiom.ts.om.builder.TestReadAttachmentBeforeRootPartComplete(
metaFactory));
- addTest(
- new org.apache.axiom.ts.om.builder.TestRegisterCustomBuilderForPayloadJAXBPlain(
- metaFactory));
- addTest(
- new org.apache.axiom.ts.om.builder
- .TestRegisterCustomBuilderForPayloadJAXBWithDataHandlerReaderExtension(
- metaFactory));
- addTest(
- new org.apache.axiom.ts.om.builder.TestRegisterCustomBuilderForPayloadJAXBWithXOP(
- metaFactory));
addTest(new org.apache.axiom.ts.om.builder.TestRootPartStreaming(metaFactory));
addTest(new org.apache.axiom.ts.om.builder.TestStandaloneConfiguration(metaFactory));
addTest(new org.apache.axiom.ts.om.comment.TestSerialize(metaFactory));
@@ -859,11 +849,6 @@
metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestSetTextQNameWithoutNamespace(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestUndeclarePrefix(metaFactory));
- addTest(new org.apache.axiom.ts.om.element.TestUnmarshalWithDataHandler(metaFactory));
- addTest(
- new org.apache.axiom.ts.om.element.TestUnmarshalWithDataHandlerToByteArray(
- metaFactory));
- addTest(new org.apache.axiom.ts.om.element.TestUnmarshalWithDeclaredType(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestWriteTextTo(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestWriteTextToWithNonTextNodes(metaFactory));
addTest(
@@ -1180,24 +1165,6 @@
addTest(
new org.apache.axiom.ts.om.sourcedelement
.TestWriteTextToWithNonDestructiveOMDataSource(metaFactory));
- addTest(
- new org.apache.axiom.ts.om.sourcedelement.jaxb.TestDataHandlerExpansion(
- metaFactory));
- addTest(
- new org.apache.axiom.ts.om.sourcedelement.jaxb.TestDataHandlerSerializationWithMTOM(
- metaFactory));
- addTest(
- new org.apache.axiom.ts.om.sourcedelement.jaxb
- .TestDataHandlerSerializationWithoutMTOM(metaFactory));
- addTest(
- new org.apache.axiom.ts.om.sourcedelement.jaxb.TestExceptionDuringSerialization(
- metaFactory));
- addTest(
- new org.apache.axiom.ts.om.sourcedelement.jaxb.TestGetNameFromJAXBElement(
- metaFactory));
- addTest(
- new org.apache.axiom.ts.om.sourcedelement.jaxb.TestGetNameFromPlainObject(
- metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.sr.TestGetName(metaFactory));
for (int events = 0; events < 7; events++) {
addTest(
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/RegisterCustomBuilderForPayloadJAXBTestCase.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/RegisterCustomBuilderForPayloadJAXBTestCase.java
deleted file mode 100644
index 9803a5d..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/RegisterCustomBuilderForPayloadJAXBTestCase.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.ts.om.builder;
-
-import javax.activation.DataHandler;
-import javax.xml.bind.JAXBContext;
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMXMLParserWrapper;
-import org.apache.axiom.om.ds.custombuilder.CustomBuilder;
-import org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport;
-import org.apache.axiom.testutils.io.IOTestUtils;
-import org.apache.axiom.ts.AxiomTestCase;
-import org.apache.axiom.util.activation.DataHandlerUtils;
-
-public abstract class RegisterCustomBuilderForPayloadJAXBTestCase extends AxiomTestCase {
- public RegisterCustomBuilderForPayloadJAXBTestCase(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- protected final OMElement createTestDocument(DataHandler dh) {
- OMFactory factory = metaFactory.getOMFactory();
- OMElement document = factory.createOMElement(new QName("urn:test", "document"));
- OMElement name = factory.createOMElement(new QName("name"));
- name.setText("some name");
- document.addChild(name);
- OMElement content = factory.createOMElement(new QName("content"));
- content.addChild(factory.createOMText(DataHandlerUtils.toBlob(dh), true));
- document.addChild(content);
- return document;
- }
-
- protected final void test(DataHandler dh, OMXMLParserWrapper builder, boolean same)
- throws Exception {
- JAXBCustomBuilder customBuilder =
- new JAXBCustomBuilder(JAXBContext.newInstance(MyDocument.class));
- ((CustomBuilderSupport) builder)
- .registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, customBuilder);
- builder.getDocumentElement().build();
- MyDocument myDocument = (MyDocument) customBuilder.getJaxbObject();
- if (same) {
- assertSame(dh, myDocument.getContent());
- } else {
- assertNotSame(dh, myDocument.getContent());
- IOTestUtils.compareStreams(
- dh.getInputStream(),
- "expected",
- myDocument.getContent().getInputStream(),
- "actual");
- }
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestRegisterCustomBuilderForPayloadJAXBPlain.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestRegisterCustomBuilderForPayloadJAXBPlain.java
deleted file mode 100644
index bb40361..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestRegisterCustomBuilderForPayloadJAXBPlain.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.ts.om.builder;
-
-import java.io.OutputStream;
-
-import javax.activation.DataHandler;
-
-import org.apache.axiom.blob.Blobs;
-import org.apache.axiom.blob.MemoryBlob;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMXMLBuilderFactory;
-import org.apache.axiom.testutils.blob.RandomBlob;
-import org.apache.axiom.util.activation.DataHandlerUtils;
-
-public class TestRegisterCustomBuilderForPayloadJAXBPlain
- extends RegisterCustomBuilderForPayloadJAXBTestCase {
- public TestRegisterCustomBuilderForPayloadJAXBPlain(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- DataHandler dh = DataHandlerUtils.toDataHandler(new RandomBlob(10000));
- MemoryBlob blob = Blobs.createMemoryBlob();
- OutputStream out = blob.getOutputStream();
- createTestDocument(dh).serialize(out);
- out.close();
- test(
- dh,
- OMXMLBuilderFactory.createOMBuilder(
- metaFactory.getOMFactory(), blob.getInputStream()),
- false);
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestRegisterCustomBuilderForPayloadJAXBWithDataHandlerReaderExtension.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestRegisterCustomBuilderForPayloadJAXBWithDataHandlerReaderExtension.java
deleted file mode 100644
index 6c0fab8..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestRegisterCustomBuilderForPayloadJAXBWithDataHandlerReaderExtension.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.ts.om.builder;
-
-import javax.activation.DataHandler;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMXMLBuilderFactory;
-import org.apache.axiom.testutils.activation.TestDataSource;
-
-public class TestRegisterCustomBuilderForPayloadJAXBWithDataHandlerReaderExtension
- extends RegisterCustomBuilderForPayloadJAXBTestCase {
- public TestRegisterCustomBuilderForPayloadJAXBWithDataHandlerReaderExtension(
- OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- DataHandler dh = new DataHandler(new TestDataSource('X', Integer.MAX_VALUE));
- OMElement document = createTestDocument(dh);
- test(
- dh,
- OMXMLBuilderFactory.createStAXOMBuilder(
- metaFactory.getOMFactory(), document.getXMLStreamReader()),
- true);
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestRegisterCustomBuilderForPayloadJAXBWithXOP.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestRegisterCustomBuilderForPayloadJAXBWithXOP.java
deleted file mode 100644
index f9efa70..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestRegisterCustomBuilderForPayloadJAXBWithXOP.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.ts.om.builder;
-
-import java.io.OutputStream;
-
-import javax.activation.DataHandler;
-
-import org.apache.axiom.blob.Blobs;
-import org.apache.axiom.blob.MemoryBlob;
-import org.apache.axiom.mime.MultipartBody;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.OMXMLBuilderFactory;
-import org.apache.axiom.om.util.StAXParserConfiguration;
-import org.apache.axiom.testutils.blob.RandomBlob;
-import org.apache.axiom.util.activation.DataHandlerUtils;
-
-public class TestRegisterCustomBuilderForPayloadJAXBWithXOP
- extends RegisterCustomBuilderForPayloadJAXBTestCase {
- public TestRegisterCustomBuilderForPayloadJAXBWithXOP(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- DataHandler dh = DataHandlerUtils.toDataHandler(new RandomBlob(10000));
- MemoryBlob blob = Blobs.createMemoryBlob();
- OutputStream out = blob.getOutputStream();
- OMOutputFormat format = new OMOutputFormat();
- format.setDoOptimize(true);
- createTestDocument(dh).serialize(out, format);
- out.close();
- MultipartBody mb =
- MultipartBody.builder()
- .setInputStream(blob.getInputStream())
- .setContentType(format.getContentType())
- .build();
- test(
- dh,
- OMXMLBuilderFactory.createOMBuilder(
- metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, mb),
- false);
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUnmarshalWithDataHandler.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUnmarshalWithDataHandler.java
deleted file mode 100644
index 93f709c..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUnmarshalWithDataHandler.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.ts.om.element;
-
-import javax.activation.DataHandler;
-import javax.xml.bind.JAXBContext;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.ds.jaxb.JAXBOMDataSource;
-import org.apache.axiom.om.util.jaxb.JAXBUtils;
-import org.apache.axiom.testutils.activation.TextDataSource;
-import org.apache.axiom.ts.AxiomTestCase;
-import org.apache.axiom.ts.jaxb.beans.DocumentBean;
-
-public class TestUnmarshalWithDataHandler extends AxiomTestCase {
- public TestUnmarshalWithDataHandler(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- OMFactory factory = metaFactory.getOMFactory();
- JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
- DocumentBean orgBean = new DocumentBean();
- orgBean.setId("AB23498");
- orgBean.setContent(new DataHandler(new TextDataSource("test content", "utf-8", "plain")));
- OMElement element = factory.createOMElement(new JAXBOMDataSource(context, orgBean));
- DocumentBean bean = (DocumentBean) JAXBUtils.unmarshal(element, context, null, true);
- assertEquals(orgBean.getId(), bean.getId());
- assertEquals(orgBean.getContent(), bean.getContent());
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUnmarshalWithDataHandlerToByteArray.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUnmarshalWithDataHandlerToByteArray.java
deleted file mode 100644
index 9845ce1..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUnmarshalWithDataHandlerToByteArray.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.ts.om.element;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import javax.activation.DataHandler;
-import javax.xml.bind.JAXBContext;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.util.jaxb.JAXBUtils;
-import org.apache.axiom.testutils.activation.TextDataSource;
-import org.apache.axiom.ts.AxiomTestCase;
-import org.apache.axiom.ts.jaxb.beans.DocumentBean2;
-import org.apache.axiom.util.activation.DataHandlerUtils;
-
-public class TestUnmarshalWithDataHandlerToByteArray extends AxiomTestCase {
- public TestUnmarshalWithDataHandlerToByteArray(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- OMFactory factory = metaFactory.getOMFactory();
- OMNamespace ns = factory.createOMNamespace("http://ws.apache.org/axiom/test/jaxb", "p");
- OMElement element = factory.createOMElement("document2", ns);
- factory.createOMElement("id", ns, element).setText("12345");
- OMElement content = factory.createOMElement("content", ns, element);
- content.addChild(
- factory.createOMText(
- DataHandlerUtils.toBlob(
- new DataHandler(
- new TextDataSource("test content", "utf-8", "plain"))),
- true));
- JAXBContext context = JAXBContext.newInstance(DocumentBean2.class);
- DocumentBean2 bean = (DocumentBean2) JAXBUtils.unmarshal(element, context, null, true);
- assertThat(bean.getId()).isEqualTo("12345");
- assertThat(bean.getContent()).isEqualTo("test content".getBytes("utf-8"));
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUnmarshalWithDeclaredType.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUnmarshalWithDeclaredType.java
deleted file mode 100644
index f839570..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestUnmarshalWithDeclaredType.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.ts.om.element;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.util.jaxb.JAXBUtils;
-import org.apache.axiom.ts.AxiomTestCase;
-
-public class TestUnmarshalWithDeclaredType extends AxiomTestCase {
- public TestUnmarshalWithDeclaredType(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- OMElement element = metaFactory.getOMFactory().createOMElement("foo", null);
- element.setText("bar");
- JAXBElement<String> result =
- JAXBUtils.unmarshal(element, JAXBContext.newInstance(), null, String.class, true);
- assertThat(result.getName()).isEqualTo(new QName("foo"));
- assertThat(result.getValue()).isEqualTo("bar");
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestDataHandlerExpansion.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestDataHandlerExpansion.java
deleted file mode 100644
index 864e26a..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestDataHandlerExpansion.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.ts.om.sourcedelement.jaxb;
-
-import javax.activation.DataHandler;
-import javax.xml.bind.JAXBContext;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.OMText;
-import org.apache.axiom.om.ds.jaxb.JAXBOMDataSource;
-import org.apache.axiom.ts.AxiomTestCase;
-import org.apache.axiom.ts.jaxb.beans.DocumentBean;
-import org.apache.axiom.util.activation.DataHandlerUtils;
-
-/**
- * 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}.
- */
-public class TestDataHandlerExpansion extends AxiomTestCase {
- public TestDataHandlerExpansion(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- OMFactory factory = metaFactory.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, DataHandlerUtils.toDataHandler(content.getBlob()));
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestDataHandlerSerializationWithMTOM.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestDataHandlerSerializationWithMTOM.java
deleted file mode 100644
index bc69c1e..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestDataHandlerSerializationWithMTOM.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.ts.om.sourcedelement.jaxb;
-
-import java.io.OutputStream;
-
-import javax.activation.DataHandler;
-import javax.xml.bind.JAXBContext;
-import javax.xml.namespace.QName;
-
-import org.apache.axiom.blob.Blob;
-import org.apache.axiom.blob.Blobs;
-import org.apache.axiom.blob.MemoryBlob;
-import org.apache.axiom.mime.MultipartBody;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMOutputFormat;
-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.JAXBOMDataSource;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.testutils.activation.TextDataSource;
-import org.apache.axiom.ts.AxiomTestCase;
-import org.apache.axiom.ts.jaxb.beans.DocumentBean;
-import org.apache.commons.io.IOUtils;
-
-/**
- * Tests that an {@link OMSourcedElement} backed by a {@link JAXBOMDataSource} with a bean
- * containing a {@link DataHandler} is correctly serialized to MTOM.
- */
-public class TestDataHandlerSerializationWithMTOM extends AxiomTestCase {
- public TestDataHandlerSerializationWithMTOM(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- SOAPFactory factory = metaFactory.getSOAP11Factory();
- JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
-
- // Construct the original message
- DocumentBean object = new DocumentBean();
- object.setId("123456");
- object.setContent(new DataHandler(new TextDataSource("some content", "utf-8", "plain")));
- 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);
- MemoryBlob mtom = Blobs.createMemoryBlob();
- OutputStream out = mtom.getOutputStream();
- orgEnvelope.serialize(out, format);
- out.close();
- assertFalse(element.isExpanded());
-
- // Parse the serialized message
- MultipartBody mb =
- MultipartBody.builder()
- .setInputStream(mtom.getInputStream())
- .setContentType(format.getContentType())
- .build();
- assertEquals(2, mb.getPartCount());
- SOAPEnvelope envelope =
- OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb).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());
- Blob blob = content.getBlob();
- assertEquals("some content", IOUtils.toString(blob.getInputStream(), "utf-8"));
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestDataHandlerSerializationWithoutMTOM.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestDataHandlerSerializationWithoutMTOM.java
deleted file mode 100644
index f9d3797..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestDataHandlerSerializationWithoutMTOM.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.ts.om.sourcedelement.jaxb;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import javax.activation.DataHandler;
-import javax.xml.bind.JAXBContext;
-
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.OMXMLBuilderFactory;
-import org.apache.axiom.om.ds.jaxb.JAXBOMDataSource;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.testutils.activation.TextDataSource;
-import org.apache.axiom.ts.AxiomTestCase;
-import org.apache.axiom.ts.jaxb.beans.DocumentBean;
-import org.apache.commons.io.IOUtils;
-
-/**
- * Tests that an {@link OMSourcedElement} backed by a {@link JAXBOMDataSource} with a bean
- * containing a {@link DataHandler} is correctly serialized.
- */
-public class TestDataHandlerSerializationWithoutMTOM extends AxiomTestCase {
- public TestDataHandlerSerializationWithoutMTOM(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- SOAPFactory factory = metaFactory.getSOAP11Factory();
- JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
-
- // Construct the original message
- DocumentBean orgObject = new DocumentBean();
- orgObject.setId("123456");
- orgObject.setContent(new DataHandler(new TextDataSource("some content", "utf-8", "plain")));
- 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(
- metaFactory, 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"));
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestExceptionDuringSerialization.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestExceptionDuringSerialization.java
deleted file mode 100644
index a9fa54d..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestExceptionDuringSerialization.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.ts.om.sourcedelement.jaxb;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.axiom.core.stream.stax.StAX;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.ds.jaxb.JAXBOMDataSource;
-import org.apache.axiom.ts.AxiomTestCase;
-import org.apache.axiom.ts.jaxb.beans.DocumentBean;
-
-/**
- * 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.
- */
-public class TestExceptionDuringSerialization extends AxiomTestCase {
- public TestExceptionDuringSerialization(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- OMFactory omFactory = metaFactory.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(
- StAX.createNullXMLStreamWriter(), exception));
- fail("Expected XMLStreamException");
- } catch (XMLStreamException ex) {
- assertSame(exception, ex);
- }
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestGetNameFromJAXBElement.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestGetNameFromJAXBElement.java
deleted file mode 100644
index 12eaf21..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestGetNameFromJAXBElement.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.ts.om.sourcedelement.jaxb;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.ds.jaxb.JAXBOMDataSource;
-import org.apache.axiom.ts.AxiomTestCase;
-import org.example.identity.LinkIdentitiesType;
-import org.example.identity.ObjectFactory;
-
-/**
- * Tests that {@link JAXBOMDataSource} backed by a {@link JAXBElement} is able to determine the
- * namespace URI and local name of the element without expansion.
- */
-public class TestGetNameFromJAXBElement extends AxiomTestCase {
- public TestGetNameFromJAXBElement(OMMetaFactory metaFactory) {
- super(metaFactory);
- }
-
- @Override
- protected void runTest() throws Throwable {
- OMFactory omFactory = metaFactory.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();
- }
-}
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestGetNameFromPlainObject.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestGetNameFromPlainObject.java
deleted file mode 100644
index f6e1fe6..0000000
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/jaxb/TestGetNameFromPlainObject.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.ts.om.sourcedelement.jaxb;
-
-import javax.xml.bind.JAXBContext;
-
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.ds.jaxb.JAXBOMDataSource;
-import org.apache.axiom.ts.AxiomTestCase;
-import org.apache.axiom.ts.jaxb.beans.DocumentBean;
-
-/**
- * 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);
- }
-
- @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());
- assertEquals("document", 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();
- }
-}