Search in sources :

Example 26 with BRefValueArray

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

the class XMLNativeFunctionTest method testSetChildren.

@Test
public void testSetChildren() {
    BValue[] returns = BRunUtil.invoke(result, "testSetChildren");
    Assert.assertEquals(returns.length, 4);
    Assert.assertTrue(returns[0] instanceof BXML);
    Assert.assertEquals(returns[0].stringValue(), "<ns0:name xmlns:ns0=\"http://sample.com/test\"><newFname>" + "supun-new</newFname><newMname>thilina-new</newMname><newLname>setunga-new</newLname></ns0:name>");
    // is children seq is empty?
    Assert.assertSame(returns[1].getClass(), BBoolean.class);
    Assert.assertEquals(((BBoolean) returns[1]).booleanValue(), false);
    // is children seq is singleton?
    Assert.assertSame(returns[2].getClass(), BBoolean.class);
    Assert.assertEquals(((BBoolean) returns[2]).booleanValue(), true);
    // Check children
    Assert.assertTrue(returns[3] instanceof BXML);
    BRefValueArray children = ((BXMLSequence) returns[3]).value();
    Assert.assertEquals(children.size(), 3);
    Assert.assertEquals(children.get(0).stringValue(), "<newFname>supun-new</newFname>");
    Assert.assertEquals(children.get(1).stringValue(), "<newMname>thilina-new</newMname>");
    Assert.assertEquals(children.get(2).stringValue(), "<newLname>setunga-new</newLname>");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BXML(org.ballerinalang.model.values.BXML) BXMLSequence(org.ballerinalang.model.values.BXMLSequence) Test(org.testng.annotations.Test)

Example 27 with BRefValueArray

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

the class XMLNativeFunctionTest method testSetChildrenWithEmptyNamespace.

@Test
public void testSetChildrenWithEmptyNamespace() {
    BValue[] returns = BRunUtil.invoke(result, "testSetChildrenEmptyNamespace");
    Assert.assertEquals(returns.length, 5);
    Assert.assertTrue(returns[0] instanceof BXML);
    Assert.assertEquals(returns[0].stringValue(), "<name xmlns=\"http://sample.com/test\"><fname>supun</fname>" + "<lname>setunga</lname><residency xmlns=\"\" citizen=\"true\">true</residency></name>");
    // is children seq is empty?
    Assert.assertSame(returns[1].getClass(), BBoolean.class);
    Assert.assertEquals(((BBoolean) returns[1]).booleanValue(), false);
    // is children seq is singleton?
    Assert.assertSame(returns[2].getClass(), BBoolean.class);
    Assert.assertEquals(((BBoolean) returns[2]).booleanValue(), true);
    // Check children
    Assert.assertTrue(returns[3] instanceof BXML);
    BRefValueArray children = ((BXMLSequence) returns[3]).value();
    Assert.assertEquals(children.size(), 3);
    Assert.assertEquals(children.get(0).stringValue(), "<fname xmlns=\"http://sample.com/test\">supun</fname>");
    Assert.assertEquals(children.get(1).stringValue(), "<lname xmlns=\"http://sample.com/test\">setunga</lname>");
    Assert.assertEquals(children.get(2).stringValue(), "<residency citizen=\"true\">true</residency>");
    // Check attribute value
    Assert.assertSame(returns[4].getClass(), BString.class);
    Assert.assertEquals(((BString) returns[4]).stringValue(), "true");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BXML(org.ballerinalang.model.values.BXML) BXMLSequence(org.ballerinalang.model.values.BXMLSequence) Test(org.testng.annotations.Test)

Example 28 with BRefValueArray

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

the class GetDate method execute.

@Override
public void execute(Context context) {
    BStruct timeStruct = ((BStruct) context.getRefArgument(0));
    BRefValueArray date = new BRefValueArray(getDateTupleType);
    date.add(0, new BInteger(getYear(timeStruct)));
    date.add(1, new BInteger(getMonth(timeStruct)));
    date.add(2, new BInteger(getDay(timeStruct)));
    context.setReturnValues(date);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BInteger(org.ballerinalang.model.values.BInteger) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Example 29 with BRefValueArray

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

the class GetTime method execute.

@Override
public void execute(Context context) {
    BStruct timeStruct = ((BStruct) context.getRefArgument(0));
    BRefValueArray time = new BRefValueArray(getTimeTupleType);
    time.add(0, new BInteger(getHour(timeStruct)));
    time.add(1, new BInteger(getMinute(timeStruct)));
    time.add(2, new BInteger(getSecond(timeStruct)));
    time.add(3, new BInteger(getMilliSecond(timeStruct)));
    context.setReturnValues(time);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BInteger(org.ballerinalang.model.values.BInteger) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Example 30 with BRefValueArray

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

the class Util method getArrayOfBodyParts.

/**
 * From a given list of body parts get a ballerina value array.
 *
 * @param bodyParts List of body parts
 * @return BRefValueArray representing an array of entities
 */
static BRefValueArray getArrayOfBodyParts(ArrayList<BStruct> bodyParts) {
    BStructType typeOfBodyPart = bodyParts.get(0).getType();
    BStruct[] result = bodyParts.toArray(new BStruct[bodyParts.size()]);
    return new BRefValueArray(result, typeOfBodyPart);
}
Also used : BStructType(org.ballerinalang.model.types.BStructType) BStruct(org.ballerinalang.model.values.BStruct) BRefValueArray(org.ballerinalang.model.values.BRefValueArray)

Aggregations

BRefValueArray (org.ballerinalang.model.values.BRefValueArray)83 BValue (org.ballerinalang.model.values.BValue)45 Test (org.testng.annotations.Test)40 BStruct (org.ballerinalang.model.values.BStruct)37 BString (org.ballerinalang.model.values.BString)22 BInteger (org.ballerinalang.model.values.BInteger)18 BXMLSequence (org.ballerinalang.model.values.BXMLSequence)9 BeforeTest (org.testng.annotations.BeforeTest)9 BIntArray (org.ballerinalang.model.values.BIntArray)7 BMap (org.ballerinalang.model.values.BMap)7 BStringArray (org.ballerinalang.model.values.BStringArray)7 BXML (org.ballerinalang.model.values.BXML)7 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)7 HashMap (java.util.HashMap)6 BStructType (org.ballerinalang.model.types.BStructType)6 BRefType (org.ballerinalang.model.values.BRefType)5 SQLDatasource (org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource)5 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)4 BFloatArray (org.ballerinalang.model.values.BFloatArray)4 IOException (java.io.IOException)3