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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations