package test;

import junit.framework.TestCase;
import org.exolab.castor.xml.*;

import java.io.*;

/**
 * <p/>
 * Created Jan 23, 2009 1:03:31 PM
 *
 * @author lchu
 */
public class CastorMixedTest extends TestCase {
    public void testSetXmlContextToMixed() throws Exception {
        XMLContext xmlContext = new XMLContext();
        xmlContext.setProperty("org.exolab.castor.xml.naming", "mixed");
        xmlContext.addClass(Foo.class);

        StringWriter writer = new StringWriter();
        Marshaller marshaller = xmlContext.createMarshaller();
        marshaller.setWriter(writer);
        marshaller.marshal(new Foo());

        assertEquals(
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<castorMixedTest$Foo barBar=\"0\"/>",
                writer.toString());
    }

    public void testSetMarshallerToMixed() throws Exception {
        XMLContext xmlContext = new XMLContext();
        xmlContext.addClass(Foo.class);

        StringWriter writer = new StringWriter();
        Marshaller marshaller = xmlContext.createMarshaller();
        marshaller.setWriter(writer);
        marshaller.setProperty("org.exolab.castor.xml.naming", "mixed");
        marshaller.marshal(new Foo());

        assertEquals(
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<castorMixedTest$Foo barBar=\"0\"/>",
                writer.toString());
    }

    public void testSetNewMarshallerToMixed() throws Exception {
        StringWriter writer = new StringWriter();
        Marshaller marshaller = new Marshaller();
        marshaller.setWriter(writer);
        marshaller.setProperty("org.exolab.castor.xml.naming", "mixed");
        marshaller.marshal(new Foo());

        assertEquals(
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<castorMixedTest$Foo barBar=\"0\"/>",
                writer.toString());
    }

    public static class Foo {
        public int barBar;
    }
}

