Search in sources :

Example 41 with BJSON

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\"}");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 42 with BJSON

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]");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 43 with BJSON

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>");
}
Also used : OMNode(org.apache.axiom.om.OMNode) BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 44 with BJSON

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>");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 45 with BJSON

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>");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Aggregations

BJSON (org.ballerinalang.model.values.BJSON)255 Test (org.testng.annotations.Test)214 BValue (org.ballerinalang.model.values.BValue)113 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)108 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)108 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)104 BString (org.ballerinalang.model.values.BString)85 BXMLItem (org.ballerinalang.model.values.BXMLItem)37 BStruct (org.ballerinalang.model.values.BStruct)23 BXML (org.ballerinalang.model.values.BXML)17 OMNode (org.apache.axiom.om.OMNode)13 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)13 BMap (org.ballerinalang.model.values.BMap)11 JsonNode (org.ballerinalang.model.util.JsonNode)10 BNewArray (org.ballerinalang.model.values.BNewArray)9 BIntArray (org.ballerinalang.model.values.BIntArray)8 BRefType (org.ballerinalang.model.values.BRefType)8 ArrayList (java.util.ArrayList)7 BStringArray (org.ballerinalang.model.values.BStringArray)7 BStructType (org.ballerinalang.model.types.BStructType)6