/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.xml;

import java.io.File;
import java.io.IOException;
import net.ranides.assira.io.StringOutput;
import net.ranides.assira.text.Charsets;
import static net.ranides.assira.xml.XMLQuery.$;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class XMLWriterTest {
    
    private static final File INPUT = new File("src/test/resources/eclipse/artifacts.xml");

    @Test
    public void testWriter() throws IOException {
        XMLElement doc = $(INPUT).normalize().find("? //repository/mappings").first();
        doc.find("? //rule[2]/@output").first().content("under");
        
        String out1 = new XMLWriter().toString(doc);
        
        String out2 = new XMLWriter()
            .param(XMLOptions.DOCTYPE_PUBLIC, "yes")
            .param(XMLOptions.INDENT, "yes")
            .param(XMLOptions.INDENT_AMOUNT, "2")
            .toString(doc);
        
        StringOutput out3 = new StringOutput();
        new XMLWriter(out3)
            .param(XMLOptions.DOCTYPE_PUBLIC, "")
            .param(XMLOptions.INDENT, "yes")
            .param(XMLOptions.INDENT_AMOUNT, "2")
            .write(doc);
        
        String out4 = new XMLWriter()
            .indent(4)
            .toString(doc);
        
        System.out.printf("%n%s%n", out1);
        System.out.printf("%n%s%n", out2);
        System.out.printf("%n%s%n", out3.toString(Charsets.UTF8));
        System.out.printf("%n%s%n", out4);
        
        assertTrue(true);
    }
    
}
