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.digester;
19:
20: import java.io.StringReader;
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: 438373 $
33: */
34: public class TestDigestDotBetwixt extends TestCase {
35:
36: public void testDigestWithOptions() throws Exception {
37: String xml = "<?xml version='1.0'?>"
38: + "<info>"
39: + " <element name='example-bean'>"
40: + " <option>"
41: + " <name>one</name>"
42: + " <value>value one</value>"
43: + " </option>"
44: + " <option>"
45: + " <name>two</name>"
46: + " <value>value two</value>"
47: + " </option>"
48: + " <element name='example' property='examples'>"
49: + " <option>"
50: + " <name>three</name>"
51: + " <value>value three</value>"
52: + " </option>" + " </element>"
53: + " </element>" + "</info>";
54:
55: XMLBeanInfoDigester digester = new XMLBeanInfoDigester();
56: digester.setXMLIntrospector(new XMLIntrospector());
57: digester.setBeanClass(ExampleBean.class);
58: XMLBeanInfo xmlBeanInfo = (XMLBeanInfo) digester
59: .parse(new StringReader(xml));
60: ElementDescriptor baseDescriptor = xmlBeanInfo
61: .getElementDescriptor();
62:
63: assertEquals("Value one set on base", "value one",
64: baseDescriptor.getOptions().getValue("one"));
65: assertEquals("Value two set on base", "value two",
66: baseDescriptor.getOptions().getValue("two"));
67: assertNull("Value three not set on base", baseDescriptor
68: .getOptions().getValue("three"));
69:
70: assertEquals("Number of child elements", 1, baseDescriptor
71: .getElementDescriptors().length);
72:
73: ElementDescriptor childDescriptor = baseDescriptor
74: .getElementDescriptors()[0];
75: assertNull("Value one set on base", childDescriptor
76: .getOptions().getValue("one"));
77: assertNull("Value two set on base", childDescriptor
78: .getOptions().getValue("two"));
79: assertEquals("Value three set on child", "value three",
80: childDescriptor.getOptions().getValue("three"));
81: }
82: }
|