1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.betwixt;
19
20
21
22
23
24 public class TestArrayMaps extends AbstractTestCase {
25
26 private static final AddressBean[] EMPTY_ADDRESS_ARRAY = {};
27 private static final Class ADDRESS_ARRAY_CLASS
28 = EMPTY_ADDRESS_ARRAY.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().setAttributesForPrimitives(true);
37
38 XMLBeanInfo xmlBeanInfo
39 = introspector.introspect(AddressBookWithMapArrayAdder.class);
40
41 ElementDescriptor beanDescriptor = xmlBeanInfo.getElementDescriptor();
42 ElementDescriptor[] childDescriptors = beanDescriptor.getElementDescriptors();
43 assertEquals("Only one child element", 1, childDescriptors.length);
44 ElementDescriptor wrappingDescriptor = childDescriptors[0];
45 ElementDescriptor[] wrappingChildDescriptors = wrappingDescriptor.getElementDescriptors();
46 assertEquals("One child descriptor", 1, wrappingChildDescriptors.length);
47 ElementDescriptor entryDescriptor = wrappingChildDescriptors[0];
48 ElementDescriptor[] entryChildDescriptors = entryDescriptor.getElementDescriptors();
49 assertEquals("Two child descriptors", 2, entryChildDescriptors.length);
50 ElementDescriptor keyDescriptor = null;
51 ElementDescriptor valueDescriptor = null;
52 if ("key".equals(entryChildDescriptors[0].getQualifiedName())) {
53 keyDescriptor = entryChildDescriptors[0];
54 }
55 if ("value".equals(entryChildDescriptors[0].getQualifiedName())) {
56 valueDescriptor = entryChildDescriptors[0];
57 }
58 if ("key".equals(entryChildDescriptors[1].getQualifiedName())) {
59 keyDescriptor = entryChildDescriptors[1];
60 }
61 if ("value".equals(entryChildDescriptors[1].getQualifiedName())) {
62 valueDescriptor = entryChildDescriptors[1];
63 }
64
65 assertNotNull("Expected key descriptor", keyDescriptor);
66 assertNotNull("Expected value descriptor", valueDescriptor);
67 assertNotNull("Expected key property type", keyDescriptor.getPropertyType());
68 assertNotNull("Expected value property type", valueDescriptor.getPropertyType());
69
70 ElementDescriptor[] childValueDescriptors = valueDescriptor.getElementDescriptors();
71 assertEquals("One hollow child descriptor for array", 1, childValueDescriptors.length);
72 ElementDescriptor hollowValueDescriptor = childValueDescriptors[0];
73 assertEquals("Child descriptor is hollow", true, hollowValueDescriptor.isHollow());
74 assertEquals(
75 "Child descriptor has AddressBean[] property type",
76 ADDRESS_ARRAY_CLASS,
77 hollowValueDescriptor.getPropertyType());
78 assertEquals(
79 "Child descriptor has AddressBean[] singular property type",
80 ADDRESS_ARRAY_CLASS,
81 hollowValueDescriptor.getSingularPropertyType());
82 }
83
84 }