Search in sources :

Example 41 with BString

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

the class GetHeader method execute.

@Override
public void execute(Context context) {
    BStruct pushPromiseStruct = (BStruct) context.getRefArgument(0);
    Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, HttpUtil.createHttpPushPromise(pushPromiseStruct));
    String headerName = context.getStringArgument(0);
    context.setReturnValues(new BString(http2PushPromise.getHeader(headerName)));
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString)

Example 42 with BString

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

the class JSONTest method testParseObject.

@Test(description = "Get JSON object from a string")
public void testParseObject() {
    BValue[] args = { new BString("{\"name\":\"supun\"}") };
    BValue[] returns = BRunUtil.invoke(compileResult, "testParse", args);
    Assert.assertTrue(returns[0] instanceof BJSON);
    Assert.assertEquals(((BJSON) returns[0]).value().getType(), Type.OBJECT);
    Assert.assertEquals(returns[0].stringValue(), "{\"name\":\"supun\"}");
}
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 43 with BString

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

the class JSONTest method testParseArray.

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

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

the class JSONTest method testToXMLJsonObject.

@Test(description = "Convert a json object")
public void testToXMLJsonObject() {
    BValue[] args = { new BJSON(jsonToXML16) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLWithXMLSequence", args);
    Assert.assertTrue(returns[0] instanceof BString);
    String textValue = returns[0].stringValue();
    Assert.assertEquals(textValue, "<key1>value1</key1><key2>value2</key2>");
}
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 45 with BString

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

the class JSONTest method testToXMLMultirootedObjects.

@Test(description = "Convert a json object with multi rooted object")
public void testToXMLMultirootedObjects() {
    BValue[] args = { new BJSON(jsonToXML7) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLWithXMLSequence", args);
    Assert.assertTrue(returns[0] instanceof BString);
    String textValue = returns[0].stringValue();
    Assert.assertEquals(textValue, "<bookStore><storeName>foo</storeName><postalCode>94</postalCode>" + "<isOpen>true</isOpen><address><street>PalmGrove</street><city>Colombo</city>" + "<country>SriLanka</country></address><codes><item>4</item><item>8</item><item>9</item></codes>" + "</bookStore><metaInfo>someinfo</metaInfo>");
}
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