Search in sources :

Example 91 with BValue

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

the class BJSONValueTest method testJsonToJsonArrayInvalidCasting.

@Test
public void testJsonToJsonArrayInvalidCasting() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testJsonToJsonArrayInvalidCasting");
    Assert.assertTrue(returns[0] instanceof BStruct);
    String errorMsg = ((BStruct) returns[0]).getStringField(0);
    Assert.assertEquals(errorMsg, "'json[]' cannot be cast to 'json[][][]'");
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 92 with BValue

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

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

Example 94 with BValue

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

the class BJSONValueTest method testUpdateJson.

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

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

the class BJSONValueTest method testStringAsJsonVal.

@Test(description = "Test initializing json with a string")
public void testStringAsJsonVal() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testStringAsJsonVal");
    Assert.assertTrue(returns[0] instanceof BJSON);
    BJSON person = ((BJSON) returns[0]);
    Assert.assertEquals(person.value().asText(), "Supun");
}
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