// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package routing.demo.convert.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.Test;

import routing.demo.convert.ConvertXML2CSV;

public class TestXML2CSV {
    @Test
    public void testSimple() {
        try {
            String xml = "<test><a>1</a><b>xxx</b></test>";
            String csv = ConvertXML2CSV.convert(xml, ',', '"');
            assertEquals("csv", "1,\"xxx\"", csv);
        } catch (Exception e) {
            fail("Unexpected exception: " + e.getMessage());
        }
    }
    @Test
    public void testTricky() {
        try {
            String xml = "<test><a>1</a><b>xxx</b><c>y,y</c><d>z\"z</d></test>";
            String csv = ConvertXML2CSV.convert(xml, ',', '"');
            assertEquals("csv", "1,\"xxx\",\"y,y\",\"z\"\"z\"", csv);
        } catch (Exception e) {
            fail("Unexpected exception: " + e.getMessage());
        }
    }
    @Test
    public void testNested() {
        try {
            String xml = "<test><a>1</a><b>xxx</b><c><d>2</d><e>yyy</e></c></test>";
            String csv = ConvertXML2CSV.convert(xml, ',', '"');
            fail("Missing exception conerting from " + xml + " to " + csv);
        } catch (Exception e) {
            // nothing
        }
    }
}
