You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ve...@apache.org on 2009/07/23 21:56:36 UTC
svn commit: r797206 - in
/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema:
AbstractTestCase.java testsuite/AbstractTest.java
testsuite/AnyElementsTest.java
Author: veithen
Date: Thu Jul 23 19:56:36 2009
New Revision: 797206
URL: http://svn.apache.org/viewvc?rev=797206&view=rev
Log:
ADB tests: refactored the AnyElementsTest to use the new test approach in AbstractTestCase. This increases the test coverage and will allow us to investigate (the second part of) AXIS2-4439.
Modified:
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/AbstractTestCase.java
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/testsuite/AbstractTest.java
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/testsuite/AnyElementsTest.java
Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/AbstractTestCase.java?rev=797206&r1=797205&r2=797206&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/AbstractTestCase.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/AbstractTestCase.java Thu Jul 23 19:56:36 2009
@@ -141,6 +141,8 @@
assertEquals("value for " + message, expected, actual);
} else if (DataHandler.class.isAssignableFrom(type)) {
assertDataHandlerEquals((DataHandler)expected, (DataHandler)actual);
+ } else if (OMElement.class.isAssignableFrom(type)) {
+ assertTrue(isOMElementsEqual((OMElement)expected, (OMElement)actual));
} else if (isADBBean(type)) {
if (isEnum(type)) {
assertSame("enum value for " + message, expected, actual);
@@ -153,6 +155,16 @@
}
}
+ protected static boolean isOMElementsEqual(OMElement omElement1,OMElement omElement2){
+ boolean isEqual = false;
+ if ((omElement1 == null) || (omElement2 == null)){
+ isEqual = (omElement1 == omElement2);
+ } else {
+ isEqual = omElement1.getLocalName().equals(omElement2.getLocalName());
+ }
+ return isEqual;
+ }
+
private static int countDataHandlers(Object bean) throws Exception {
int count = 0;
for (PropertyDescriptor desc : getBeanInfo(bean.getClass()).getPropertyDescriptors()) {
Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/testsuite/AbstractTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/testsuite/AbstractTest.java?rev=797206&r1=797205&r2=797206&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/testsuite/AbstractTest.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/testsuite/AbstractTest.java Thu Jul 23 19:56:36 2009
@@ -19,15 +19,16 @@
package org.apache.axis2.schema.testsuite;
-import junit.framework.TestCase;
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.axis2.schema.AbstractTestCase;
+
import services.echo.types.BookInformation;
-public class AbstractTest extends TestCase {
+public class AbstractTest extends AbstractTestCase {
protected OMElement getOMElement(){
OMFactory fac = OMAbstractFactory.getSOAP12Factory();
@@ -37,16 +38,6 @@
return omElement;
}
- protected boolean isOMElementsEqual(OMElement omElement1,OMElement omElement2){
- boolean isEqual = false;
- if ((omElement1 == null) || (omElement2 == null)){
- isEqual = (omElement1 == omElement2);
- } else {
- isEqual = omElement1.getLocalName().equals(omElement2.getLocalName());
- }
- return isEqual;
- }
-
protected boolean isObjectsEqual(Object object1,Object object2){
boolean isEqual = false;
if ((object1 == null) || (object2 == null)){
Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/testsuite/AnyElementsTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/testsuite/AnyElementsTest.java?rev=797206&r1=797205&r2=797206&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/testsuite/AnyElementsTest.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/testsuite/AnyElementsTest.java Thu Jul 23 19:56:36 2009
@@ -19,153 +19,83 @@
package org.apache.axis2.schema.testsuite;
-import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.util.StAXUtils;
+
import services.echo.types.TestAny1;
import services.echo.types.TestAny2;
import services.echo.types.TestAny3;
import services.echo.types.TestAny4;
-import javax.xml.stream.XMLStreamReader;
-import java.io.ByteArrayInputStream;
-
-
public class AnyElementsTest extends AbstractTest {
public static final int MIN_EQUALS_ZERO = 0;
public static final int MIN_EQUALS_ONE = 1;
- public void testAnyArray() {
- OMElement[] returnObject;
- try {
- returnObject = testAnyArray(null, MIN_EQUALS_ZERO);
- assertTrue(assertArrayEqual(returnObject, null));
- returnObject = testAnyArray(new OMElement[]{null}, MIN_EQUALS_ZERO);
- assertTrue(assertArrayEqual(returnObject, null));
- returnObject = testAnyArray(new OMElement[]{getOMElement()}, MIN_EQUALS_ZERO);
- assertTrue(assertArrayEqual(returnObject, new OMElement[]{getOMElement()}));
- returnObject = testAnyArray(new OMElement[]{getOMElement(), getOMElement()}, MIN_EQUALS_ZERO);
- assertTrue(assertArrayEqual(returnObject, new OMElement[]{getOMElement(), getOMElement()}));
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
-
- try {
- returnObject = testAnyArray(null, MIN_EQUALS_ONE);
- fail();
- } catch (Exception e) {
- assertTrue(true);
- }
-
- try {
- returnObject = testAnyArray(new OMElement[]{null}, MIN_EQUALS_ONE);
- fail();
- } catch (Exception e) {
- assertTrue(true);
- }
-
- try {
- returnObject = testAnyArray(new OMElement[]{getOMElement(), getOMElement()}, MIN_EQUALS_ONE);
- assertTrue(assertArrayEqual(returnObject, new OMElement[]{getOMElement(), getOMElement()}));
- } catch (Exception e) {
- fail();
- }
-
-
- }
-
- private OMElement[] testAnyArray(OMElement[] innerObject, int type) throws Exception {
- OMElement omElement;
- String omElementString;
- OMElement[] returnObject = null;
-
- switch (type) {
- case MIN_EQUALS_ZERO : {
- TestAny1 testAny = new TestAny1();
- testAny.setExtraElement(innerObject);
- omElement = testAny.getOMElement(TestAny1.MY_QNAME, OMAbstractFactory.getSOAP12Factory());
- omElementString = omElement.toStringWithConsume();
- System.out.println("OMElement ==> " + omElementString);
- XMLStreamReader xmlReader =
- StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
- returnObject = TestAny1.Factory.parse(xmlReader).getExtraElement();
- break;
- }
- case MIN_EQUALS_ONE : {
- TestAny3 testAny = new TestAny3();
- testAny.setExtraElement(innerObject);
- omElement = testAny.getOMElement(TestAny3.MY_QNAME, OMAbstractFactory.getSOAP12Factory());
- omElementString = omElement.toStringWithConsume();
- System.out.println("OMElement ==> " + omElementString);
- XMLStreamReader xmlReader =
- StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
- returnObject = TestAny3.Factory.parse(xmlReader).getExtraElement();
- break;
- }
- }
- return returnObject;
- }
-
- public void testAny() {
- OMElement returnObject;
- try {
- returnObject = testAny(null, MIN_EQUALS_ZERO);
- assertTrue(isOMElementsEqual(returnObject, null));
- returnObject = testAny(getOMElement(), MIN_EQUALS_ZERO);
- assertTrue(isOMElementsEqual(returnObject, getOMElement()));
-
- } catch (Exception e) {
- fail();
- }
-
- try {
- returnObject = testAny(null, MIN_EQUALS_ONE);
- fail();
- } catch (Exception e) {
- assertTrue(true);
- }
-
- try {
- returnObject = testAny(getOMElement(), MIN_EQUALS_ONE);
- assertTrue(isOMElementsEqual(returnObject, getOMElement()));
- } catch (Exception e) {
- fail();
- }
- }
-
- private OMElement testAny(OMElement innerObject, int type) throws Exception {
- OMElement omElement;
- OMElement returnObject = null;
- String omElementString;
-
- switch (type) {
- case MIN_EQUALS_ZERO : {
- TestAny2 testAny = new TestAny2();
- testAny.setExtraElement(innerObject);
- omElement = testAny.getOMElement(TestAny2.MY_QNAME, OMAbstractFactory.getSOAP12Factory());
- omElementString = omElement.toStringWithConsume();
- System.out.println("OMElement ==> " + omElementString);
- XMLStreamReader xmlReader =
- StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
- returnObject = TestAny2.Factory.parse(xmlReader).getExtraElement();
- break;
- }
- case MIN_EQUALS_ONE : {
- TestAny4 testAny = new TestAny4();
- testAny.setExtraElement(innerObject);
- omElement = testAny.getOMElement(TestAny4.MY_QNAME, OMAbstractFactory.getSOAP12Factory());
- omElementString = omElement.toStringWithConsume();
- System.out.println("OMElement ==> " + omElementString);
- XMLStreamReader xmlReader =
- StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
- returnObject = TestAny4.Factory.parse(xmlReader).getExtraElement();
- break;
- }
- }
- return returnObject;
+ public void testAnyArray1() throws Exception {
+ TestAny1 testAny = new TestAny1();
+ testAny.setExtraElement(null);
+ testSerializeDeserialize(testAny);
+ }
+
+ public void testAnyArray2() throws Exception {
+ TestAny1 testAny = new TestAny1();
+ testAny.setExtraElement(new OMElement[]{null});
+ TestAny1 expected = new TestAny1();
+ testAny.setExtraElement(null);
+ testSerializeDeserialize(testAny, expected);
+ }
+
+ public void testAnyArray3() throws Exception {
+ TestAny1 testAny = new TestAny1();
+ testAny.setExtraElement(new OMElement[]{getOMElement()});
+ testSerializeDeserialize(testAny, false);
+ }
+
+ public void testAnyArray4() throws Exception {
+ TestAny1 testAny = new TestAny1();
+ testAny.setExtraElement(new OMElement[]{getOMElement(), getOMElement()});
+ testSerializeDeserialize(testAny, false);
+ }
+
+ public void testAnyArray5() throws Exception {
+ TestAny3 testAny = new TestAny3();
+ testAny.setExtraElement(null);
+ assertSerializationFailure(testAny);
+ }
+
+ public void testAnyArray6() throws Exception {
+ TestAny3 testAny = new TestAny3();
+ testAny.setExtraElement(new OMElement[]{null});
+ assertSerializationFailure(testAny);
+ }
+
+ public void testAnyArray7() throws Exception {
+ TestAny3 testAny = new TestAny3();
+ testAny.setExtraElement(new OMElement[]{getOMElement(), getOMElement()});
+ testSerializeDeserialize(testAny, false);
+ }
+
+ public void testAny1() throws Exception {
+ TestAny2 testAny = new TestAny2();
+ testAny.setExtraElement(null);
+ testSerializeDeserialize(testAny);
+ }
+
+ public void testAny2() throws Exception {
+ TestAny2 testAny = new TestAny2();
+ testAny.setExtraElement(getOMElement());
+ testSerializeDeserialize(testAny);
+ }
+
+ public void testAny3() throws Exception {
+ TestAny4 testAny = new TestAny4();
+ testAny.setExtraElement(null);
+ assertSerializationFailure(testAny);
+ }
+
+ public void testAny4() throws Exception {
+ TestAny4 testAny = new TestAny4();
+ testAny.setExtraElement(getOMElement());
+ testSerializeDeserialize(testAny);
}
-
-
}