Search in sources :

Example 46 with BXMLItem

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

the class JSONTest method testToXMLBooleanValue.

@Test(description = "Convert a json object with boolean value only")
public void testToXMLBooleanValue() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLBooleanValue");
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(((OMText) returnElement).getText(), "true");
}
Also used : OMNode(org.apache.axiom.om.OMNode) BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) Test(org.testng.annotations.Test)

Example 47 with BXMLItem

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

the class JSONTest method testToXMLArrayWithinArrayObject.

@Test(description = "Convert json object which has an array within an array")
public void testToXMLArrayWithinArrayObject() {
    BValue[] args = { new BJSON(jsonToXML3) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXML", args);
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(returnElement.toString(), "<books><item><item><bookName>book1</bookName><bookId>101" + "</bookId></item></item><item><item><bookName>book2</bookName><bookId>102</bookId></item></item>" + "<item><item><bookName>book3</bookName><bookId>103</bookId></item></item></books>");
}
Also used : OMNode(org.apache.axiom.om.OMNode) BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 48 with BXMLItem

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

the class JSONTest method testToXMLArrayObject.

@Test(description = "Convert json object with array within")
public void testToXMLArrayObject() {
    BValue[] args = { new BJSON(jsonToXML2) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXML", args);
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(returnElement.toString(), "<books><item><bookName>book1</bookName><bookId>101</bookId>" + "</item><item><bookName>book2</bookName><bookId>102</bookId></item><item><bookName>book3</bookName>" + "<bookId>103</bookId></item></books>");
}
Also used : OMNode(org.apache.axiom.om.OMNode) BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 49 with BXMLItem

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

the class JSONTest method testToXMLComplexAttributesCustomPrefix.

@Test(description = "Convert a complex json object with attributes and custom attribute prefix")
public void testToXMLComplexAttributesCustomPrefix() {
    BValue[] args = { new BJSON(jsonToXML14) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLWithOptions", args);
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(returnElement.toString(), "<bookStore storeName=\"foo\"><postalCode>94</postalCode>" + "<isOpen>true</isOpen><address city=\"Colombo\"><street>PalmGrove</street><country>SriLanka</country>" + "</address><codes><wrapper>4</wrapper><wrapper>8</wrapper><wrapper>9</wrapper></codes></bookStore>");
}
Also used : OMNode(org.apache.axiom.om.OMNode) BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 50 with BXMLItem

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

the class JSONTest method testToXMLNullElementsInObject.

@Test(description = "Convert a json object with null object elements")
public void testToXMLNullElementsInObject() {
    BValue[] args = { new BJSON(jsonToXML9) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXML", args);
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(returnElement.toString(), "<Person><name>John</name><age>30</age>" + "<car xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\"/></Person>");
}
Also used : OMNode(org.apache.axiom.om.OMNode) BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Aggregations

BXMLItem (org.ballerinalang.model.values.BXMLItem)56 Test (org.testng.annotations.Test)46 BValue (org.ballerinalang.model.values.BValue)42 BJSON (org.ballerinalang.model.values.BJSON)36 BString (org.ballerinalang.model.values.BString)26 OMNode (org.apache.axiom.om.OMNode)18 BXML (org.ballerinalang.model.values.BXML)17 BStruct (org.ballerinalang.model.values.BStruct)6 OMElement (org.apache.axiom.om.OMElement)5 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)5 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)4 ArrayList (java.util.ArrayList)3 OMText (org.apache.axiom.om.OMText)3 BXMLSequence (org.ballerinalang.model.values.BXMLSequence)3 OMDocument (org.apache.axiom.om.OMDocument)2 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)2 BFloatArray (org.ballerinalang.model.values.BFloatArray)2 BIntArray (org.ballerinalang.model.values.BIntArray)2 BStringArray (org.ballerinalang.model.values.BStringArray)2 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)2