Search in sources :

Example 46 with OMNode

use of org.apache.axiom.om.OMNode in project ballerina by ballerina-lang.

the class JSONTest method testToXMLKeyValue.

@Test(description = "Convert json object with key value")
public void testToXMLKeyValue() {
    BValue[] args = { new BJSON(jsonToXML15) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXML", args);
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(returnElement.toString(), "<key>value</key>");
}
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 47 with OMNode

use of org.apache.axiom.om.OMNode in project ballerina by ballerina-lang.

the class JSONTest method testToXMLSimpleArrayObject.

@Test(description = "Convert json object with simple array")
public void testToXMLSimpleArrayObject() {
    BValue[] args = { new BJSON(jsonToXML4) };
    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>book1</item><item>book2</item><item>book3" + "</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 OMNode

use of org.apache.axiom.om.OMNode in project ballerina by ballerina-lang.

the class JSONTest method testToXMLAttributes.

@Test(description = "Convert a simple json object with attributes")
public void testToXMLAttributes() {
    BValue[] args = { new BJSON(jsonToXML12) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXML", args);
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(returnElement.toString(), "<info id=\"100\"><name>John</name><age>30</age><car>honda</car>" + "</info>");
}
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 OMNode

use of org.apache.axiom.om.OMNode in project ballerina by ballerina-lang.

the class JSONTest method testToXMLComplexObject.

@Test(description = "Convert complex json object in to xml")
public void testToXMLComplexObject() {
    BValue[] args = { new BJSON(jsonToXML1) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXML", args);
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(returnElement.toString(), "<bookStore><storeName>foo" + "</storeName><postalCode>94</postalCode><isOpen>true</isOpen><address><street>PalmGrove</street>" + "<city>Colombo</city><country>SriLanka</country></address><codes><item>4</item><item>8</item>" + "<item>9</item></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 OMNode

use of org.apache.axiom.om.OMNode in project ballerina by ballerina-lang.

the class JSONTest method testToXMLKeyWithAttributeAndValue.

@Test(description = "Convert json object with attribute and value")
public void testToXMLKeyWithAttributeAndValue() {
    BValue[] args = { new BJSON(jsonToXML19) };
    BValue[] returns = BRunUtil.invoke(compileResult, "testToXML", args);
    Assert.assertTrue(returns[0] instanceof BXML);
    OMNode returnElement = ((BXMLItem) returns[0]).value();
    Assert.assertEquals(returnElement.toString(), "<foo key=\"value\"><test>hello</test></foo>");
}
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

OMNode (org.apache.axiom.om.OMNode)150 OMElement (org.apache.axiom.om.OMElement)87 Iterator (java.util.Iterator)28 OMText (org.apache.axiom.om.OMText)23 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)20 BXMLItem (org.ballerinalang.model.values.BXMLItem)18 StringReader (java.io.StringReader)17 SynapseException (org.apache.synapse.SynapseException)15 OMAttribute (org.apache.axiom.om.OMAttribute)14 OMFactory (org.apache.axiom.om.OMFactory)14 BValue (org.ballerinalang.model.values.BValue)14 BXML (org.ballerinalang.model.values.BXML)14 Test (org.testng.annotations.Test)14 QName (javax.xml.namespace.QName)13 BJSON (org.ballerinalang.model.values.BJSON)13 OMDocument (org.apache.axiom.om.OMDocument)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 SOAPHeader (org.apache.axiom.soap.SOAPHeader)10 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)10