1 7 package org.jboss.test.xml; 8 9 import java.io.StringReader ; 10 import java.io.StringWriter ; 11 import junit.framework.TestCase; 12 import org.jboss.logging.Logger; 13 import org.jboss.test.xml.person.Person; 14 import org.jboss.xb.binding.SchemalessMarshaller; 15 import org.jboss.xb.binding.SchemalessObjectModelFactory; 16 import org.jboss.xb.binding.Unmarshaller; 17 import org.jboss.xb.binding.UnmarshallerFactory; 18 19 23 public class SchemalessTestCase 24 extends TestCase 25 { 26 private static final Logger log = Logger.getLogger(SchemalessTestCase.class); 27 28 public SchemalessTestCase() 29 { 30 } 31 32 public SchemalessTestCase(String localName) 33 { 34 super(localName); 35 } 36 37 public void testSchemalessMarshalling() throws Exception 38 { 39 Person person = Person.newInstance(); 40 StringWriter writer = new StringWriter (); 41 42 SchemalessMarshaller marshaller = new SchemalessMarshaller(); 43 marshaller.marshal(person, writer); 44 45 log.info("marshalled:\n" + writer.getBuffer()); 46 47 StringReader reader = new StringReader (writer.getBuffer().toString()); 48 Unmarshaller unmarshaller = UnmarshallerFactory.newInstance() 49 .newUnmarshaller(); 50 SchemalessObjectModelFactory factory = new SchemalessObjectModelFactory(); 51 Person unmarshalled = (Person)unmarshaller.unmarshal(reader, factory, null); 52 53 log.info("unmarshalled: " + unmarshalled); 54 assertEquals(person, unmarshalled); 55 } 56 57 } 58 | Popular Tags |