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 2016/05/03 00:28:09 UTC
svn commit: r1742044 - in /webservices/axiom/trunk:
axiom-api/src/main/java/org/apache/axiom/blob/
testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/
testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/
testing/axiom-...
Author: veithen
Date: Mon May 2 22:28:09 2016
New Revision: 1742044
URL: http://svn.apache.org/viewvc?rev=1742044&view=rev
Log:
Test with BlobOMDataSource instead of ByteArrayDataSource.
Added:
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/ByteArrayBlob.java (with props)
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestBlobOMDataSource.java
- copied, changed from r1741958, webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestByteArrayDS.java
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestBlobOMDataSource.java
- copied, changed from r1741958, webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestByteArrayDS.java
Removed:
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestByteArrayDS.java
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestByteArrayDS.java
Modified:
webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/Blobs.java
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/Blobs.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/Blobs.java?rev=1742044&r1=1742043&r2=1742044&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/Blobs.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/Blobs.java Mon May 2 22:28:09 2016
@@ -27,6 +27,16 @@ public final class Blobs {
private Blobs() {}
/**
+ * Create a blob from a byte array.
+ *
+ * @param data the byte array
+ * @return the blob
+ */
+ public static Blob createBlob(byte[] data) {
+ return new ByteArrayBlob(data);
+ }
+
+ /**
* Create a {@link MemoryBlob} instance.
*
* @return the blob
Added: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/ByteArrayBlob.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/ByteArrayBlob.java?rev=1742044&view=auto
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/ByteArrayBlob.java (added)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/ByteArrayBlob.java Mon May 2 22:28:09 2016
@@ -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.blob;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.axiom.ext.io.StreamCopyException;
+
+final class ByteArrayBlob implements Blob {
+ private final byte[] data;
+
+ ByteArrayBlob(byte[] data) {
+ this.data = data;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return new ByteArrayInputStream(data);
+ }
+
+ @Override
+ public void writeTo(OutputStream out) throws StreamCopyException {
+ try {
+ out.write(data);
+ } catch (IOException ex) {
+ throw new StreamCopyException(StreamCopyException.WRITE, ex);
+ }
+ }
+
+ @Override
+ public long getSize() {
+ return data.length;
+ }
+}
Propchange: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/blob/ByteArrayBlob.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1742044&r1=1742043&r2=1742044&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Mon May 2 22:28:09 2016
@@ -540,7 +540,7 @@ public class OMTestSuiteBuilder extends
for (AddAttributeStrategy strategy : getInstances(AddAttributeStrategy.class)) {
addTest(new org.apache.axiom.ts.om.sourcedelement.TestAddAttribute(metaFactory, strategy));
}
- addTest(new org.apache.axiom.ts.om.sourcedelement.TestByteArrayDS(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestBlobOMDataSource(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestStringOMDataSource(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestCloneNonDestructive(metaFactory, true));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestCloneNonDestructive(metaFactory, false));
Copied: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestBlobOMDataSource.java (from r1741958, webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestByteArrayDS.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestBlobOMDataSource.java?p2=webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestBlobOMDataSource.java&p1=webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestByteArrayDS.java&r1=1741958&r2=1742044&rev=1742044&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestByteArrayDS.java (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestBlobOMDataSource.java Mon May 2 22:28:09 2016
@@ -18,26 +18,25 @@
*/
package org.apache.axiom.ts.om.sourcedelement;
-import java.io.ByteArrayOutputStream;
+import static com.google.common.truth.Truth.assertThat;
import javax.xml.stream.XMLStreamReader;
-import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.blob.Blobs;
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.OMNode;
-import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.ds.ByteArrayDataSource;
+import org.apache.axiom.om.ds.BlobOMDataSource;
import org.apache.axiom.ts.AxiomTestCase;
/**
- * Tests functionality of ByteArrayDataSource
+ * Tests functionality of BlobOMDataSource
*/
-public class TestByteArrayDS extends AxiomTestCase {
- public TestByteArrayDS(OMMetaFactory metaFactory) {
+public class TestBlobOMDataSource extends AxiomTestCase {
+ public TestBlobOMDataSource(OMMetaFactory metaFactory) {
super(metaFactory);
}
@@ -46,36 +45,31 @@ public class TestByteArrayDS extends Axi
String localName = "myPayload";
String encoding = "utf-8";
- String payload1 = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
+ String payload = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
OMNamespace ns = factory.createOMNamespace("urn://test", "tns");
- ByteArrayDataSource bads1 = new ByteArrayDataSource(payload1.getBytes(encoding), encoding);
+ BlobOMDataSource ds = new BlobOMDataSource(Blobs.createBlob(payload.getBytes(encoding)), encoding);
OMElement parent = factory.createOMElement("root", null);
- OMSourcedElement omse = factory.createOMElement(bads1, localName, ns);
+ OMSourcedElement omse = factory.createOMElement(ds, localName, ns);
parent.addChild(omse);
OMNode firstChild = parent.getFirstOMChild();
assertTrue("Expected OMSourcedElement child", firstChild instanceof OMSourcedElement);
OMSourcedElement child = (OMSourcedElement) firstChild;
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
- assertTrue("OMSourcedElement should be backed by a ByteArrayDataSource",
- child.getDataSource() instanceof ByteArrayDataSource);
+ assertThat(child.getDataSource()).isSameAs(ds);
- // A ByteArrayDataSource does not consume the backing object when read.
- // Thus getting the XMLStreamReader of the ByteArrayDataSource should not
+ // A BlobOMDataSource does not consume the backing object when read.
+ // Thus getting the XMLStreamReader of the BlobOMDataSource should not
// cause expansion of the OMSourcedElement.
XMLStreamReader reader = child.getXMLStreamReader();
reader.next();
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
- // Likewise, a ByteArrayDataSource does not consume the backing object when
+ // Likewise, a BlobOMDataSource does not consume the backing object when
// written. Thus serializing the OMSourcedElement should not cause the expansion
// of the OMSourcedElement.
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- parent.serialize(baos);
- String output = baos.toString(encoding);
-// System.out.println(output);
assertTrue("The payload was not present in the output",
- output.indexOf(payload1) > 0);
+ parent.toString().indexOf(payload) > 0);
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
// If a consumer calls build or buildWithAttachments on the tree, the
@@ -85,21 +79,7 @@ public class TestByteArrayDS extends Axi
parent.buildWithAttachments();
assertTrue("OMSourcedElement is expanded after buildWithAttachments(). This is unexpected", !child.isExpanded());
- // Test getting the raw bytes from the ByteArrayDataSource.
- OMDataSourceExt ds = (OMDataSourceExt) child.getDataSource();
- byte[] bytes = ds.getXMLBytes("UTF-16"); // Get the bytes as UTF-16
- String payload = new String(bytes, "utf-16");
- assertTrue("The obtained bytes did not match the payload",
- payload1.equals(payload));
-
-
- // Test getting the raw bytes with the default encoding
- OMOutputFormat outputFormat = new OMOutputFormat();
- baos = new ByteArrayOutputStream();
- ds.serialize(baos, outputFormat);
- output = baos.toString(OMOutputFormat.DEFAULT_CHAR_SET_ENCODING);
-// System.out.println(output);
- assertTrue("The obtained bytes did not match the payload",
- payload1.equals(output));
+ // Test getting the raw bytes from the BlobOMDataSource.
+ assertThat(child.getDataSource()).isSameAs(ds);
}
}
Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java?rev=1742044&r1=1742043&r2=1742044&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java Mon May 2 22:28:09 2016
@@ -257,7 +257,7 @@ public class SOAPTestSuiteBuilder extend
}
}
if (supportsOMSourcedElement) {
- addTest(new org.apache.axiom.ts.soap.headerblock.TestByteArrayDS(metaFactory, spec));
+ addTest(new org.apache.axiom.ts.soap.headerblock.TestBlobOMDataSource(metaFactory, spec));
}
addTest(new org.apache.axiom.ts.soap.headerblock.TestClone(metaFactory, spec, Boolean.TRUE));
addTest(new org.apache.axiom.ts.soap.headerblock.TestClone(metaFactory, spec, Boolean.FALSE));
Copied: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestBlobOMDataSource.java (from r1741958, webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestByteArrayDS.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestBlobOMDataSource.java?p2=webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestBlobOMDataSource.java&p1=webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestByteArrayDS.java&r1=1741958&r2=1742044&rev=1742044&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestByteArrayDS.java (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/headerblock/TestBlobOMDataSource.java Mon May 2 22:28:09 2016
@@ -18,16 +18,16 @@
*/
package org.apache.axiom.ts.soap.headerblock;
-import java.io.ByteArrayOutputStream;
+import static com.google.common.truth.Truth.assertThat;
import javax.xml.stream.XMLStreamReader;
-import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.blob.Blobs;
import org.apache.axiom.om.OMMetaFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.ds.ByteArrayDataSource;
+import org.apache.axiom.om.ds.BlobOMDataSource;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPHeader;
import org.apache.axiom.soap.SOAPHeaderBlock;
@@ -35,10 +35,10 @@ import org.apache.axiom.ts.soap.SOAPSpec
import org.apache.axiom.ts.soap.SOAPTestCase;
/**
- * Tests functionality of ByteArrayDataSource
+ * Tests functionality of BlobOMDataSource
*/
-public class TestByteArrayDS extends SOAPTestCase {
- public TestByteArrayDS(OMMetaFactory metaFactory, SOAPSpec spec) {
+public class TestBlobOMDataSource extends SOAPTestCase {
+ public TestBlobOMDataSource(OMMetaFactory metaFactory, SOAPSpec spec) {
super(metaFactory, spec);
}
@@ -47,51 +47,40 @@ public class TestByteArrayDS extends SOA
SOAPHeader soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
String localName = "myPayload";
String encoding = "utf-8";
- String payload1 = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
+ String payload = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
OMNamespace ns = soapFactory.createOMNamespace("urn://test", "tns");
- ByteArrayDataSource bads1 = new ByteArrayDataSource(payload1.getBytes(encoding), encoding);
+ BlobOMDataSource ds = new BlobOMDataSource(Blobs.createBlob(payload.getBytes(encoding)), encoding);
// Set an empty MustUnderstand property on the data source
- bads1.setProperty(SOAPHeaderBlock.MUST_UNDERSTAND_PROPERTY, null);
+ ds.setProperty(SOAPHeaderBlock.MUST_UNDERSTAND_PROPERTY, null);
- OMSourcedElement omse = soapFactory.createSOAPHeaderBlock(localName, ns, bads1);
+ OMSourcedElement omse = soapFactory.createSOAPHeaderBlock(localName, ns, ds);
soapHeader.addChild(omse);
OMNode firstChild = soapHeader.getFirstOMChild();
assertTrue("Expected OMSourcedElement child", firstChild instanceof SOAPHeaderBlock);
SOAPHeaderBlock child = (SOAPHeaderBlock) firstChild;
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
- assertTrue("OMSourcedElement should be backed by a ByteArrayDataSource",
- child.getDataSource() instanceof ByteArrayDataSource);
+ assertThat(child.getDataSource()).isSameAs(ds);
// Make sure that getting the MustUnderstand property does not cause expansion.
assertTrue(!child.getMustUnderstand());
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
- assertTrue("OMSourcedElement should be backed by a ByteArrayDataSource",
- child.getDataSource() instanceof ByteArrayDataSource);
+ assertThat(child.getDataSource()).isSameAs(ds);
- // A ByteArrayDataSource does not consume the backing object when read.
- // Thus getting the XMLStreamReader of the ByteArrayDataSource should not
+ // A BlobOMDataSource does not consume the backing object when read.
+ // Thus getting the XMLStreamReader of the BlobOMDataSource should not
// cause expansion of the OMSourcedElement.
XMLStreamReader reader = child.getXMLStreamReader();
reader.next();
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
- // Likewise, a ByteArrayDataSource does not consume the backing object when
+ // Likewise, a BlobOMDataSource does not consume the backing object when
// written. Thus serializing the OMSourcedElement should not cause the expansion
// of the OMSourcedElement.
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- soapHeader.serialize(baos);
- String output = baos.toString(encoding);
-// System.out.println(output);
assertTrue("The payload was not present in the output",
- output.indexOf(payload1) > 0);
+ soapHeader.toString().indexOf(payload) > 0);
assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
- // Test getting the raw bytes from the ByteArrayDataSource.
- OMDataSourceExt ds = (OMDataSourceExt) child.getDataSource();
- byte[] bytes = ds.getXMLBytes("UTF-16"); // Get the bytes as UTF-16
- String payload = new String(bytes, "utf-16");
- assertTrue("The obtained bytes did not match the payload",
- payload1.equals(payload));
+ assertThat(child.getDataSource()).isSameAs(ds);
}
}