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 2014/06/23 18:24:25 UTC
svn commit: r1604861 - in /webservices/axiom/trunk:
modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/
modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/
modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/ mo...
Author: veithen
Date: Mon Jun 23 16:24:24 2014
New Revision: 1604861
URL: http://svn.apache.org/r1604861
Log:
AXIOM-311: Eliminate the (partially redundant) CustomBuilderTest and replace it by more meaningful test cases.
Added:
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java (with props)
Removed:
webservices/axiom/trunk/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/builder/CustomBuilderTest.java
Modified:
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/CustomBuilder.java
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/envelope/TestCloneWithSourcedElement1.java
webservices/axiom/trunk/testsuites/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/TestMessage.java
Modified: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/CustomBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/CustomBuilder.java?rev=1604861&r1=1604860&r2=1604861&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/CustomBuilder.java (original)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/CustomBuilder.java Mon Jun 23 16:24:24 2014
@@ -40,6 +40,7 @@ public interface CustomBuilder {
* Create an OMElement for this whole subtree.
* A null is returned if the default StAXBuilder behavior should be used.
* @param namespace
+ * the namespace URI, or the empty string if the element has no namespace
* @param localPart
* @param parent
* @param reader
Modified: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=1604861&r1=1604860&r2=1604861&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Mon Jun 23 16:24:24 2014
@@ -324,6 +324,9 @@ public class StAXOMBuilder extends StAXB
protected OMNode createWithCustomBuilder(CustomBuilder customBuilder, OMFactory factory) {
String namespace = parser.getNamespaceURI();
+ if (namespace == null) {
+ namespace = "";
+ }
String localPart = parser.getLocalName();
if (log.isDebugEnabled()) {
Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java?rev=1604861&r1=1604860&r2=1604861&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java Mon Jun 23 16:24:24 2014
@@ -297,6 +297,9 @@ public class SOAPTestSuiteBuilder extend
}
for (TestMessage msg : goodSOAPFiles) {
addTest(new org.apache.axiom.ts.soap.builder.MessageTest(metaFactory, msg));
+ if (supportsOMSourcedElement) {
+ addTest(new org.apache.axiom.ts.soap.builder.TestRegisterCustomBuilderForPayload(metaFactory, msg));
+ }
addTest(new org.apache.axiom.ts.soap.envelope.TestClone(metaFactory, msg));
}
for (int i=0; i<goodSOAPFiles.length; i++) {
Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java?rev=1604861&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java (added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java Mon Jun 23 16:24:24 2014
@@ -0,0 +1,62 @@
+/*
+ * 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.soap.builder;
+
+import java.io.ByteArrayInputStream;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.ds.ByteArrayDataSource;
+import org.apache.axiom.om.ds.ByteArrayDataSource.ByteArray;
+import org.apache.axiom.om.ds.custombuilder.ByteArrayCustomBuilder;
+import org.apache.axiom.soap.SOAPModelBuilder;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.ts.soap.TestMessage;
+import org.apache.axiom.ts.soap.TestMessageAdapter;
+import org.custommonkey.xmlunit.XMLAssert;
+import org.xml.sax.InputSource;
+
+public class TestRegisterCustomBuilderForPayload extends AxiomTestCase {
+ private final TestMessage message;
+
+ public TestRegisterCustomBuilderForPayload(OMMetaFactory metaFactory, TestMessage message) {
+ super(metaFactory);
+ this.message = message;
+ addTestParameter("message", message.getName());
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ SOAPModelBuilder builder = message.getAdapter(TestMessageAdapter.class).getBuilder(metaFactory);
+ ((StAXSOAPModelBuilder)builder).registerCustomBuilderForPayload(new ByteArrayCustomBuilder("utf-8"));
+ OMElement payload = builder.getSOAPEnvelope().getBody().getFirstElement();
+ if (message.getPayload() == null) {
+ assertNull(payload);
+ } else {
+ assertTrue(payload instanceof OMSourcedElement);
+ ByteArray byteArray = (ByteArray)((OMSourcedElement)payload).getObject(ByteArrayDataSource.class);
+ assertNotNull(byteArray);
+ InputSource is = new InputSource(new ByteArrayInputStream(byteArray.bytes));
+ is.setEncoding(byteArray.encoding);
+ XMLAssert.assertXMLEqual(message.getPayloadInputSource(), is);
+ }
+ }
+}
Propchange: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/builder/TestRegisterCustomBuilderForPayload.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/envelope/TestCloneWithSourcedElement1.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/envelope/TestCloneWithSourcedElement1.java?rev=1604861&r1=1604860&r2=1604861&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/envelope/TestCloneWithSourcedElement1.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/envelope/TestCloneWithSourcedElement1.java Mon Jun 23 16:24:24 2014
@@ -43,5 +43,6 @@ public class TestCloneWithSourcedElement
OMSourcedElement omse =body.getOMFactory().createOMElement(bads, "payload", ns);
body.addChild(omse);
copyAndCheck(sourceEnv);
+ assertFalse(omse.isExpanded());
}
}
Modified: webservices/axiom/trunk/testsuites/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/TestMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testsuites/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/TestMessage.java?rev=1604861&r1=1604860&r2=1604861&view=diff
==============================================================================
--- webservices/axiom/trunk/testsuites/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/TestMessage.java (original)
+++ webservices/axiom/trunk/testsuites/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/TestMessage.java Mon Jun 23 16:24:24 2014
@@ -18,8 +18,20 @@
*/
package org.apache.axiom.ts.soap;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
/**
* A SOAP test message.
*/
@@ -56,4 +68,47 @@ public abstract class TestMessage extend
* @return an input stream with the content of this message
*/
public abstract InputStream getInputStream();
+
+ public final Element getEnvelope() {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ try {
+ return factory.newDocumentBuilder().parse(getInputStream()).getDocumentElement();
+ } catch (Exception ex) {
+ throw new Error(ex);
+ }
+ }
+
+ private Element getBody() {
+ NodeList children = getEnvelope().getChildNodes();
+ for (int i=0; i<children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE && child.getLocalName().equals("Body")) {
+ return (Element)child;
+ }
+ }
+ throw new Error("SOAP message has no body");
+ }
+
+ public final Element getPayload() {
+ NodeList children = getBody().getChildNodes();
+ for (int i=0; i<children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ return (Element)child;
+ }
+ }
+ return null;
+ }
+
+ public final InputSource getPayloadInputSource() {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ TransformerFactory.newInstance().newTransformer().transform(
+ new DOMSource(getPayload()), new StreamResult(baos));
+ } catch (Exception ex) {
+ throw new Error(ex);
+ }
+ return new InputSource(new ByteArrayInputStream(baos.toByteArray()));
+ }
}