Search in sources :

Example 26 with BJSON

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

the class BJSONValueTest method testAddString.

@Test
public void testAddString() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testAddString");
    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 27 with BJSON

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

the class BJSONValueTest method testIntAsJsonVal.

@Test(description = "Test initializing json with an integer")
public void testIntAsJsonVal() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testIntAsJsonVal");
    Assert.assertTrue(returns[0] instanceof BJSON);
    BJSON person = ((BJSON) returns[0]);
    Assert.assertEquals(person.value().longValue(), 5);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 28 with BJSON

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

the class BJSONValueTest method testUpdateInt.

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

Example 29 with BJSON

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

the class BJSONValueTest method testFloatAsJsonVal.

@Test(description = "Test initializing json with a float")
public void testFloatAsJsonVal() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testFloatAsJsonVal");
    Assert.assertTrue(returns[0] instanceof BJSON);
    BJSON person = ((BJSON) returns[0]);
    Assert.assertEquals(person.value().doubleValue(), 7.65);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 30 with BJSON

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

the class BJSONValueTest method testJSONWithExpressionKey.

@Test
public void testJSONWithExpressionKey() {
    CompileResult result = BCompileUtil.compile("test-src/types/jsontype/json-literal-with-expr-key.bal");
    BValue[] returns = BRunUtil.invoke(result, "testJSONWithExpressionKey");
    Assert.assertTrue(returns[0] instanceof BJSON);
    Assert.assertEquals(returns[0].stringValue(), "{\"a\":\"Lion\",\"key1\":\"Cat\",\"key2\":\"Dog\"}");
}
Also used : BValue(org.ballerinalang.model.values.BValue) CompileResult(org.ballerinalang.launcher.util.CompileResult) 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