01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.commons.betwixt;
19:
20: /**
21: * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
22: * @version $Revision: 438373 $
23: */
24: public class TestArrayMaps extends AbstractTestCase {
25:
26: private static final AddressBean[] EMPTY_ADDRESS_ARRAY = {};
27: private static final Class ADDRESS_ARRAY_CLASS = EMPTY_ADDRESS_ARRAY
28: .getClass();
29:
30: public TestArrayMaps(String testName) {
31: super (testName);
32: }
33:
34: public void testIntrospection() throws Exception {
35: XMLIntrospector introspector = new XMLIntrospector();
36: introspector.getConfiguration()
37: .setAttributesForPrimitives(true);
38:
39: XMLBeanInfo xmlBeanInfo = introspector
40: .introspect(AddressBookWithMapArrayAdder.class);
41:
42: ElementDescriptor beanDescriptor = xmlBeanInfo
43: .getElementDescriptor();
44: ElementDescriptor[] childDescriptors = beanDescriptor
45: .getElementDescriptors();
46: assertEquals("Only one child element", 1,
47: childDescriptors.length);
48: ElementDescriptor wrappingDescriptor = childDescriptors[0];
49: ElementDescriptor[] wrappingChildDescriptors = wrappingDescriptor
50: .getElementDescriptors();
51: assertEquals("One child descriptor", 1,
52: wrappingChildDescriptors.length);
53: ElementDescriptor entryDescriptor = wrappingChildDescriptors[0];
54: ElementDescriptor[] entryChildDescriptors = entryDescriptor
55: .getElementDescriptors();
56: assertEquals("Two child descriptors", 2,
57: entryChildDescriptors.length);
58: ElementDescriptor keyDescriptor = null;
59: ElementDescriptor valueDescriptor = null;
60: if ("key".equals(entryChildDescriptors[0].getQualifiedName())) {
61: keyDescriptor = entryChildDescriptors[0];
62: }
63: if ("value".equals(entryChildDescriptors[0].getQualifiedName())) {
64: valueDescriptor = entryChildDescriptors[0];
65: }
66: if ("key".equals(entryChildDescriptors[1].getQualifiedName())) {
67: keyDescriptor = entryChildDescriptors[1];
68: }
69: if ("value".equals(entryChildDescriptors[1].getQualifiedName())) {
70: valueDescriptor = entryChildDescriptors[1];
71: }
72:
73: assertNotNull("Expected key descriptor", keyDescriptor);
74: assertNotNull("Expected value descriptor", valueDescriptor);
75: assertNotNull("Expected key property type", keyDescriptor
76: .getPropertyType());
77: assertNotNull("Expected value property type", valueDescriptor
78: .getPropertyType());
79:
80: ElementDescriptor[] childValueDescriptors = valueDescriptor
81: .getElementDescriptors();
82: assertEquals("One hollow child descriptor for array", 1,
83: childValueDescriptors.length);
84: ElementDescriptor hollowValueDescriptor = childValueDescriptors[0];
85: assertEquals("Child descriptor is hollow", true,
86: hollowValueDescriptor.isHollow());
87: assertEquals(
88: "Child descriptor has AddressBean[] property type",
89: ADDRESS_ARRAY_CLASS, hollowValueDescriptor
90: .getPropertyType());
91: assertEquals(
92: "Child descriptor has AddressBean[] singular property type",
93: ADDRESS_ARRAY_CLASS, hollowValueDescriptor
94: .getSingularPropertyType());
95: }
96:
97: }
|