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

public class TestJSON2XML {
    @Test
    public void testSimple() {
        try {
            String json = "{ \"a\": 1, \"b\": \"xxx\"}";
            String xml = ConvertJSON2XML.convert(json, "test");
            assertEquals("xml", "<?xml version=\"1.0\" ?><test><a>1</a><b>xxx</b></test>", xml);
        } catch (Exception e) {
            fail("Unexpected exception: " + e.getMessage());
        }
    }
    @Test
    public void testNested() {
        try {
            String json = "{ \"a\": 1, \"b\": \"xxx\", \"c\": { \"d\": 2, \"e\": \"yyy\" } }";
            String xml = ConvertJSON2XML.convert(json, "test");
            assertEquals("xml", "<?xml version=\"1.0\" ?><test><a>1</a><b>xxx</b><c><d>2</d><e>yyy</e></c></test>", xml);
        } catch (Exception e) {
            fail("Unexpected exception: " + e.getMessage());
        }
    }
}
