You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by aj...@apache.org on 2006/06/27 11:45:27 UTC
svn commit: r417390 - in
/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate:
derived/AbstractDerivedPopulater.java simple/AbstractSimplePopulater.java
Author: ajith
Date: Tue Jun 27 02:45:26 2006
New Revision: 417390
URL: http://svn.apache.org/viewvc?rev=417390&view=rev
Log:
1. Made slight improvements to the test class code
2. Added the same test to the AbstractSimplePopulater.java
Modified:
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate/derived/AbstractDerivedPopulater.java
webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate/simple/AbstractSimplePopulater.java
Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate/derived/AbstractDerivedPopulater.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate/derived/AbstractDerivedPopulater.java?rev=417390&r1=417389&r2=417390&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate/derived/AbstractDerivedPopulater.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate/derived/AbstractDerivedPopulater.java Tue Jun 27 02:45:26 2006
@@ -36,7 +36,9 @@
// force others to implement this method
public abstract void testPopulate() throws Exception;
- // Simple reusable method to make object instances via reflection
+ /**
+ * Simple reusable method to make object instances via reflection
+ */
protected Object process(String testString,String className) throws Exception{
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(testString.getBytes()));
Class clazz = Class.forName(className);
@@ -54,48 +56,77 @@
protected String className= null;
protected Class propertyClass = null;
-
+ /**
+ * check value function - may be overridden
+ * @param xmlToSet
+ * @param value
+ * @throws Exception
+ */
protected void checkValue(String xmlToSet, String value) throws Exception {
Object o = process(xmlToSet, className);
Class beanClass = Class.forName(className);
-
+
BeanInfo info = Introspector.getBeanInfo(beanClass);
PropertyDescriptor[] propDescs = info.getPropertyDescriptors();
for (int i = 0; i < propDescs.length; i++) {
PropertyDescriptor propDesc = propDescs[i];
-
+
if (propDesc.getPropertyType().equals(propertyClass)){
String s = convertToString(propDesc.getReadMethod().invoke(o,
(Object[]) null));
compare(value,s);
}
}
-
+
+
+ CompareOMElemntSerializations(o, xmlToSet);
+ }
+
+ /**
+ * Compares serializations - may be overridden
+ * @param o
+ * @param xmlToSet
+ * @throws Exception
+ */
+ protected void CompareOMElemntSerializations(Object o, String xmlToSet) throws Exception {
OMElement element = getOMElement(o);
-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(baos);
element.serialize(writer);
writer.flush();
-
+
assertXMLEqual(baos.toString(),xmlToSet);
- }
-
+ }
+
+ /**
+ * Get OM element via reflection
+ * @param bean
+ * @return
+ * @throws Exception
+ */
protected OMElement getOMElement(Object bean) throws Exception {
Method method = bean.getClass().getMethod("getOMElement", new Class[]{
- Class.forName("javax.xml.namespace.QName"),
- Class.forName("org.apache.axiom.om.OMFactory")});
-
- OMElement result = (OMElement) method.invoke(bean, new Object[]{null, OMAbstractFactory.getOMFactory()});
- return result;
-// throw new UnsupportedOperationException();
-
+ javax.xml.namespace.QName.class,
+ org.apache.axiom.om.OMFactory.class});
+
+ return (OMElement) method.invoke(bean, new Object[]{null, OMAbstractFactory.getOMFactory()});
+
}
+ /**
+ * comapare method - may be overridden
+ * @param val1
+ * @param val2
+ */
protected void compare(String val1,String val2){
assertEquals(val1,val2);
}
+ /**
+ *
+ * @param o
+ * @return
+ */
protected String convertToString(Object o){
return o.toString();
}
Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate/simple/AbstractSimplePopulater.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate/simple/AbstractSimplePopulater.java?rev=417390&r1=417389&r2=417390&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate/simple/AbstractSimplePopulater.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/populate/simple/AbstractSimplePopulater.java Tue Jun 27 02:45:26 2006
@@ -4,13 +4,19 @@
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLOutputFactory;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.lang.reflect.Method;
import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.custommonkey.xmlunit.XMLTestCase;
/*
* Copyright 2004,2005 The Apache Software Foundation.
*
@@ -27,14 +33,22 @@
* limitations under the License.
*/
-public abstract class AbstractSimplePopulater extends TestCase {
+public abstract class AbstractSimplePopulater extends XMLTestCase {
// force others to implement this method
public abstract void testPopulate() throws Exception;
+
protected String className= null;
protected Class propertyClass = null;
- // Simple reusable method to make object instances via reflection
+
+ /**
+ * Simple reusable method to make object instances via reflection
+ * @param testString
+ * @param className
+ * @return
+ * @throws Exception
+ */
protected Object process(String testString,String className) throws Exception{
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(testString.getBytes()));
Class clazz = Class.forName(className);
@@ -49,6 +63,12 @@
}
+ /**
+ * Simple method to compare. May be overridden
+ * @param xmlToSet
+ * @param value
+ * @throws Exception
+ */
protected void checkValue(String xmlToSet, String value) throws Exception {
Object o = process(xmlToSet, className);
Class beanClass = Class.forName(className);
@@ -66,10 +86,50 @@
}
+ /**
+ * Compares serializations - may be overridden
+ * @param o
+ * @param xmlToSet
+ * @throws Exception
+ */
+ protected void CompareOMElemntSerializations(Object o, String xmlToSet) throws Exception {
+ OMElement element = getOMElement(o);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(baos);
+ element.serialize(writer);
+ writer.flush();
+
+ assertXMLEqual(baos.toString(),xmlToSet);
+ }
+
+ /**
+ * Get OM element via reflection
+ * @param bean
+ * @return
+ * @throws Exception
+ */
+ protected OMElement getOMElement(Object bean) throws Exception {
+ Method method = bean.getClass().getMethod("getOMElement", new Class[]{
+ javax.xml.namespace.QName.class,
+ org.apache.axiom.om.OMFactory.class});
+
+ return (OMElement) method.invoke(bean, new Object[]{null, OMAbstractFactory.getOMFactory()});
+
+ }
+ /**
+ * value comparisom
+ * @param val1
+ * @param val2
+ */
protected void compare(String val1,String val2){
assertEquals(val1,val2);
}
+ /**
+ * conversion - may be overriddens
+ * @param o
+ * @return
+ */
protected String convertToString(Object o){
return o.toString();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org