From: Alex L. <al...@jb...> - 2005-11-23 11:19:04
|
User: aloubyansky Date: 05/11/23 05:41:07 Modified: src/main/org/jboss/test/xml AttributesUnitTestCase.java JbxbCharactersUnitTestCase.java Log: more tests for binding simple content of a complex type to a property Revision Changes Path 1.2 +1 -5 jbosstest/src/main/org/jboss/test/xml/AttributesUnitTestCase.java (In the diff below, changes in quantity of whitespace are not shown.) Index: AttributesUnitTestCase.java =================================================================== RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/xml/AttributesUnitTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- AttributesUnitTestCase.java 7 Nov 2005 12:28:52 -0000 1.1 +++ AttributesUnitTestCase.java 23 Nov 2005 10:41:07 -0000 1.2 @@ -41,7 +41,7 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.1 $</tt> + * @version <tt>$Revision: 1.2 $</tt> */ public class AttributesUnitTestCase extends XbTestCaseBase @@ -83,8 +83,6 @@ " </xsd:appinfo>" + " </xsd:annotation>" + " <xsd:complexType>" + - " <xsd:simpleContent>" + - " <xsd:extension base='xsd:string'>" + " <xsd:attribute name='" + UNQUALIFIED_NAME + "' type='xsd:string'/>" + @@ -94,8 +92,6 @@ " <xsd:attribute ref='attrs2:" + FOREIGNER_NAME + "'/>" + - " </xsd:extension>" + - " </xsd:simpleContent>" + " </xsd:complexType>" + "</xsd:element>" + "</xsd:schema>"; 1.5 +64 -15 jbosstest/src/main/org/jboss/test/xml/JbxbCharactersUnitTestCase.java (In the diff below, changes in quantity of whitespace are not shown.) Index: JbxbCharactersUnitTestCase.java =================================================================== RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/xml/JbxbCharactersUnitTestCase.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -b -r1.4 -r1.5 --- JbxbCharactersUnitTestCase.java 17 Nov 2005 13:00:25 -0000 1.4 +++ JbxbCharactersUnitTestCase.java 23 Nov 2005 10:41:07 -0000 1.5 @@ -22,16 +22,21 @@ package org.jboss.test.xml; import java.io.FileReader; -import java.io.StringReader; import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; import java.net.URL; -import org.jboss.test.xml.jbxb.characters.Binding; import org.jboss.test.BaseTestCase; +import org.jboss.test.xml.jbxb.characters.Binding; +import org.jboss.xb.binding.JBossXBException; +import org.jboss.xb.binding.MappingObjectModelProvider; import org.jboss.xb.binding.Unmarshaller; import org.jboss.xb.binding.UnmarshallerFactory; -import org.jboss.xb.binding.JBossXBException; +import org.jboss.xb.binding.XercesXsMarshaller; +import org.jboss.xb.binding.Marshaller; import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding; import org.jboss.xb.binding.sunday.unmarshalling.XsdBinder; +import org.jboss.xb.binding.sunday.MarshallerImpl; /** @@ -39,11 +44,17 @@ * into org.jboss.test.xml.jbxb.characters.Binding. * * @author Sco...@jb... - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class JbxbCharactersUnitTestCase extends BaseTestCase { + private static final String XML_VALUE4 = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<ns_binding:binding xmlns:ns_binding=\"urn:jboss:jbxb-characters-schema1\" name=\"root\">" + + "<ns_binding:value4>val4</ns_binding:value4>" + + "</ns_binding:binding>"; + public JbxbCharactersUnitTestCase(String name) { super(name); @@ -56,7 +67,7 @@ } */ - public void testMain() throws Exception + public void testMainUnmarshalling() throws Exception { String res = getPath("xml/jbxb/characters/testSchema1.xml").getFile(); FileReader xmlReader = new FileReader(res); @@ -67,16 +78,16 @@ assertEquals("Binding.text = value1 ", "value1", binding.getText()); } - public void testValue2() throws Exception + public void testValue2Unmarshalling() throws Exception { - StringReader xmlReader = new StringReader( - "<?xml version='1.0' encoding='UTF-8'?>" + + StringReader xmlReader = new StringReader("<?xml version='1.0' encoding='UTF-8'?>" + "<binding xmlns='urn:jboss:jbxb-characters-schema1'" + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" + " xsi:schemaLocation='urn:jboss:jbxb-characters-schema1 schema1.xsd'" + " name='root'>" + " <value2>value2</value2>" + - "</binding>"); + "</binding>" + ); Binding binding = unmarshal(xmlReader); @@ -86,16 +97,16 @@ assertEquals("Binding.text2 = value2 ", "value2", value2.text); } - public void testValue3() throws Exception + public void testValue3Unmarshalling() throws Exception { - StringReader xmlReader = new StringReader( - "<?xml version='1.0' encoding='UTF-8'?>" + + StringReader xmlReader = new StringReader("<?xml version='1.0' encoding='UTF-8'?>" + "<binding xmlns='urn:jboss:jbxb-characters-schema1'" + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" + " xsi:schemaLocation='urn:jboss:jbxb-characters-schema1 schema1.xsd'" + " name='root'>" + " <value3 attr='attr'>value3</value3>" + - "</binding>"); + "</binding>" + ); Binding binding = unmarshal(xmlReader); @@ -106,6 +117,44 @@ assertEquals("attr", value3.attr); } + public void testValue4Unmarshalling() throws Exception + { + Binding binding = unmarshal(new StringReader(XML_VALUE4)); + assertEquals("Binding.name = root ", "root", binding.getName()); + Binding.Value4 value4 = binding.value4; + assertNotNull(value4); + assertEquals("val4", value4.value); + + } + + public void testValue4MarshallingXerces() throws Exception + { + Binding binding = new Binding(); + binding.setName("root"); + binding.value4 = new Binding.Value4("val4"); + StringWriter writer = new StringWriter(); + XercesXsMarshaller marshaller = new XercesXsMarshaller(); + marshaller.setProperty(Marshaller.PROP_OUTPUT_INDENTATION, "false"); + String file = getPath("xml/jbxb/characters/schema1.xsd").getFile(); + marshaller.marshal(new FileReader(file), new MappingObjectModelProvider(), binding, writer); + String xml = writer.getBuffer().toString(); + assertEquals(XML_VALUE4, xml); + } + + public void testValue4MarshallingSunday() throws Exception + { + Binding binding = new Binding(); + binding.setName("root"); + binding.value4 = new Binding.Value4("val4"); + StringWriter writer = new StringWriter(); + MarshallerImpl marshaller = new MarshallerImpl(); + marshaller.setProperty(Marshaller.PROP_OUTPUT_INDENTATION, "false"); + String file = getPath("xml/jbxb/characters/schema1.xsd").getFile(); + marshaller.marshal(new FileReader(file), new MappingObjectModelProvider(), binding, writer); + String xml = writer.getBuffer().toString(); + assertEquals(XML_VALUE4, xml); + } + // Private private Binding unmarshal(Reader xmlReader) @@ -116,7 +165,7 @@ schemaBinding.setIgnoreUnresolvedFieldOrClass(true); Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller(); - Binding binding = (Binding) unmarshaller.unmarshal(xmlReader, schemaBinding); + Binding binding = (Binding)unmarshaller.unmarshal(xmlReader, schemaBinding); return binding; } |