AXIOM-506: Break dependency between axiom-testsuite and axiom-activation
diff --git a/axiom-activation/pom.xml b/axiom-activation/pom.xml
index 12f6265..22a8eff 100644
--- a/axiom-activation/pom.xml
+++ b/axiom-activation/pom.xml
@@ -51,6 +51,18 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axiom-impl</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>soap-testsuite</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/axiom-activation/src/test/java/org/apache/axiom/mime/activation/PartDataHandlerBlobFactoryTest.java b/axiom-activation/src/test/java/org/apache/axiom/mime/activation/PartDataHandlerBlobFactoryTest.java
new file mode 100644
index 0000000..41abfe1
--- /dev/null
+++ b/axiom-activation/src/test/java/org/apache/axiom/mime/activation/PartDataHandlerBlobFactoryTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.mime.activation;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.activation.DataSource;
+
+import org.apache.axiom.mime.MultipartBody;
+import org.apache.axiom.mime.PartBlob;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.ts.soap.MTOMSample;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+
+public class PartDataHandlerBlobFactoryTest {
+ @Test
+ public void testDefaultImplementation() throws Exception {
+ MTOMSample testMessage = MTOMSample.SAMPLE1;
+ MultipartBody mb =
+ MultipartBody.builder()
+ .setInputStream(testMessage.getInputStream())
+ .setContentType(testMessage.getContentType())
+ .setPartBlobFactory(PartDataHandlerBlobFactory.DEFAULT)
+ .build();
+ PartBlob blob =
+ (PartBlob)
+ ((OMText)
+ OMXMLBuilderFactory.createSOAPModelBuilder(mb)
+ .getSOAPEnvelope()
+ .getBody()
+ .getFirstElement()
+ .getFirstElement()
+ .getFirstOMChild())
+ .getBlob();
+ assertThat(blob).isInstanceOf(PartDataHandlerBlob.class);
+ PartDataHandler dh = ((PartDataHandlerBlob) blob).getDataHandler();
+ assertThat(dh.getPart()).isSameAs(blob.getPart());
+ assertThat(dh.getBlob()).isSameAs(blob);
+ assertThat(dh.getContentType()).isEqualTo("image/jpeg");
+ DataSource ds = dh.getDataSource();
+ assertThat(ds.getContentType()).isEqualTo("image/jpeg");
+ byte[] expectedContent = IOUtils.toByteArray(testMessage.getPart(1));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ dh.writeTo(out);
+ assertThat(out.toByteArray()).isEqualTo(expectedContent);
+ assertThat(dh.getInputStream()).hasBinaryContent(expectedContent);
+ assertThat(ds.getInputStream()).hasBinaryContent(expectedContent);
+ }
+}
diff --git a/testing/axiom-testsuite/pom.xml b/testing/axiom-testsuite/pom.xml
index b6bd3b3..d929b60 100644
--- a/testing/axiom-testsuite/pom.xml
+++ b/testing/axiom-testsuite/pom.xml
@@ -46,11 +46,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>axiom-activation</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/TestSerialize.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/TestSerialize.java
index d8158e7..b46c66e 100644
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/TestSerialize.java
+++ b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/TestSerialize.java
@@ -21,8 +21,9 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+import org.apache.axiom.mime.ContentType;
+import org.apache.axiom.mime.MediaType;
import org.apache.axiom.mime.MultipartBody;
-import org.apache.axiom.mime.activation.PartDataHandlerBlobFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMMetaFactory;
import org.apache.axiom.om.OMOutputFormat;
@@ -31,7 +32,6 @@
import org.apache.axiom.om.util.StAXParserConfiguration;
import org.apache.axiom.ts.AxiomTestCase;
import org.apache.axiom.ts.soap.MTOMSample;
-import org.apache.axiom.util.activation.DataHandlerContentTypeProvider;
public class TestSerialize extends AxiomTestCase {
private final boolean base64;
@@ -52,7 +52,6 @@
MultipartBody.builder()
.setInputStream(inStream)
.setContentType(testMessage.getContentType())
- .setPartBlobFactory(PartDataHandlerBlobFactory.DEFAULT)
.build();
OMOutputFormat oof = new OMOutputFormat();
@@ -60,7 +59,7 @@
oof.setMimeBoundary(testMessage.getBoundary());
oof.setRootContentId(testMessage.getStart());
if (base64) {
- oof.setContentTypeProvider(DataHandlerContentTypeProvider.INSTANCE);
+ oof.setContentTypeProvider(blob -> new ContentType(new MediaType("image", "jpeg")));
oof.setProperty(
OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS, Boolean.TRUE);
}