use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class JSONTest method testParseObject.
@Test(description = "Get JSON object from a string")
public void testParseObject() {
BValue[] args = { new BString("{\"name\":\"supun\"}") };
BValue[] returns = BRunUtil.invoke(compileResult, "testParse", args);
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(((BJSON) returns[0]).value().getType(), Type.OBJECT);
Assert.assertEquals(returns[0].stringValue(), "{\"name\":\"supun\"}");
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class JSONTest method testParseArray.
@Test(description = "Get JSON array from a string")
public void testParseArray() {
BValue[] args = { new BString("[\"supun\", 45, true, null]") };
BValue[] returns = BRunUtil.invoke(compileResult, "testParse", args);
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(((BJSON) returns[0]).value().getType(), Type.ARRAY);
Assert.assertEquals(returns[0].stringValue(), "[\"supun\",45,true,null]");
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class JSONTest method testToXMLSimpleArrayObject.
@Test(description = "Convert json object with simple array")
public void testToXMLSimpleArrayObject() {
BValue[] args = { new BJSON(jsonToXML4) };
BValue[] returns = BRunUtil.invoke(compileResult, "testToXML", args);
Assert.assertTrue(returns[0] instanceof BXML);
OMNode returnElement = ((BXMLItem) returns[0]).value();
Assert.assertEquals(returnElement.toString(), "<books><item>book1</item><item>book2</item><item>book3" + "</item></books>");
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class JSONTest method testToXMLJsonObject.
@Test(description = "Convert a json object")
public void testToXMLJsonObject() {
BValue[] args = { new BJSON(jsonToXML16) };
BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLWithXMLSequence", args);
Assert.assertTrue(returns[0] instanceof BString);
String textValue = returns[0].stringValue();
Assert.assertEquals(textValue, "<key1>value1</key1><key2>value2</key2>");
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class JSONTest method testToXMLMultirootedObjects.
@Test(description = "Convert a json object with multi rooted object")
public void testToXMLMultirootedObjects() {
BValue[] args = { new BJSON(jsonToXML7) };
BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLWithXMLSequence", args);
Assert.assertTrue(returns[0] instanceof BString);
String textValue = returns[0].stringValue();
Assert.assertEquals(textValue, "<bookStore><storeName>foo</storeName><postalCode>94</postalCode>" + "<isOpen>true</isOpen><address><street>PalmGrove</street><city>Colombo</city>" + "<country>SriLanka</country></address><codes><item>4</item><item>8</item><item>9</item></codes>" + "</bookStore><metaInfo>someinfo</metaInfo>");
}
Aggregations