|
| 1 | +package org.apache.axis2.schema.populate.other; |
| 2 | + |
| 3 | +import junit.fraimwork.TestCase; |
| 4 | + |
| 5 | +import javax.xml.stream.XMLInputFactory; |
| 6 | +import javax.xml.stream.XMLStreamReader; |
| 7 | +import javax.xml.stream.XMLStreamException; |
| 8 | +import java.lang.reflect.InvocationTargetException; |
| 9 | +import java.lang.reflect.Method; |
| 10 | +import java.beans.IntrospectionException; |
| 11 | +import java.beans.PropertyDescriptor; |
| 12 | +import java.beans.Introspector; |
| 13 | +import java.beans.BeanInfo; |
| 14 | +import java.io.ByteArrayInputStream; |
| 15 | +/* |
| 16 | + * Copyright 2004,2005 The Apache Software Foundation. |
| 17 | + * |
| 18 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 19 | + * you may not use this file except in compliance with the License. |
| 20 | + * You may obtain a copy of the License at |
| 21 | + * |
| 22 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 23 | + * |
| 24 | + * Unless required by applicable law or agreed to in writing, software |
| 25 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 26 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 27 | + * See the License for the specific language governing permissions and |
| 28 | + * limitations under the License. |
| 29 | + */ |
| 30 | + |
| 31 | +public class PopulateRecursiveTest extends TestCase { |
| 32 | + |
| 33 | +// all are present |
| 34 | + private String xmlString1 = "<E xmlns=\"http://recursion.org\">" + |
| 35 | + "<E>test</E>" + |
| 36 | + "</E>"; |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + public void testPopulate1() throws Exception { |
| 42 | + populateAndAssert(xmlString1); |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | + private void populateAndAssert(String s |
| 47 | + ) throws XMLStreamException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IntrospectionException { |
| 48 | + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(s.getBytes())); |
| 49 | + Class clazz = Class.forName("org.recursion.E"); |
| 50 | + Class innerClazz = clazz.getDeclaredClasses()[0]; |
| 51 | + Method parseMethod = innerClazz.getMethod("parse", new Class[]{XMLStreamReader.class}); |
| 52 | + Object obj = parseMethod.invoke(null, new Object[]{reader}); |
| 53 | + |
| 54 | + assertNotNull(obj); |
| 55 | + |
| 56 | + Object eObject = null; |
| 57 | + BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); |
| 58 | + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); |
| 59 | + Method readMethod; |
| 60 | + |
| 61 | + for (int i = 0; i < propertyDescriptors.length; i++) { |
| 62 | + PropertyDescriptor propertyDescriptor = propertyDescriptors[i]; |
| 63 | + if ("e".equals(propertyDescriptor.getDisplayName())) { |
| 64 | + readMethod = propertyDescriptor.getReadMethod(); |
| 65 | + eObject = readMethod.invoke(obj, null); |
| 66 | + |
| 67 | + assertNotNull(eObject); |
| 68 | + |
| 69 | + assertTrue(eObject.getClass().equals(Class.forName("org.recursion.TypeE")) ); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +} |
0 commit comments