Search in sources :

Example 96 with BString

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

the class Base64ToBase16Encode method execute.

@Override
public void execute(Context context) {
    String value = context.getStringArgument(0);
    byte[] base64DecodedValue = Base64.getDecoder().decode(value);
    String base16EncodedValue = DatatypeConverter.printHexBinary(base64DecodedValue);
    context.setReturnValues(new BString(base16EncodedValue));
}
Also used : BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString)

Example 97 with BString

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

the class MimeUtilityFunctionTest method testMimeBase64DecodeString.

@Test(description = "Test 'testMimeBase64DecodeString' function in ballerina.mime package")
public void testMimeBase64DecodeString() {
    BValue[] args = { new BString("QmFsbGVyaW5h"), new BString("utf-8") };
    BValue[] returns = BRunUtil.invoke(compileResult, "testMimeBase64DecodeString", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertEquals(returns[0].stringValue(), "Ballerina");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 98 with BString

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

the class MimeUtilityFunctionTest method testGetAndSetText.

@Test(description = "Set text data to entity and get the content back from entity as text")
public void testGetAndSetText() {
    BString textContent = new BString("Hello Ballerina !");
    BValue[] args = { textContent };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSetAndGetText", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertEquals(returns[0].stringValue(), "Hello Ballerina !");
}
Also used : BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) Test(org.testng.annotations.Test)

Example 99 with BString

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

the class MimeUtilityFunctionTest method testGetTextMoreThanOnce.

@Test(description = "Test whether the text content can be retrieved properly when it is called multiple times")
public void testGetTextMoreThanOnce() {
    BString textContent = new BString("Hello Ballerina !");
    BValue[] args = { textContent };
    BValue[] returns = BRunUtil.invoke(compileResult, "testGetTextMultipleTimes", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertEquals(returns[0].stringValue(), "Hello Ballerina !Hello Ballerina !Hello Ballerina !");
}
Also used : BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) Test(org.testng.annotations.Test)

Example 100 with BString

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

the class SystemTest method testFormatStringWithPadding.

@Test
public void testFormatStringWithPadding() {
    BRefValueArray fArgs = new BRefValueArray();
    fArgs.add(0, new BString("Hello Ballerina"));
    BValue[] args = { new BString("%9.2s"), fArgs };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
    Assert.assertEquals(returns[0].stringValue(), "       He");
}
Also used : BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) 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