use of org.ballerinalang.model.values.BXMLSequence in project ballerina by ballerina-lang.
the class XMLLiteralTest method testElementLiteralWithNamespaces.
@Test
public void testElementLiteralWithNamespaces() {
BValue[] returns = BRunUtil.invoke(literalWithNamespacesResult, "testElementLiteralWithNamespaces");
Assert.assertTrue(returns[0] instanceof BXML);
Assert.assertEquals(returns[0].stringValue(), "<root xmlns=\"http://ballerina.com/\" xmlns:ns0=\"http://ballerina.com/a\" " + "xmlns:ns1=\"http://ballerina.com/c\" ns0:id=\"456\"><foo>123</foo>" + "<bar ns1:status=\"complete\"/></root>");
Assert.assertTrue(returns[1] instanceof BXML);
BXMLSequence seq = (BXMLSequence) returns[1];
Assert.assertEquals(seq.stringValue(), "<foo xmlns=\"http://ballerina.com/\" " + "xmlns:ns0=\"http://ballerina.com/a\" xmlns:ns1=\"http://ballerina.com/c\">123</foo>" + "<bar xmlns=\"http://ballerina.com/\" xmlns:ns0=\"http://ballerina.com/a\" " + "xmlns:ns1=\"http://ballerina.com/c\" ns1:status=\"complete\"/>");
BRefValueArray items = seq.value();
Assert.assertEquals(items.size(), 2);
}
use of org.ballerinalang.model.values.BXMLSequence in project ballerina by ballerina-lang.
the class XMLLiteralTest method testElementLiteralWithTemplateChildren.
@Test
public void testElementLiteralWithTemplateChildren() {
BValue[] returns = BRunUtil.invoke(result, "testElementLiteralWithTemplateChildren");
Assert.assertTrue(returns[0] instanceof BXML);
Assert.assertEquals(returns[0].stringValue(), "<root>hello aaa<bbb good morning <fname>John</fname> " + "<lname>Doe</lname>. Have a nice day!<foo>123</foo><bar/></root>");
Assert.assertTrue(returns[1] instanceof BXML);
BXMLSequence seq = (BXMLSequence) returns[1];
Assert.assertEquals(seq.stringValue(), "hello aaa<bbb good morning <fname>John</fname> <lname>Doe</lname>. " + "Have a nice day!<foo>123</foo><bar/>");
BRefValueArray items = seq.value();
Assert.assertEquals(items.size(), 7);
}
use of org.ballerinalang.model.values.BXMLSequence 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>");
}
use of org.ballerinalang.model.values.BXMLSequence 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");
}
use of org.ballerinalang.model.values.BXMLSequence in project ballerina by ballerina-lang.
the class XMLNativeFunctionTest method testSelectDescendants.
@Test
public void testSelectDescendants() {
BValue[] returns = BRunUtil.invoke(result, "testSelectDescendants");
Assert.assertTrue(returns[0] instanceof BXML);
BXMLSequence seq = (BXMLSequence) returns[0];
Assert.assertEquals(seq.value().size(), 2);
Assert.assertEquals(seq.stringValue(), "<name xmlns=\"http://ballerinalang.org/\" " + "xmlns:ns0=\"http://ballerinalang.org/aaa\"><name>Supun</name><lname>Setunga</lname></name>" + "<name xmlns=\"http://ballerinalang.org/\" xmlns:ns0=\"http://ballerinalang.org/aaa\">John</name>");
}
Aggregations