use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class XMLNativeFunctionTest method testToJsonWithMultipleAttributesNamespacesWithOptions.
@Test
public void testToJsonWithMultipleAttributesNamespacesWithOptions() {
String xmlStr = "<ns0:bookStore status=\"online\" xmlns:ns0=\"http://sample0.com/test\" " + "xmlns:ns1=\"http://sample1.com/test\"><ns0:storeName>foo</ns0:storeName>" + "<ns3:postalCode xmlns:ns3=\"http://sample3.com/test\">94</ns3:postalCode>" + "<ns0:isOpen>true</ns0:isOpen><ns2:address xmlns:ns2=\"http://sample2.com/test\">" + "<ns2:street>foo</ns2:street><ns2:city>111</ns2:city><ns2:country>true</ns2:country>" + "</ns2:address><ns4:codes xmlns:ns4=\"http://sample4.com/test\"><ns4:item>4</ns4:item><ns4:item>8" + "</ns4:item><ns4:item>9</ns4:item></ns4:codes></ns0:bookStore>";
BValue[] args = { new BXMLItem(xmlStr) };
BValue[] returns = BRunUtil.invoke(result, "testToJSONWithoutNamespace", args);
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(returns[0].stringValue(), "{\"bookStore\":{\"@status\":\"online\"," + "\"storeName\":\"foo\",\"postalCode\":\"94\",\"isOpen\":\"true\",\"address\":{\"street\":\"foo\"," + "\"city\":\"111\",\"country\":\"true\"},\"codes\":{\"item\":[\"4\",\"8\",\"9\"]}}}");
}
use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class XMLNativeFunctionTest method testToJsonWithComplexObjectWithMultipleAttributes.
@Test
public void testToJsonWithComplexObjectWithMultipleAttributes() {
String xmlStr = "<bookStore status = \"online\" id = \"5\"><storeName>foo</storeName><postalCode>94" + "</postalCode><isOpen>true</isOpen><address><street>foo</street>" + "<city code = \"A\" reg = \"C\">94</city><country>true</country></address>" + "<codes quality=\"b\" type = \"0\"><item>4</item><item>8</item><item>9</item></codes></bookStore>";
BValue[] args = { new BXMLItem(xmlStr) };
BValue[] returns = BRunUtil.invoke(result, "testToJSON", args);
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(returns[0].stringValue(), "{\"bookStore\":{\"@status\":\"online\",\"@id\":\"5\"," + "\"storeName\":\"foo\",\"postalCode\":\"94\",\"isOpen\":\"true\",\"address\":{\"street\":\"foo\"," + "\"country\":\"true\",\"city\":{\"@code\":\"A\",\"@reg\":\"C\",\"#text\":\"94\"}}," + "\"codes\":{\"@quality\":\"b\",\"@type\":\"0\",\"item\":[\"4\",\"8\",\"9\"]}}}");
}
use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class XMLNativeFunctionTest method testToJsonWithXMLInMiddle.
@Test
public void testToJsonWithXMLInMiddle() {
String xmlStr = "<person><name>Jack</name><age>40</age><!-- some comment --></person>";
BValue[] args = { new BXMLItem(xmlStr) };
BValue[] returns = BRunUtil.invoke(result, "testToJSON", args);
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(returns[0].stringValue(), "{\"person\":{\"name\":\"Jack\",\"age\":\"40\"}}");
}
use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class XMLNativeFunctionTest method testToJsonXMLWithSingleEmptyElementAndAttributes.
@Test
public void testToJsonXMLWithSingleEmptyElementAndAttributes() {
String xmlStr = "<ns0:name test=\"5\" xmlns:ns0=\"http://sample0.com/test\"></ns0:name>";
BValue[] args = { new BXMLItem(xmlStr) };
BValue[] returns = BRunUtil.invoke(result, "testToJSON", args);
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(returns[0].stringValue(), "{\"ns0:name\":{\"@xmlns:ns0\":\"http://sample0.com/test\"," + "\"@test\":\"5\"}}");
}
use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class XMLNativeFunctionTest method testToJsonForSingleElement.
@Test
public void testToJsonForSingleElement() {
String xmlStr = "<key>value</key>";
BValue[] args = { new BXMLItem(xmlStr) };
BValue[] returns = BRunUtil.invoke(result, "testToJSON", args);
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(returns[0].stringValue(), "{\"key\":\"value\"}");
}
Aggregations