Search in sources :

Example 41 with BXML

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

the class JSONTest method testToXMLKeyWithAttribute.

@Test(description = "Convert json object with attribute")
public void testToXMLKeyWithAttribute() {
    BValue[] args = { new BJSON(jsonToXML18) };
    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\"/>");
}
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 42 with BXML

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

the class JSONTest method testToXMLComplexAttributes.

@Test(description = "Convert a complex json object with attributes")
public void testToXMLComplexAttributes() {
    BValue[] args = { new BJSON(jsonToXML13) };
    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\"><postalCode>94</postalCode>" + "<isOpen>true</isOpen><address city=\"Colombo\"><street>PalmGrove</street><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 43 with BXML

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

the class VariableDTO method getStringValue.

private String getStringValue(BValue bValue) {
    String bValueString;
    if (bValue instanceof BValueType || bValue instanceof BXML || bValue instanceof BJSON) {
        bValueString = bValue.stringValue();
    } else if (bValue instanceof BNewArray) {
        BNewArray bArray = (BNewArray) bValue;
        bValueString = "Array[" + bArray.size() + "] ";
        bValueString = bValueString + bArray.stringValue();
    } else if (bValue instanceof BMap) {
        BMap bmap = (BMap) bValue;
        bValueString = "Map[" + bmap.size() + "] ";
        bValueString = bValueString + bmap.stringValue();
    } else if (bValue instanceof BStruct) {
        BStruct bStruct = (BStruct) bValue;
        bValueString = "struct " + bStruct.getType().getName() + " ";
        bValueString = bValueString + bStruct.stringValue();
    } else {
        bValueString = "<Complex_Value>";
    }
    return bValueString;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BValueType(org.ballerinalang.model.values.BValueType) BNewArray(org.ballerinalang.model.values.BNewArray) BMap(org.ballerinalang.model.values.BMap) BXML(org.ballerinalang.model.values.BXML) BJSON(org.ballerinalang.model.values.BJSON)

Example 44 with BXML

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

the class MimeUtilityFunctionTest method testGetAndSetXml.

@Test(description = "Set xml data to entity and get the content back from entity as xml")
public void testGetAndSetXml() {
    BXML xmlContent = XMLUtils.parse("<name>ballerina</name>");
    BValue[] args = { xmlContent };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSetAndGetXml", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertEquals(((BXML) returns[0]).getTextValue().stringValue(), "ballerina");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) Test(org.testng.annotations.Test)

Example 45 with BXML

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

the class MimeUtilityFunctionTest method testGetXmlMoreThanOnce.

@Test(description = "Test whether the xml content can be retrieved properly when it is called multiple times")
public void testGetXmlMoreThanOnce() {
    BXML xmlContent = XMLUtils.parse("<name>ballerina</name>");
    BValue[] args = { xmlContent };
    BValue[] returns = BRunUtil.invoke(compileResult, "testGetXmlMultipleTimes", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertEquals(((BXML<Object>) returns[0]).getMessageAsString(), "<name>ballerina</name><name>ballerina</name><name>ballerina</name>");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BXML(org.ballerinalang.model.values.BXML) Test(org.testng.annotations.Test)

Aggregations

BXML (org.ballerinalang.model.values.BXML)52 BValue (org.ballerinalang.model.values.BValue)40 Test (org.testng.annotations.Test)29 BXMLItem (org.ballerinalang.model.values.BXMLItem)17 BJSON (org.ballerinalang.model.values.BJSON)16 OMNode (org.apache.axiom.om.OMNode)14 BXMLSequence (org.ballerinalang.model.values.BXMLSequence)11 BStruct (org.ballerinalang.model.values.BStruct)8 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)7 BString (org.ballerinalang.model.values.BString)3 BlobDataSource (org.ballerinalang.runtime.message.BlobDataSource)2 StringDataSource (org.ballerinalang.runtime.message.StringDataSource)2 IOException (java.io.IOException)1 FileChannel (java.nio.channels.FileChannel)1 ArrayList (java.util.ArrayList)1 BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)1 BBlob (org.ballerinalang.model.values.BBlob)1 BMap (org.ballerinalang.model.values.BMap)1 BNewArray (org.ballerinalang.model.values.BNewArray)1 BValueType (org.ballerinalang.model.values.BValueType)1