use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class JSONTest method testToXMLEmptyElementsWithNonEmpty.
@Test(description = "Convert a json object with empty elements and non emepty elements")
public void testToXMLEmptyElementsWithNonEmpty() {
BValue[] args = { new BJSON(jsonToXML11) };
BValue[] returns = BRunUtil.invoke(compileResult, "testToXML", args);
Assert.assertTrue(returns[0] instanceof BXML);
OMNode returnElement = ((BXMLItem) returns[0]).value();
Assert.assertEquals(returnElement.toString(), "<info><address/><homeAddresses><item>a</item><item>b</item>" + "</homeAddresses><phoneNumbers/></info>");
}
use of org.ballerinalang.model.values.BXMLItem 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.BXMLItem 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.BXMLItem in project ballerina by ballerina-lang.
the class MultipartFormDataDecoderTest method testXmlBodyPart.
@Test(description = "Test sending a multipart request with a xml body part which is kept in memory")
public void testXmlBodyPart() {
String path = "/test/xmlbodypart";
Map<String, Object> messageMap = Util.createPrerequisiteMessages(path, MULTIPART_FORM_DATA, result);
ArrayList<BStruct> bodyParts = new ArrayList<>();
bodyParts.add(Util.getXmlBodyPart(result));
HTTPTestRequest cMsg = Util.getCarbonMessageWithBodyParts(messageMap, Util.getArrayOfBodyParts(bodyParts));
HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response, "Response message not found");
Assert.assertEquals(new BXMLItem(ResponseReader.getReturnValue(response)).getTextValue().stringValue(), "Ballerina");
}
use of org.ballerinalang.model.values.BXMLItem in project ballerina by ballerina-lang.
the class ResponseNativeFunctionSuccessTest method testSetXmlPayload.
@Test
public void testSetXmlPayload() {
BXMLItem value = new BXMLItem("<name>Ballerina</name>");
BValue[] inputArg = { value };
BValue[] returnVals = BRunUtil.invoke(result, "testSetXmlPayload", inputArg);
Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVals[0] instanceof BStruct);
BStruct entity = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
BXML xmlValue = (BXML) EntityBodyHandler.getMessageDataSource(entity);
Assert.assertEquals(xmlValue.getTextValue().stringValue(), "Ballerina", "Payload is not set properly");
}
Aggregations