Search in sources :

Example 46 with BString

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

the class JSONTest method testParseMalformedString.

@Test(description = "Get JSON from a malformed string")
public void testParseMalformedString() {
    BValue[] args = { new BString("some words without quotes") };
    BValue[] returns = BRunUtil.invoke(compileResult, "testParse", args);
    Assert.assertTrue(returns[0] instanceof BStruct);
    Assert.assertEquals(((BStruct) returns[0]).getStringField(0), "Failed to parse json string: unrecognized token 'some' at line: 1 column: 6");
}
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 47 with BString

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

the class JSONTest method testToXMLJsonWithValue.

@Test(description = "Convert a json object with number value only")
public void testToXMLJsonWithValue() {
    BValue[] args = { new BJSON(jsonToXML5) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLString", args);
    Assert.assertTrue(returns[0] instanceof BString);
    String returnElement = (returns[0]).stringValue();
    Assert.assertEquals(returnElement, "5");
}
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 48 with BString

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

the class JSONTest method testParseBoolean.

@Test(description = "Get JSON boolean from a string")
public void testParseBoolean() {
    BValue[] args = { new BString("true") };
    BValue[] returns = BRunUtil.invoke(compileResult, "testParse", args);
    Assert.assertTrue(returns[0] instanceof BJSON);
    Assert.assertEquals(((BJSON) returns[0]).value().getType(), Type.BOOLEAN);
    Assert.assertEquals(returns[0].stringValue(), "true");
}
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 49 with BString

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

the class JSONTest method testParseNumber.

@Test(description = "Get JSON number from a string")
public void testParseNumber() {
    BValue[] args = { new BString("45678") };
    BValue[] returns = BRunUtil.invoke(compileResult, "testParse", args);
    Assert.assertTrue(returns[0] instanceof BJSON);
    Assert.assertEquals(((BJSON) returns[0]).value().getType(), Type.LONG);
    Assert.assertEquals(returns[0].stringValue(), "45678");
}
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 50 with BString

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

the class JSONTest method testToXMLEmptyElements.

@Test(description = "Convert a json object with empty elements")
public void testToXMLEmptyElements() {
    BValue[] args = { new BJSON(jsonToXML10) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLWithXMLSequence", args);
    Assert.assertTrue(returns[0] instanceof BString);
    String textValue = returns[0].stringValue();
    Assert.assertEquals(textValue, "<address/><homeAddresses/><phoneNumbers/>");
}
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

BString (org.ballerinalang.model.values.BString)418 BValue (org.ballerinalang.model.values.BValue)339 Test (org.testng.annotations.Test)321 BInteger (org.ballerinalang.model.values.BInteger)77 BStruct (org.ballerinalang.model.values.BStruct)76 BMap (org.ballerinalang.model.values.BMap)37 BBoolean (org.ballerinalang.model.values.BBoolean)36 BFloat (org.ballerinalang.model.values.BFloat)34 BJSON (org.ballerinalang.model.values.BJSON)28 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)21 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)18 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)11 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)11 CompileResult (org.ballerinalang.launcher.util.CompileResult)11 BBlob (org.ballerinalang.model.values.BBlob)11 BStringArray (org.ballerinalang.model.values.BStringArray)11 BType (org.ballerinalang.model.types.BType)10 BIntArray (org.ballerinalang.model.values.BIntArray)9 BRefType (org.ballerinalang.model.values.BRefType)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7