01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.schema.populate.other;
20:
21: import junit.framework.TestCase;
22:
23: import javax.xml.stream.XMLStreamReader;
24: import javax.xml.stream.XMLInputFactory;
25: import java.io.ByteArrayInputStream;
26: import java.lang.reflect.Method;
27: import java.beans.BeanInfo;
28: import java.beans.Introspector;
29: import java.beans.PropertyDescriptor;
30:
31: import org.apache.axiom.om.util.StAXUtils;
32:
33: public class PopulateParticleAllTest extends TestCase {
34: private String xmlString = "<myParticleAllElement xmlns=\"http://soapinterop.org/types\">"
35: + "<varFloat>3.3</varFloat>"
36: + "<varString>foo</varString>"
37: + "</myParticleAllElement>";
38:
39: public void testPopulate() throws Exception {
40:
41: XMLStreamReader reader = StAXUtils
42: .createXMLStreamReader(new ByteArrayInputStream(
43: xmlString.getBytes()));
44: Class clazz = Class
45: .forName("org.soapinterop.types.MyParticleAllElement");
46: Class innerClazz = clazz.getDeclaredClasses()[0];
47: Method parseMethod = innerClazz.getMethod("parse",
48: new Class[] { XMLStreamReader.class });
49: Object obj = parseMethod.invoke(null, new Object[] { reader });
50:
51: Object myParticleAllElement = null;
52: BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
53: PropertyDescriptor[] propertyDescriptors = beanInfo
54: .getPropertyDescriptors();
55: Method readMethod;
56: for (int i = 0; i < propertyDescriptors.length; i++) {
57: PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
58: if ("myParticleAllElement".equals(propertyDescriptor
59: .getDisplayName())) {
60: readMethod = propertyDescriptor.getReadMethod();
61: myParticleAllElement = readMethod.invoke(obj,
62: (Object[]) null);
63: break;
64: }
65: }
66: assertNotNull(myParticleAllElement);
67:
68: BeanInfo structBeanInfo = Introspector
69: .getBeanInfo(myParticleAllElement.getClass());
70: PropertyDescriptor[] structPropertyDescriptors = structBeanInfo
71: .getPropertyDescriptors();
72: for (int i = 0; i < structPropertyDescriptors.length; i++) {
73: PropertyDescriptor propertyDescriptor = structPropertyDescriptors[i];
74: if ("varFloat".equals(propertyDescriptor.getDisplayName())) {
75: readMethod = propertyDescriptor.getReadMethod();
76: assertEquals("varFloat is not properly set", new Float(
77: 3.3), readMethod.invoke(myParticleAllElement,
78: (Object[]) null));
79:
80: } else if ("varString".equals(propertyDescriptor
81: .getDisplayName())) {
82: readMethod = propertyDescriptor.getReadMethod();
83: //this should not be set ! - it should return zero
84: assertEquals("varString is not properly set", "foo",
85: readMethod.invoke(myParticleAllElement,
86: (Object[]) null));
87:
88: } else if ("varInt".equals(propertyDescriptor
89: .getDisplayName())) {
90: readMethod = propertyDescriptor.getReadMethod();
91: //this should not be set ! - it should return zero
92: assertEquals("varInt is not properly set", new Integer(
93: 0), readMethod.invoke(myParticleAllElement,
94: (Object[]) null));
95: }
96:
97: }
98: }
99: }
|