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.digester;
18:
19: import java.io.StringReader;
20: import java.util.Map;
21:
22: import junit.framework.TestCase;
23:
24: import org.apache.commons.betwixt.ElementDescriptor;
25: import org.apache.commons.betwixt.XMLBeanInfo;
26: import org.apache.commons.betwixt.XMLIntrospector;
27: import org.apache.commons.betwixt.dotbetwixt.ExampleBean;
28:
29: /**
30: * Tests for reading dot betwist files.
31: * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
32: * @version $Revision: 155402 $
33: */
34: public class TestDigestMultiMapping extends TestCase {
35:
36: public void testDigestWithOptions() throws Exception {
37: String xml = "<?xml version='1.0'?>" + "<betwixt-config>"
38: + " <class name=\""
39: + TestDigestMultiMapping.class.getName() + "\">"
40: + " <element name=\"test-multi-mapping\">"
41: + " <option>" + " <name>test-key-a</name>"
42: + " <value>test-value-a</value>"
43: + " </option>" + " <option>"
44: + " <name>test-key-b</name>"
45: + " <value>test-value-b</value>"
46: + " </option>"
47: + " <element name=\"maps\" property=\"maps\">"
48: + " <option>"
49: + " <name>test-key-c</name>"
50: + " <value>test-value-c</value>"
51: + " </option>" + " </element>"
52: + " </element>" + " </class>" + "</betwixt-config>";
53:
54: MultiMappingBeanInfoDigester digester = new MultiMappingBeanInfoDigester();
55: digester.setXMLIntrospector(new XMLIntrospector());
56: digester.setBeanClass(ExampleBean.class);
57:
58: digester.parse(new StringReader(xml));
59: Map beanInfoMap = digester.getBeanInfoMap();
60: assertTrue(beanInfoMap
61: .containsKey(TestDigestMultiMapping.class));
62:
63: XMLBeanInfo xmlBeanInfo = (XMLBeanInfo) beanInfoMap
64: .get(TestDigestMultiMapping.class);
65: assertNotNull(xmlBeanInfo);
66:
67: ElementDescriptor baseDescriptor = xmlBeanInfo
68: .getElementDescriptor();
69:
70: assertEquals("Value one set on base", "test-value-a",
71: baseDescriptor.getOptions().getValue("test-key-a"));
72: assertEquals("Value two set on base", "test-value-b",
73: baseDescriptor.getOptions().getValue("test-key-b"));
74: assertNull("Value three not set on base", baseDescriptor
75: .getOptions().getValue("three"));
76:
77: assertEquals("Number of child elements", 1, baseDescriptor
78: .getElementDescriptors().length);
79:
80: ElementDescriptor childDescriptor = baseDescriptor
81: .getElementDescriptors()[0];
82: assertNull("Value one set on base", childDescriptor
83: .getOptions().getValue("test-key-a"));
84: assertNull("Value two set on base", childDescriptor
85: .getOptions().getValue("test-key-b"));
86: assertEquals("Value three set on child", "test-value-c",
87: childDescriptor.getOptions().getValue("test-key-c"));
88: }
89: }
|