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: package org.apache.commons.betwixt.dotbetwixt;
18:
19: import java.io.StringReader;
20:
21: import org.apache.commons.betwixt.AbstractTestCase;
22: import org.apache.commons.betwixt.AddressBean;
23: import org.apache.commons.betwixt.ElementDescriptor;
24: import org.apache.commons.betwixt.XMLBeanInfo;
25: import org.apache.commons.betwixt.XMLIntrospector;
26: import org.xml.sax.InputSource;
27:
28: /**
29: * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a>
30: */
31: public class TestMultiMap extends AbstractTestCase {
32:
33: public TestMultiMap(String testName) {
34: super (testName);
35: }
36:
37: private static final String MAPPING = "<?xml version='1.0'?>"
38: + " <betwixt-config>"
39: + " <class name='org.apache.commons.betwixt.PartyBean'>"
40: + " <element name='party'>"
41: + " <element name='the-excuse' property='excuse'/>"
42: + " <element name='location' property='venue'/> "
43: + " <element name='time' property='fromHour'/>"
44: + " </element>"
45: + " </class>"
46: + " <class name='org.apache.commons.betwixt.AddressBean'>"
47: + " <element name='not-address'>"
48: + " <element name='not-street' property='street'/>"
49: + " <element name='not-city' property='city'/>"
50: + " <element name='not-code' property='code'/>"
51: + " <element name='not-country' property='country'/>"
52: + " </element>"
53: + " </class>"
54: + " <class name='org.apache.commons.betwixt.dotbetwixt.SimpleTestBean'>"
55: + " <element name='jelly'>"
56: + " <element name='wibble' property='alpha'/>"
57: + " <element name='wobble' property='beta'/>"
58: + " </element>" + " </class>"
59: + " </betwixt-config>";
60:
61: public void testRegisterMultiMapping() throws Exception {
62: XMLIntrospector xmlIntrospector = new XMLIntrospector();
63: Class[] mapped = xmlIntrospector.register(new InputSource(
64: new StringReader(MAPPING)));
65:
66: assertEquals("Mapped classes", 3, mapped.length);
67:
68: XMLBeanInfo beanInfo = xmlIntrospector
69: .introspect(AddressBean.class);
70: assertNotNull("Bean info mapping", beanInfo);
71: ElementDescriptor descriptor = beanInfo.getElementDescriptor();
72: assertEquals("Root element name", "not-address", descriptor
73: .getLocalName());
74: ElementDescriptor[] childDescriptors = descriptor
75: .getElementDescriptors();
76: assertEquals("4 child elements", 4, childDescriptors.length);
77: assertEquals("First element", "not-street", childDescriptors[0]
78: .getLocalName());
79: assertEquals("Second element", "not-city", childDescriptors[1]
80: .getLocalName());
81: assertEquals("Third element", "not-code", childDescriptors[2]
82: .getLocalName());
83: assertEquals("Forth element", "not-country",
84: childDescriptors[3].getLocalName());
85:
86: beanInfo = xmlIntrospector.introspect(SimpleTestBean.class);
87: assertNotNull("Bean info mapping", beanInfo);
88: descriptor = beanInfo.getElementDescriptor();
89: assertEquals("Root element name", "jelly", descriptor
90: .getLocalName());
91: childDescriptors = descriptor.getElementDescriptors();
92: assertEquals("Child elements", 2, childDescriptors.length);
93: assertEquals("First element", "wibble", childDescriptors[0]
94: .getLocalName());
95: assertEquals("Second element", "wobble", childDescriptors[1]
96: .getLocalName());
97:
98: }
99: }
|