Search in sources :

Example 11 with BInteger

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

the class SQLActionsTest method testSelectIntFloatData.

@Test(groups = "ConnectorTest for int float types")
public void testSelectIntFloatData() {
    BValue[] returns = BRunUtil.invoke(result, "testSelectIntFloatData");
    Assert.assertEquals(returns.length, 4);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    Assert.assertSame(returns[1].getClass(), BInteger.class);
    Assert.assertSame(returns[2].getClass(), BFloat.class);
    Assert.assertSame(returns[3].getClass(), BFloat.class);
    BInteger intVal = (BInteger) returns[0];
    BInteger longVal = (BInteger) returns[1];
    BFloat floatVal = (BFloat) returns[2];
    BFloat doubleVal = (BFloat) returns[3];
    long intExpected = 10;
    long longExpected = 9223372036854774807L;
    double floatExpected = 123.34;
    double doubleExpected = 2139095039;
    Assert.assertEquals(intVal.intValue(), intExpected);
    Assert.assertEquals(longVal.intValue(), longExpected);
    Assert.assertEquals(floatVal.floatValue(), floatExpected, DELTA);
    Assert.assertEquals(doubleVal.floatValue(), doubleExpected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) Test(org.testng.annotations.Test)

Example 12 with BInteger

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

the class SQLActionsTest method testArrayInParameters.

@Test(groups = "ConnectorTest")
public void testArrayInParameters() {
    BValue[] returns = BRunUtil.invoke(result, "testArrayInParameters");
    BInteger retValue = (BInteger) returns[0];
    Assert.assertEquals(retValue.intValue(), 1);
    Assert.assertTrue(returns[1] instanceof BIntArray);
    BIntArray intArray = (BIntArray) returns[1];
    Assert.assertEquals(intArray.get(0), 1);
    Assert.assertTrue(returns[2] instanceof BIntArray);
    BIntArray longArray = (BIntArray) returns[2];
    Assert.assertEquals(longArray.get(0), 1503383034226L);
    Assert.assertEquals(longArray.get(1), 1503383034224L);
    Assert.assertEquals(longArray.get(2), 1503383034225L);
    Assert.assertTrue(returns[3] instanceof BFloatArray);
    BFloatArray doubleArray = (BFloatArray) returns[3];
    Assert.assertEquals(doubleArray.get(0), 1503383034226.23D);
    Assert.assertEquals(doubleArray.get(1), 1503383034224.43D);
    Assert.assertEquals(doubleArray.get(2), 1503383034225.123D);
    Assert.assertTrue(returns[4] instanceof BStringArray);
    BStringArray stringArray = (BStringArray) returns[4];
    Assert.assertEquals(stringArray.get(0), "Hello");
    Assert.assertEquals(stringArray.get(1), "Ballerina");
    Assert.assertTrue(returns[5] instanceof BBooleanArray);
    BBooleanArray booleanArray = (BBooleanArray) returns[5];
    Assert.assertEquals(booleanArray.get(0), 1);
    Assert.assertEquals(booleanArray.get(1), 0);
    Assert.assertEquals(booleanArray.get(2), 1);
    Assert.assertTrue(returns[6] instanceof BFloatArray);
    BFloatArray floatArray = (BFloatArray) returns[6];
    Assert.assertEquals(floatArray.get(0), 245.23);
    Assert.assertEquals(floatArray.get(1), 5559.49);
    Assert.assertEquals(floatArray.get(2), 8796.123);
}
Also used : BBooleanArray(org.ballerinalang.model.values.BBooleanArray) BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BFloatArray(org.ballerinalang.model.values.BFloatArray) BStringArray(org.ballerinalang.model.values.BStringArray) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 13 with BInteger

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

the class CachingTest method testCacheEviction3.

@Test
public void testCacheEviction3() {
    String cacheName = "userCache";
    int expiryTime = 20000;
    int capacity = 10;
    float evictionFactor = 0.2f;
    BValue[] args = new BValue[4];
    args[0] = new BString(cacheName);
    args[1] = new BInteger(expiryTime);
    args[2] = new BInteger(capacity);
    args[3] = new BFloat(evictionFactor);
    BValue[] returns = BRunUtil.invoke(compileResult, "testCacheEviction3", args);
    Assert.assertTrue(returns.length == 2);
    Assert.assertTrue(returns[0] instanceof BStringArray);
    Assert.assertEquals(((BStringArray) returns[0]).get(0), "A");
    Assert.assertEquals(((BStringArray) returns[0]).get(1), "B");
    Assert.assertEquals(((BStringArray) returns[0]).get(2), "E");
    Assert.assertEquals(((BStringArray) returns[0]).get(3), "F");
    Assert.assertEquals(((BStringArray) returns[0]).get(4), "G");
    Assert.assertEquals(((BStringArray) returns[0]).get(5), "H");
    Assert.assertEquals(((BStringArray) returns[0]).get(6), "I");
    Assert.assertEquals(((BStringArray) returns[0]).get(7), "J");
    Assert.assertEquals(((BStringArray) returns[0]).get(8), "K");
    Assert.assertEquals(((BInteger) returns[1]).intValue(), 9);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) BString(org.ballerinalang.model.values.BString) BStringArray(org.ballerinalang.model.values.BStringArray) Test(org.testng.annotations.Test)

Example 14 with BInteger

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

the class CachingTest method testGet.

@Test
public void testGet() {
    String cacheName = "userCache";
    int expiryTime = 20000;
    int capacity = 10;
    float evictionFactor = 0.1f;
    String key = "Ballerina";
    String value = "Rocks";
    BValue[] args = new BValue[6];
    args[0] = new BString(cacheName);
    args[1] = new BInteger(expiryTime);
    args[2] = new BInteger(capacity);
    args[3] = new BFloat(evictionFactor);
    args[4] = new BString(key);
    args[5] = new BString(value);
    BValue[] returns = BRunUtil.invoke(compileResult, "testGet", args);
    Assert.assertTrue(returns.length == 2);
    Assert.assertTrue(returns[0] instanceof BInteger);
    Assert.assertTrue(returns[1] instanceof BString);
    Assert.assertEquals(((BInteger) returns[0]).intValue(), 1);
    Assert.assertEquals(returns[1].stringValue(), "Rocks");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 15 with BInteger

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

the class CachingTest method testRemove.

@Test
public void testRemove() {
    String cacheName = "userCache";
    int expiryTime = 20000;
    int capacity = 10;
    float evictionFactor = 0.1f;
    String key = "Ballerina";
    String value = "Rocks";
    BValue[] args = new BValue[6];
    args[0] = new BString(cacheName);
    args[1] = new BInteger(expiryTime);
    args[2] = new BInteger(capacity);
    args[3] = new BFloat(evictionFactor);
    args[4] = new BString(key);
    args[5] = new BString(value);
    BValue[] returns = BRunUtil.invoke(compileResult, "testRemove", args);
    Assert.assertTrue(returns.length == 1);
    Assert.assertEquals(((BInteger) returns[0]).intValue(), 0);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Aggregations

BInteger (org.ballerinalang.model.values.BInteger)364 BValue (org.ballerinalang.model.values.BValue)324 Test (org.testng.annotations.Test)305 BString (org.ballerinalang.model.values.BString)91 BFloat (org.ballerinalang.model.values.BFloat)55 BStruct (org.ballerinalang.model.values.BStruct)33 BBoolean (org.ballerinalang.model.values.BBoolean)24 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)18 CompileResult (org.ballerinalang.launcher.util.CompileResult)12 BBlob (org.ballerinalang.model.values.BBlob)11 BeforeTest (org.testng.annotations.BeforeTest)11 BIntArray (org.ballerinalang.model.values.BIntArray)9 BMap (org.ballerinalang.model.values.BMap)9 BRefType (org.ballerinalang.model.values.BRefType)8 BStringArray (org.ballerinalang.model.values.BStringArray)8 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)8 BType (org.ballerinalang.model.types.BType)6 BStructType (org.ballerinalang.model.types.BStructType)4 BJSON (org.ballerinalang.model.values.BJSON)4 UnsupportedFieldTypeException (org.ballerinalang.net.grpc.exception.UnsupportedFieldTypeException)4