Author: veithen
Date: Sun Oct 2 10:40:26 2011
New Revision: 1178174
URL: http://svn.apache.org/viewvc?rev=1178174&view=rev
Log:
AXIOM-363: Automatically check for collisions between the Axiom API and DOM.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/DOMCompatibilityTest.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodCollisionTestCase.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodSignature.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/DOMCompatibilityTest.java
(with props)
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/DOMCompatibilityTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/DOMCompatibilityTest.java?rev=1178174&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/DOMCompatibilityTest.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/DOMCompatibilityTest.java
Sun Oct 2 10:40:26 2011
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Checks that there are no collisions between the Axiom object model
interfaces and DOM.
+ * <p>
+ * A fundamental design constraint of the Axiom API is that there must be no
collisions between
+ * Axiom methods and DOM methods, so that it is possible to create an Axiom
implementation that also
+ * implements DOM. Note however that Axiom may define methods with the same
signature as DOM
+ * methods, provided that they have the same behavior. This is e.g. the case
for
+ * {@link OMElement#getNamespaceURI()} and {@link OMElement#getLocalName()}.
+ */
+public class DOMCompatibilityTest extends TestCase {
+ public static TestSuite suite() {
+ TestSuite suite = new TestSuite();
+ // Note: All exceptions are methods that are known to have the same
behavior in Axiom
+ // and DOM. In these cases, method collisions are allowed.
+ suite.addTest(new MethodCollisionTestCase(OMAttribute.class,
Attr.class,
+ new MethodSignature[] { new MethodSignature("getNamespaceURI",
new Class[0]),
+ new MethodSignature("getLocalName",
new Class[0]) }));
+ suite.addTest(new MethodCollisionTestCase(OMComment.class,
Comment.class));
+ suite.addTest(new MethodCollisionTestCase(OMDocType.class,
DocumentType.class));
+ suite.addTest(new MethodCollisionTestCase(OMDocument.class,
Document.class));
+ suite.addTest(new
MethodCollisionTestCase(OMProcessingInstruction.class,
ProcessingInstruction.class,
+ new MethodSignature[] { new MethodSignature("getTarget", new
Class[0]) }));
+ suite.addTest(new MethodCollisionTestCase(OMElement.class,
Element.class,
+ new MethodSignature[] { new MethodSignature("getNamespaceURI",
new Class[0]),
+ new MethodSignature("getLocalName",
new Class[0]) }));
+ suite.addTest(new MethodCollisionTestCase(OMSourcedElement.class,
Element.class,
+ new MethodSignature[] { new MethodSignature("getNamespaceURI",
new Class[0]),
+ new MethodSignature("getLocalName",
new Class[0]) }));
+ suite.addTest(new MethodCollisionTestCase(OMText.class, Text.class));
+ suite.addTest(new MethodCollisionTestCase(OMText.class,
CDATASection.class));
+ suite.addTest(new MethodCollisionTestCase(OMText.class,
EntityReference.class));
+ return suite;
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/DOMCompatibilityTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodCollisionTestCase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodCollisionTestCase.java?rev=1178174&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodCollisionTestCase.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodCollisionTestCase.java
Sun Oct 2 10:40:26 2011
@@ -0,0 +1,63 @@
+/*
+ * 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;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+public class MethodCollisionTestCase extends TestCase {
+ private final Class omInterface;
+ private final Class domInterface;
+ private final MethodSignature[] exceptions;
+
+ public MethodCollisionTestCase(Class omInterface, Class domInterface,
MethodSignature[] exceptions) {
+ this.omInterface = omInterface;
+ this.domInterface = domInterface;
+ this.exceptions = exceptions;
+ setName(omInterface.getName() + " <-> " + domInterface.getName());
+ }
+
+ public MethodCollisionTestCase(Class omInterface, Class domInterface) {
+ this(omInterface, domInterface, null);
+ }
+
+ private Set/*<MethodSignature>*/ getMethodSignatures(Class iface) {
+ Set result = new HashSet();
+ Method[] methods = iface.getMethods();
+ for (int i=0; i<methods.length; i++) {
+ result.add(new MethodSignature(methods[i]));
+ }
+ return result;
+ }
+
+ protected void runTest() throws Throwable {
+ Set signatures = getMethodSignatures(omInterface);
+ signatures.retainAll(getMethodSignatures(domInterface));
+ if (exceptions != null) {
+ signatures.removeAll(Arrays.asList(exceptions));
+ }
+ if (!signatures.isEmpty()) {
+ fail("Method collision detected for the following methods: " +
signatures);
+ }
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodCollisionTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodSignature.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodSignature.java?rev=1178174&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodSignature.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodSignature.java
Sun Oct 2 10:40:26 2011
@@ -0,0 +1,70 @@
+/*
+ * 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;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+public class MethodSignature {
+ // Note: Although the JVM considers the return type as part of the
signature,
+ // the Java compiler does not.
+ private final String name;
+ private final Class[] parameterTypes;
+
+ public MethodSignature(String name, Class[] parameterTypes) {
+ this.name = name;
+ this.parameterTypes = parameterTypes;
+ }
+
+ public MethodSignature(Method method) {
+ name = method.getName();
+ parameterTypes = method.getParameterTypes();
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof MethodSignature) {
+ MethodSignature other = (MethodSignature)obj;
+ return other.name.equals(name) &&
Arrays.equals(other.parameterTypes, parameterTypes);
+ } else {
+ return false;
+ }
+ }
+
+ public int hashCode() {
+ int hashCode = name.hashCode();
+ for (int i=0; i<parameterTypes.length; i++) {
+ hashCode = 31*hashCode + parameterTypes[i].hashCode();
+ }
+ return hashCode;
+ }
+
+ public String toString() {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(name);
+ buffer.append('(');
+ for (int i=0; i<parameterTypes.length; i++) {
+ if (i>0) {
+ buffer.append(", ");
+ }
+ buffer.append(parameterTypes[i].getName());
+ }
+ buffer.append(')');
+ return buffer.toString();
+ }
+}
\ No newline at end of file
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/MethodSignature.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/DOMCompatibilityTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/DOMCompatibilityTest.java?rev=1178174&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/DOMCompatibilityTest.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/DOMCompatibilityTest.java
Sun Oct 2 10:40:26 2011
@@ -0,0 +1,66 @@
+/*
+ * 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.soap;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.axiom.om.MethodCollisionTestCase;
+import org.apache.axiom.om.MethodSignature;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Checks that there are no collisions between the SOAP object model
interfaces and DOM.
+ *
+ * @see org.apache.axiom.om.DOMCompatibilityTest
+ */
+public class DOMCompatibilityTest extends TestCase {
+ public static TestSuite suite() {
+ TestSuite suite = new TestSuite();
+
+ // These methods are known to have the same behavior in Axiom and DOM:
+ MethodSignature[] elementExceptions = new MethodSignature[] {
+ new MethodSignature("getNamespaceURI", new Class[0]),
+ new MethodSignature("getLocalName", new Class[0]) };
+
+ suite.addTest(new MethodCollisionTestCase(SOAPBody.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPEnvelope.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPFault.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPFaultCode.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPFaultDetail.class,
Element.class, elementExceptions));
+
+ // The getNodeValue and setNodeValue methods are real collisions that
will be fixed in Axiom 1.3; see AXIOM-363
+ suite.addTest(new MethodCollisionTestCase(SOAPFaultNode.class,
Element.class, new MethodSignature[] {
+ new MethodSignature("getNamespaceURI", new Class[0]),
+ new MethodSignature("getLocalName", new Class[0]),
+ new MethodSignature("getNodeValue", new Class[0]),
+ new MethodSignature("setNodeValue", new Class[] { String.class
}) }));
+
+ suite.addTest(new MethodCollisionTestCase(SOAPFaultReason.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPFaultRole.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPFaultSubCode.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPFaultText.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPFaultValue.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPHeader.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPHeaderBlock.class,
Element.class, elementExceptions));
+ suite.addTest(new MethodCollisionTestCase(SOAPMessage.class,
Document.class, elementExceptions));
+ return suite;
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/DOMCompatibilityTest.java
------------------------------------------------------------------------------
svn:eol-style = native