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.XMLInputFactory;
24: import javax.xml.stream.XMLStreamReader;
25: import javax.xml.stream.XMLStreamException;
26: import java.lang.reflect.InvocationTargetException;
27: import java.lang.reflect.Method;
28: import java.beans.IntrospectionException;
29: import java.beans.PropertyDescriptor;
30: import java.beans.Introspector;
31: import java.beans.BeanInfo;
32: import java.io.ByteArrayInputStream;
33:
34: import org.apache.axiom.om.util.StAXUtils;
35:
36: public class PopulateRecursiveTest extends TestCase {
37:
38: // all are present
39: private String xmlString1 = "<E xmlns=\"http://recursion.org\">"
40: + "<E>test</E>" + "</E>";
41:
42: public void testPopulate1() throws Exception {
43: populateAndAssert(xmlString1);
44: }
45:
46: private void populateAndAssert(String s) throws XMLStreamException,
47: ClassNotFoundException, NoSuchMethodException,
48: IllegalAccessException, InvocationTargetException,
49: IntrospectionException {
50: XMLStreamReader reader = StAXUtils
51: .createXMLStreamReader(new ByteArrayInputStream(s
52: .getBytes()));
53: Class clazz = Class.forName("org.recursion.E");
54: Class innerClazz = clazz.getDeclaredClasses()[0];
55: Method parseMethod = innerClazz.getMethod("parse",
56: new Class[] { XMLStreamReader.class });
57: Object obj = parseMethod.invoke(null, new Object[] { reader });
58:
59: assertNotNull(obj);
60:
61: Object eObject = null;
62: BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
63: PropertyDescriptor[] propertyDescriptors = beanInfo
64: .getPropertyDescriptors();
65: Method readMethod;
66:
67: for (int i = 0; i < propertyDescriptors.length; i++) {
68: PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
69: if ("e".equals(propertyDescriptor.getDisplayName())) {
70: readMethod = propertyDescriptor.getReadMethod();
71: eObject = readMethod.invoke(obj, null);
72:
73: assertNotNull(eObject);
74:
75: assertTrue(eObject.getClass().equals(
76: Class.forName("org.recursion.TypeE")));
77: }
78: }
79: }
80:
81: }
|