Search in sources :

Example 21 with BIntArray

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

the class TypeCastExprTest method testStructAsAnyToStruct.

@Test(description = "Test casting struct stored as any to struct")
public void testStructAsAnyToStruct() {
    BValue[] returns = BRunUtil.invoke(result, "testStructAsAnyToStruct");
    Assert.assertTrue(returns[0] instanceof BStruct);
    Assert.assertTrue(returns[0] instanceof BStruct);
    BStruct student = (BStruct) returns[0];
    String name = student.getStringField(0);
    Assert.assertEquals(name, "Supun");
    int age = (int) student.getIntField(0);
    Assert.assertEquals(age, 25);
    BValue address = student.getRefField(0);
    Assert.assertTrue(address instanceof BMap<?, ?>);
    BMap<String, ?> addressMap = (BMap<String, ?>) address;
    Assert.assertEquals(addressMap.get("city").stringValue(), "Kandy");
    Assert.assertEquals(addressMap.get("country").stringValue(), "SriLanka");
    BIntArray marks = (BIntArray) student.getRefField(1);
    Assert.assertTrue(marks instanceof BIntArray);
    Assert.assertEquals(marks.size(), 2);
    Assert.assertEquals(marks.get(0), 24);
    Assert.assertEquals(marks.get(1), 81);
    double score = student.getFloatField(0);
    Assert.assertEquals(score, 0.0);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BMap(org.ballerinalang.model.values.BMap) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 22 with BIntArray

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

the class TypeCastExprTest method testStructToStruct.

/*@Test
    public void testSimpleJsonToMap() {
        BValue[] returns = BTestUtils.invoke(result, "testSimpleJsonToMap");
        Assert.assertTrue(returns[0] instanceof BMap<?, ?>);
        BMap map = (BMap) returns[0];

        BValue value1 = map.get(new BString("fname"));
        Assert.assertTrue(value1 instanceof BString);
        Assert.assertEquals(value1.stringValue(), "Supun");

        BValue value2 = map.get(new BString("lname"));
        Assert.assertTrue(value2 instanceof BString);
        Assert.assertEquals(value2.stringValue(), "Setunga");
    }*/
/*@Test
    public void testComplexJsonToMap() {
        BValue[] returns = BTestUtils.invoke(result, "testComplexJsonToMap");
        Assert.assertTrue(returns[0] instanceof BMap<?, ?>);
        BMap map = (BMap) returns[0];

        BValue value1 = map.get(new BString("name"));
        Assert.assertTrue(value1 instanceof BString);
        Assert.assertEquals(value1.stringValue(), "Supun");

        BValue value2 = map.get(new BString("age"));
        Assert.assertTrue(value2 instanceof BInteger);
        Assert.assertEquals(((BInteger) value2).intValue(), 25);

        BValue value3 = map.get(new BString("gpa"));
        Assert.assertTrue(value3 instanceof BFloat);
        Assert.assertEquals(((BFloat) value3).floatValue(), 2.81);

        BValue value4 = map.get(new BString("status"));
        Assert.assertTrue(value4 instanceof BBoolean);
        Assert.assertEquals(((BBoolean) value4).booleanValue(), true);

        BValue value5 = map.get(new BString("info"));
        Assert.assertEquals(value5, null);

        BValue value6 = map.get(new BString("address"));
        Assert.assertTrue(value6 instanceof BJSON);
        Assert.assertEquals(value6.stringValue(), "{\"city\":\"Colombo\",\"country\":\"SriLanka\"}");

        BValue value7 = map.get(new BString("marks"));
        Assert.assertTrue(value7 instanceof BJSON);
        Assert.assertEquals(value7.stringValue(), "[1,5,7]");
    }*/
/*@Test
    public void testSimpleMapToJson() {
        BValue[] returns = BTestUtils.invoke(result, "testSimpleMapToJson");
        Assert.assertTrue(returns[0] instanceof BJSON);
        JsonNode jsonNode = ((BJSON) returns[0]).value();
        Assert.assertEquals(jsonNode.get("fname").textValue(), "Supun");
        Assert.assertEquals(jsonNode.get("lname").textValue(), "Setunga");
    }*/
/*@Test
    public void testComplexMapToJson() {
        BValue[] returns = BTestUtils.invoke(result, "testComplexMapToJson");
        Assert.assertTrue(returns[0] instanceof BJSON);
        JsonNode jsonNode = ((BJSON) returns[0]).value();
        Assert.assertEquals(jsonNode.get("name").textValue(), "Supun");
        Assert.assertEquals(jsonNode.get("age").intValue(), 25);
        Assert.assertEquals(jsonNode.get("status").booleanValue(), true);
        Assert.assertTrue(jsonNode.get("info").isNull());
        Assert.assertEquals(jsonNode.get("intArray").toString(), "[7,8,9]");

        JsonNode addressNode = jsonNode.get("address");
        Assert.assertEquals(addressNode.get("country").textValue(), "USA");
        Assert.assertEquals(addressNode.get("city").textValue(), "CA");
    }*/
@Test
public void testStructToStruct() {
    BValue[] returns = BRunUtil.invoke(result, "testStructToStruct");
    Assert.assertTrue(returns[0] instanceof BStruct);
    BStruct student = (BStruct) returns[0];
    Assert.assertEquals(student.getStringField(0), "Supun");
    Assert.assertEquals(student.getIntField(0), 25);
    BValue address = student.getRefField(0);
    Assert.assertTrue(address instanceof BMap<?, ?>);
    BMap<String, ?> addressMap = (BMap<String, ?>) address;
    Assert.assertEquals(addressMap.get("city").stringValue(), "Kandy");
    Assert.assertEquals(addressMap.get("country").stringValue(), "SriLanka");
    BIntArray marksArray = (BIntArray) student.getRefField(1);
    Assert.assertTrue(marksArray instanceof BIntArray);
    Assert.assertEquals(marksArray.size(), 2);
    Assert.assertEquals(marksArray.get(0), 24);
    Assert.assertEquals(marksArray.get(1), 81);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BMap(org.ballerinalang.model.values.BMap) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 23 with BIntArray

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

the class SQLActionsTest method testBatchUpdate.

@Test(groups = "ConnectorTest")
public void testBatchUpdate() {
    BValue[] returns = BRunUtil.invoke(result, "testBatchUpdate");
    BIntArray retValue = (BIntArray) returns[0];
    Assert.assertEquals(retValue.get(0), 1);
    Assert.assertEquals(retValue.get(1), 1);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 24 with BIntArray

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

the class SQLActionsTest method testInsertTimeData.

@Test(groups = "ConnectorTest")
public void testInsertTimeData() {
    BValue[] returns = BRunUtil.invoke(result, "testDateTimeInParameters");
    BIntArray retValue = (BIntArray) returns[0];
    Assert.assertEquals((int) retValue.get(0), 1);
    Assert.assertEquals((int) retValue.get(1), 1);
    Assert.assertEquals((int) retValue.get(2), 1);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 25 with BIntArray

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

the class SQLActionsTest method testBatchUpdateWithNullParam.

@Test(groups = "ConnectorTest")
public void testBatchUpdateWithNullParam() {
    BValue[] returns = BRunUtil.invoke(result, "testBatchUpdateWithNullParam");
    BIntArray retValue = (BIntArray) returns[0];
    Assert.assertEquals(retValue.get(0), 1);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Aggregations

BIntArray (org.ballerinalang.model.values.BIntArray)33 BValue (org.ballerinalang.model.values.BValue)25 Test (org.testng.annotations.Test)25 BString (org.ballerinalang.model.values.BString)14 BInteger (org.ballerinalang.model.values.BInteger)9 BStruct (org.ballerinalang.model.values.BStruct)9 BFloatArray (org.ballerinalang.model.values.BFloatArray)8 BStringArray (org.ballerinalang.model.values.BStringArray)8 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)7 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)7 BJSON (org.ballerinalang.model.values.BJSON)6 BMap (org.ballerinalang.model.values.BMap)6 BBlobArray (org.ballerinalang.model.values.BBlobArray)4 BFloat (org.ballerinalang.model.values.BFloat)4 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)4 BRefType (org.ballerinalang.model.values.BRefType)3 CompileResult (org.ballerinalang.launcher.util.CompileResult)2 BMapType (org.ballerinalang.model.types.BMapType)2 BBoolean (org.ballerinalang.model.values.BBoolean)2 StructureType (org.ballerinalang.model.values.StructureType)2