KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > xml > SchemalessTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.xml;
8
9 import java.io.StringReader JavaDoc;
10 import java.io.StringWriter JavaDoc;
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 /**
20  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
21  * @version <tt>$Revision: 1.1.2.3 $</tt>
22  */

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 JavaDoc localName)
33    {
34       super(localName);
35    }
36
37    public void testSchemalessMarshalling() throws Exception JavaDoc
38    {
39       Person person = Person.newInstance();
40       StringWriter JavaDoc writer = new StringWriter JavaDoc();
41
42       SchemalessMarshaller marshaller = new SchemalessMarshaller();
43       marshaller.marshal(person, writer);
44
45       log.info("marshalled:\n" + writer.getBuffer());
46
47       StringReader JavaDoc reader = new StringReader JavaDoc(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