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\"/>");
}
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>");
}
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;
}
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");
}
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>");
}
Aggregations