1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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://commons.apache.org/'>Apache Commons Team</a>
32   * @version $Revision: 561314 $
33   */
34  public class TestDigestDotBetwixt extends TestCase {
35      
36      
37      public void testDigestWithOptions() throws Exception {
38          String xml = "<?xml version='1.0'?>" +
39              "<info>" +
40              "    <element name='example-bean'>" +
41              "        <option>" +
42              "           <name>one</name>" +
43              "           <value>value one</value>" +
44              "        </option>" +
45              "        <option>" +
46              "           <name>two</name>" +
47              "           <value>value two</value>" +
48              "        </option>" +
49              "        <element name='example' property='examples'>" +
50              "          <option>" +
51              "             <name>three</name>" +
52              "             <value>value three</value>" +
53              "          </option>" +
54              "        </element>" +
55              "    </element>" +
56              "</info>";
57              
58          XMLBeanInfoDigester digester = new XMLBeanInfoDigester();
59          digester.setXMLIntrospector(new XMLIntrospector());
60          digester.setBeanClass(ExampleBean.class);
61          XMLBeanInfo xmlBeanInfo = (XMLBeanInfo) digester.parse(new StringReader(xml));
62          ElementDescriptor baseDescriptor = xmlBeanInfo.getElementDescriptor();
63          
64          assertEquals("Value one set on base", "value one",  baseDescriptor.getOptions().getValue("one"));
65          assertEquals("Value two set on base", "value two",  baseDescriptor.getOptions().getValue("two"));
66          assertNull("Value three not set on base",  baseDescriptor.getOptions().getValue("three"));
67  
68          assertEquals("Number of child elements", 1, baseDescriptor.getElementDescriptors().length);
69          
70          ElementDescriptor childDescriptor = baseDescriptor.getElementDescriptors()[0];
71          assertNull("Value one set on base",  childDescriptor.getOptions().getValue("one"));
72          assertNull("Value two set on base",  childDescriptor.getOptions().getValue("two"));
73          assertEquals("Value three set on child", "value three",  childDescriptor.getOptions().getValue("three"));
74      }
75  }