Search in sources :

Example 1 with BXMLSequence

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);
}
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 2 with BXMLSequence

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&lt;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);
}
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 3 with BXMLSequence

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>");
}
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 4 with BXMLSequence

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");
}
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 5 with BXMLSequence

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>");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) BXMLSequence(org.ballerinalang.model.values.BXMLSequence) Test(org.testng.annotations.Test)

Aggregations

BXMLSequence (org.ballerinalang.model.values.BXMLSequence)14 BXML (org.ballerinalang.model.values.BXML)11 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)9 BValue (org.ballerinalang.model.values.BValue)9 Test (org.testng.annotations.Test)9 BXMLItem (org.ballerinalang.model.values.BXMLItem)3 OMNode (org.apache.axiom.om.OMNode)2 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)2 DeferredParsingException (org.apache.axiom.om.DeferredParsingException)1 OMDocument (org.apache.axiom.om.OMDocument)1 OMElement (org.apache.axiom.om.OMElement)1 BJSON (org.ballerinalang.model.values.BJSON)1 BXMLQName (org.ballerinalang.model.values.BXMLQName)1