use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class JSONTest method testToXMLJsonWithStringValue.
@Test(description = "Convert a json object with string value only")
public void testToXMLJsonWithStringValue() {
BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLStringValue");
Assert.assertTrue(returns[0] instanceof BXML);
OMNode returnElement = ((BXMLItem) returns[0]).value();
Assert.assertEquals(((OMText) returnElement).getText(), "value");
}
use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class BMapValueTest method testBMapToString.
@Test(description = "Testing convert map values to string")
public void testBMapToString() {
BMap<String, BRefType> map = new BMap<>();
map.put(new String("key1"), new BInteger(1));
map.put(new String("key2"), new BString("foo"));
map.put(new String("key3"), new BXMLItem("<bar>hello</bar>"));
Assert.assertEquals(map.stringValue(), "{\"key1\":1, \"key2\":\"foo\", \"key3\":<bar>hello</bar>}");
}
use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class StringTest method testXmlValueOf.
@Test
public void testXmlValueOf() {
BValue[] args = { new BXMLItem("<test>name</test>") };
BValue[] returns = BRunUtil.invoke(result, "xmlValueOf", args);
Assert.assertTrue(returns[0] instanceof BString);
final String expected = "<test>name</test>";
Assert.assertEquals(returns[0].stringValue(), expected);
}
use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class StringTest method testXmlValueOfNegative.
// TODO test this
@Test(expectedExceptions = { BLangRuntimeException.class })
public void testXmlValueOfNegative() {
BValue[] args = { new BXMLItem("<test>name<test>") };
BRunUtil.invoke(result, "xmlValueOf", args);
}
use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class XMLNativeFunctionTest method testToJsonWithMultipleAttributesNamespaces.
@Test
public void testToJsonWithMultipleAttributesNamespaces() {
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, "testToJSON", args);
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(returns[0].stringValue(), "{\"ns0:bookStore\":{\"@xmlns:ns0\":\"http://sample0.com/test\"," + "\"@xmlns:ns1\":\"http://sample1.com/test\",\"@status\":\"online\",\"ns0:storeName\":\"foo\"," + "\"ns0:isOpen\":\"true\",\"ns3:postalCode\":{\"@xmlns:ns3\":\"http://sample3.com/test\"," + "\"#text\":\"94\"},\"ns2:address\":{\"@xmlns:ns2\":\"http://sample2.com/test\"," + "\"ns2:street\":\"foo\",\"ns2:city\":\"111\",\"ns2:country\":\"true\"}," + "\"ns4:codes\":{\"@xmlns:ns4\":\"http://sample4.com/test\",\"ns4:item\":[\"4\",\"8\",\"9\"]}}}");
}
Aggregations