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/03/30 13:30:46 UTC
svn commit: r390089 - in /webservices/axis2/trunk/java/modules/codegen:
maven.xml test-resources/xsd/simple_choice.xsd
test/org/apache/axis2/schema/populate/other/PopulateChoiceTest.java
Author: ajith
Date: Thu Mar 30 03:30:37 2006
New Revision: 390089
URL: http://svn.apache.org/viewcvs?rev=390089&view=rev
Log:
Adding a test case to test the functionality of choice particles
Added:
webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateChoiceTest.java
Modified:
webservices/axis2/trunk/java/modules/codegen/maven.xml
webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd
Modified: webservices/axis2/trunk/java/modules/codegen/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/maven.xml?rev=390089&r1=390088&r2=390089&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/codegen/maven.xml Thu Mar 30 03:30:37 2006
@@ -59,6 +59,14 @@
<arg file="${schema.source.dir}/anonymous_complexType.xsd"/>
<arg file="${schema.generated.src.dir}"/>
</java>
+ <!-- anon choice xsd -->
+ <java classname="org.apache.axis2.schema.XSD2Java" fork="true">
+ <jvmarg line="${maven.junit.jvmargs}"/>
+ <classpath refid="maven.dependency.classpath"/>
+ <classpath location="${compiled.classes.dir}"/>
+ <arg file="${schema.source.dir}/simple_choice.xsd"/>
+ <arg file="${schema.generated.src.dir}"/>
+ </java>
<!-- simple max occurs xsd -->
<java classname="org.apache.axis2.schema.XSD2Java" fork="true">
<jvmarg line="${maven.junit.jvmargs}"/>
Modified: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd?rev=390089&r1=390088&r2=390089&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd (original)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple_choice.xsd Thu Mar 30 03:30:37 2006
@@ -2,8 +2,7 @@
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://soapinterop.org/types"
targetNamespace="http://soapinterop.org/types">
- <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
- <complexType name="SOAPStruct">
+ <complexType name="SOAPStruct">
<choice>
<element name="varString" type="xsd:string"/>
<element name="varInt" type="xsd:int"/>
Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateChoiceTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateChoiceTest.java?rev=390089&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateChoiceTest.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateChoiceTest.java Thu Mar 30 03:30:37 2006
@@ -0,0 +1,73 @@
+package org.apache.axis2.schema.populate.other;
+
+import junit.framework.TestCase;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import java.io.ByteArrayInputStream;
+import java.lang.reflect.Method;
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+public class PopulateChoiceTest extends TestCase {
+ private String xmlString = "<myElement xmlns=\"http://soapinterop.org/types\">" +
+ "<varFloat>3.3</varFloat>" +
+ "</myElement>";
+
+ public void testPopulate() throws Exception{
+
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(xmlString.getBytes()));
+ Class clazz = Class.forName("org.soapinterop.types.MyElement");
+ Class innerClazz = clazz.getDeclaredClasses()[0];
+ Method parseMethod = innerClazz.getMethod("parse",new Class[]{XMLStreamReader.class});
+ Object obj = parseMethod.invoke(null,new Object[]{reader});
+
+ Object myElement = null;
+ BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ Method readMethod;
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
+ if ("myElement".equals(propertyDescriptor.getDisplayName())){
+ readMethod = propertyDescriptor.getReadMethod();
+ myElement = readMethod.invoke(obj, (Object[]) null);
+ break;
+ }
+ }
+ assertNotNull(myElement);
+
+ BeanInfo structBeanInfo = Introspector.getBeanInfo(myElement.getClass());
+ PropertyDescriptor[] structPropertyDescriptors = structBeanInfo.getPropertyDescriptors();
+ for (int i = 0; i < structPropertyDescriptors.length; i++) {
+ PropertyDescriptor propertyDescriptor = structPropertyDescriptors[i];
+ if ("varFloat".equals(propertyDescriptor.getDisplayName())){
+ readMethod = propertyDescriptor.getReadMethod();
+ assertEquals("varFloat is not properly set",new Float(3.3),
+ readMethod.invoke(myElement, (Object[]) null));
+
+ }else if ("varInt".equals(propertyDescriptor.getDisplayName())){
+ readMethod = propertyDescriptor.getReadMethod();
+ //this should not be set ! - it should return zero
+ assertEquals("varInt is not properly set",new Integer(0),
+ readMethod.invoke(myElement, (Object[]) null));
+ }
+
+ }
+ }
+}