KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > digester > TestDigestDotBetwixt


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16  
17 package org.apache.commons.betwixt.digester;
18
19 import java.io.StringReader JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.apache.commons.betwixt.ElementDescriptor;
24 import org.apache.commons.betwixt.XMLBeanInfo;
25 import org.apache.commons.betwixt.XMLIntrospector;
26 import org.apache.commons.betwixt.dotbetwixt.ExampleBean;
27
28 /**
29  * Tests for reading dot betwist files.
30  * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
31  * @version $Revision: 1.2 $
32  */

33 public class TestDigestDotBetwixt extends TestCase {
34     
35     
36     public void testDigestWithOptions() throws Exception JavaDoc {
37         String JavaDoc 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>" +
53             " </element>" +
54             " </element>" +
55             "</info>";
56             
57         XMLBeanInfoDigester digester = new XMLBeanInfoDigester();
58         digester.setXMLIntrospector(new XMLIntrospector());
59         digester.setBeanClass(ExampleBean.class);
60         XMLBeanInfo xmlBeanInfo = (XMLBeanInfo) digester.parse(new StringReader JavaDoc(xml));
61         ElementDescriptor baseDescriptor = xmlBeanInfo.getElementDescriptor();
62         
63         assertEquals("Value one set on base", "value one", baseDescriptor.getOptions().getValue("one"));
64         assertEquals("Value two set on base", "value two", baseDescriptor.getOptions().getValue("two"));
65         assertNull("Value three not set on base", baseDescriptor.getOptions().getValue("three"));
66
67         assertEquals("Number of child elements", 1, baseDescriptor.getElementDescriptors().length);
68         
69         ElementDescriptor childDescriptor = baseDescriptor.getElementDescriptors()[0];
70         assertNull("Value one set on base", childDescriptor.getOptions().getValue("one"));
71         assertNull("Value two set on base", childDescriptor.getOptions().getValue("two"));
72         assertEquals("Value three set on child", "value three", childDescriptor.getOptions().getValue("three"));
73     }
74 }
75
Popular Tags