1 16 17 package org.apache.commons.betwixt.digester; 18 19 import java.io.StringReader ; 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 33 public class TestDigestDotBetwixt extends TestCase { 34 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>" + 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 (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 |