Search in sources :

Example 36 with BJSON

use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.

the class BJSONValueTest method testUpdateJsonInArray.

@Test
public void testUpdateJsonInArray() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testUpdateJsonInArray");
    Assert.assertTrue(returns[0] instanceof BJSON);
    BJSON json = ((BJSON) returns[0]);
    Assert.assertEquals(json.toString(), "[\"a\",{\"country\":\"SriLanka\"},\"c\"]");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 37 with BJSON

use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.

the class BJSONValueTest method testUpdateString.

@Test
public void testUpdateString() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testUpdateString");
    Assert.assertTrue(returns[0] instanceof BJSON);
    BJSON json = ((BJSON) returns[0]);
    Assert.assertEquals(json.toString(), "{\"fname\":\"Supun\",\"lname\":\"Setunga\"}");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 38 with BJSON

use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.

the class BJSONValueTest method testAddBoolean.

@Test
public void testAddBoolean() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testAddBoolean");
    Assert.assertTrue(returns[0] instanceof BJSON);
    BJSON json = ((BJSON) returns[0]);
    Assert.assertEquals(json.toString(), "{\"fname\":\"Supun\",\"status\":true}");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 39 with BJSON

use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.

the class BJSONValueTest method testAddJson.

@Test
public void testAddJson() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testAddJson");
    Assert.assertTrue(returns[0] instanceof BJSON);
    BJSON json = ((BJSON) returns[0]);
    Assert.assertEquals(json.toString(), "{\"fname\":\"Supun\",\"address\":{\"country\":\"SriLanka\"}}");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 40 with BJSON

use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.

the class JSONTest method testToXMLKeyValue.

@Test(description = "Convert json object with key value")
public void testToXMLKeyValue() {
    BValue[] args = { new BJSON(jsonToXML15) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXML", args);
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(returnElement.toString(), "<key>value</key>");
}
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)

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