Search in sources :

Example 86 with BValue

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

the class BJSONValueTest method testUpdateNestedElement.

// @Test
// public void testJsonArrayWithVariable() {
// BValue[] returns = BLangFunctions.invoke(bLangProgram, "testJsonArrayWithVariable");
// Assert.assertTrue(returns[0] instanceof BJSON);
// Assert.assertEquals(returns[0].stringValue(), "[\"a\",\"b\",\"c\",{\"name\":\"supun\"}]");
// }
@Test
public void testUpdateNestedElement() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testUpdateNestedElement");
    Assert.assertTrue(returns[0] instanceof BJSON);
    BJSON json = ((BJSON) returns[0]);
    Assert.assertEquals(json.toString(), "{\"details\":{\"fname\":\"Supun\",\"lname\":\"Setunga\"}}");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 87 with BValue

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

the class BJSONValueTest method testUpdateJsonArrayInArray.

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

Example 88 with BValue

use of org.ballerinalang.model.values.BValue 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 89 with BValue

use of org.ballerinalang.model.values.BValue 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 90 with BValue

use of org.ballerinalang.model.values.BValue 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)

Aggregations

BValue (org.ballerinalang.model.values.BValue)1043 Test (org.testng.annotations.Test)923 BString (org.ballerinalang.model.values.BString)437 BInteger (org.ballerinalang.model.values.BInteger)323 BStruct (org.ballerinalang.model.values.BStruct)188 BFloat (org.ballerinalang.model.values.BFloat)118 BJSON (org.ballerinalang.model.values.BJSON)112 BBoolean (org.ballerinalang.model.values.BBoolean)79 CompileResult (org.ballerinalang.launcher.util.CompileResult)60 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)45 BMap (org.ballerinalang.model.values.BMap)43 BXMLItem (org.ballerinalang.model.values.BXMLItem)42 BXML (org.ballerinalang.model.values.BXML)40 BStringArray (org.ballerinalang.model.values.BStringArray)30 BIntArray (org.ballerinalang.model.values.BIntArray)25 BBlob (org.ballerinalang.model.values.BBlob)23 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)19 BeforeTest (org.testng.annotations.BeforeTest)19 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)19 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)16