// 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.ConvertXML2JSON;

public class TestXML2JSON {
    @Test
    public void testSimple() {
        try {
            String xml = "<test><a>1</a><b>xxx</b></test>";
            String json = ConvertXML2JSON.convert(xml);
            assertEquals("json", "{ \"a\": 1, \"b\": \"xxx\" }", json);
        } 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 json = ConvertXML2JSON.convert(xml);
            assertEquals("json", "{ \"a\": 1, \"b\": \"xxx\", \"c\": { \"d\": 2, \"e\": \"yyy\" } }", json);
        } catch (Exception e) {
            fail("Unexpected exception: " + e.getMessage());
        }
    }
}
