From: Alex L. <al...@jb...> - 2006-01-17 11:47:50
|
User: aloubyansky Date: 06/01/17 06:47:36 Modified: src/main/org/jboss/test/xml MiscUnitTestCase.java SimpleTypeBindingUnitTestCase.java Log: tests for JBXB-47 'marshalled string values should be normalized' Revision Changes Path 1.38 +55 -1 jbosstest/src/main/org/jboss/test/xml/MiscUnitTestCase.java (In the diff below, changes in quantity of whitespace are not shown.) Index: MiscUnitTestCase.java =================================================================== RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/xml/MiscUnitTestCase.java,v retrieving revision 1.37 retrieving revision 1.38 diff -u -b -r1.37 -r1.38 --- MiscUnitTestCase.java 7 Dec 2005 15:22:08 -0000 1.37 +++ MiscUnitTestCase.java 17 Jan 2006 11:47:36 -0000 1.38 @@ -42,6 +42,7 @@ import org.jboss.test.xml.immutable.Child3; import org.jboss.test.xml.immutable.ImmutableChoice; import org.jboss.test.xml.immutable.Parent; +import org.jboss.test.xml.person.Person; import org.jboss.xb.binding.MappingObjectModelFactory; import org.jboss.xb.binding.MappingObjectModelProvider; import org.jboss.xb.binding.MetadataDrivenObjectModelFactory; @@ -65,7 +66,7 @@ * Various tests that should later be categorized. * * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.37 $</tt> + * @version <tt>$Revision: 1.38 $</tt> */ public class MiscUnitTestCase extends XbTestCaseBase @@ -77,6 +78,59 @@ super(localName); } + public void testStringNormalization() throws Exception + { + String xsd = "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'" + + " targetNamespace='http://www.jboss.org/test/xml/snorm'" + + " xmlns='http://www.jboss.org/test/xml/snorm'" + + " xmlns:jbxb='" + Constants.NS_JBXB + "'" + + " version='1.0'>" + + "<xsd:complexType name='ctype'>" + + " <xsd:annotation>" + + " <xsd:appinfo>" + + " <jbxb:class impl='" + Person.class.getName() + "'/>" + + " <jbxb:characters>" + + " <jbxb:property name='lastName'/>" + + " </jbxb:characters>" + + " </xsd:appinfo>" + + " </xsd:annotation>" + + " <xsd:simpleContent>" + + " <xsd:extension base='xsd:string'>" + + " <xsd:attribute name='attr' type='xsd:string'>" + + " <xsd:annotation>" + + " <xsd:appinfo>" + + " <jbxb:property name='firstName'/>" + + " </xsd:appinfo>" + + " </xsd:annotation>" + + " </xsd:attribute>" + + " </xsd:extension>" + + " </xsd:simpleContent>" + + "</xsd:complexType>" + + "<xsd:element name='person' type='ctype'/>" + + "</xsd:schema>"; + + String xml = "<person" + + " xmlns='http://www.jboss.org/test/xml/snorm'" + + " attr=''"&><'><>&"'</person>"; + + String lastName = "<>&\"'"; + String firstName = "'\"&><"; + SchemaBinding schema = XsdBinder.bind(new StringReader(xsd), null); + Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller(); + Object unmarshalled = unmarshaller.unmarshal(new StringReader(xml), schema); + assertNotNull(unmarshalled); + assertTrue(unmarshalled instanceof Person); + Person person = (Person)unmarshalled; + assertEquals(firstName, person.getFirstName()); + assertEquals(lastName, person.getLastName()); + + StringWriter writer = new StringWriter(); + MarshallerImpl marshaller = new MarshallerImpl(); + marshaller.marshal(schema, null, person, writer); + String marshalled = writer.getBuffer().toString(); + assertXmlEqual(xml, marshalled); + } + public void testImmutableXerces() throws Exception { immutableTest(new XercesXsMarshaller()); 1.13 +1 -25 jbosstest/src/main/org/jboss/test/xml/SimpleTypeBindingUnitTestCase.java (In the diff below, changes in quantity of whitespace are not shown.) Index: SimpleTypeBindingUnitTestCase.java =================================================================== RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/xml/SimpleTypeBindingUnitTestCase.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -b -r1.12 -r1.13 --- SimpleTypeBindingUnitTestCase.java 16 Jan 2006 14:47:35 -0000 1.12 +++ SimpleTypeBindingUnitTestCase.java 17 Jan 2006 11:47:36 -0000 1.13 @@ -38,7 +38,7 @@ /** * @author <a href="mailto:al...@jb...">Alexey Loubyansky</a> - * @version <tt>$Revision: 1.12 $</tt> + * @version <tt>$Revision: 1.13 $</tt> */ public class SimpleTypeBindingUnitTestCase extends TestCase @@ -488,28 +488,4 @@ assertNotNull(marshalled); assertEquals("true true false true", marshalled); } - - public void testStringMarshalling() throws Exception - { - String res = SimpleTypeBindings.marshal(SimpleTypeBindings.XS_STRING_NAME, "AsIs", null); - assertEquals ("AsIs", res); - - // Please see 4.6 Predefined Entities for a complete list - // http://www.w3.org/TR/REC-xml/#sec-predefined-ent - - res = SimpleTypeBindings.marshal(SimpleTypeBindings.XS_STRING_NAME, "\"Quoted\"", null); - assertEquals (""Quoted"", res); - } - - public void testStringUnmarshalling() throws Exception - { - String res = (String)SimpleTypeBindings.unmarshal(SimpleTypeBindings.XS_STRING_NAME, "AsIs", null); - assertEquals ("AsIs", res); - - // Please see 4.6 Predefined Entities for a complete list - // http://www.w3.org/TR/REC-xml/#sec-predefined-ent - - res = (String)SimpleTypeBindings.unmarshal(SimpleTypeBindings.XS_STRING_NAME, ""Quoted"", null); - assertEquals ("\"Quoted\"", res); - } } |