use of org.ballerinalang.model.values.BXML in project ballerina by ballerina-lang.
the class XMLNativeFunctionTest method testSelectDescendants.
@Test
public void testSelectDescendants() {
BValue[] returns = BRunUtil.invoke(result, "testSelectDescendants");
Assert.assertTrue(returns[0] instanceof BXML);
BXMLSequence seq = (BXMLSequence) returns[0];
Assert.assertEquals(seq.value().size(), 2);
Assert.assertEquals(seq.stringValue(), "<name xmlns=\"http://ballerinalang.org/\" " + "xmlns:ns0=\"http://ballerinalang.org/aaa\"><name>Supun</name><lname>Setunga</lname></name>" + "<name xmlns=\"http://ballerinalang.org/\" xmlns:ns0=\"http://ballerinalang.org/aaa\">John</name>");
}
use of org.ballerinalang.model.values.BXML in project ballerina by ballerina-lang.
the class MultipartEncoderTest method validateBodyPartContent.
/**
* Validate that the decoded body part content matches with the encoded content.
*
* @param mimeParts List of decoded body parts
* @param bodyPart Ballerina body part
* @throws IOException When an exception occurs during binary data decoding
*/
private void validateBodyPartContent(List<MIMEPart> mimeParts, BStruct bodyPart) throws IOException {
EntityBodyHandler.populateBodyContent(bodyPart, mimeParts.get(0));
BJSON jsonData = EntityBodyHandler.constructJsonDataSource(bodyPart);
Assert.assertNotNull(jsonData);
Assert.assertEquals(jsonData.getMessageAsString(), "{\"" + "bodyPart" + "\":\"" + "jsonPart" + "\"}");
EntityBodyHandler.populateBodyContent(bodyPart, mimeParts.get(1));
BXML xmlData = EntityBodyHandler.constructXmlDataSource(bodyPart);
Assert.assertNotNull(xmlData);
Assert.assertEquals(xmlData.getMessageAsString(), "<name>Ballerina xml file part</name>");
EntityBodyHandler.populateBodyContent(bodyPart, mimeParts.get(2));
StringDataSource textData = EntityBodyHandler.constructStringDataSource(bodyPart);
Assert.assertNotNull(textData);
Assert.assertEquals(textData.getMessageAsString(), "Ballerina text body part");
EntityBodyHandler.populateBodyContent(bodyPart, mimeParts.get(3));
BlobDataSource blobDataSource = EntityBodyHandler.constructBlobDataSource(bodyPart);
Assert.assertNotNull(blobDataSource);
Assert.assertEquals(blobDataSource.getMessageAsString(), "Ballerina binary file part");
}
use of org.ballerinalang.model.values.BXML in project ballerina by ballerina-lang.
the class HttpDispatcher method populateAndGetEntityBody.
private static BValue populateAndGetEntityBody(HttpResource httpResource, BStruct inRequest, BStruct inRequestEntity, BType entityBodyType) throws IOException {
HttpUtil.populateEntityBody(null, inRequest, inRequestEntity, true);
switch(entityBodyType.getTag()) {
case TypeTags.STRING_TAG:
StringDataSource stringDataSource = EntityBodyHandler.constructStringDataSource(inRequestEntity);
EntityBodyHandler.addMessageDataSource(inRequestEntity, stringDataSource);
return stringDataSource != null ? new BString(stringDataSource.getMessageAsString()) : null;
case TypeTags.JSON_TAG:
BJSON bjson = EntityBodyHandler.constructJsonDataSource(inRequestEntity);
EntityBodyHandler.addMessageDataSource(inRequestEntity, bjson);
return bjson;
case TypeTags.XML_TAG:
BXML bxml = EntityBodyHandler.constructXmlDataSource(inRequestEntity);
EntityBodyHandler.addMessageDataSource(inRequestEntity, bxml);
return bxml;
case TypeTags.BLOB_TAG:
BlobDataSource blobDataSource = EntityBodyHandler.constructBlobDataSource(inRequestEntity);
EntityBodyHandler.addMessageDataSource(inRequestEntity, blobDataSource);
return new BBlob(blobDataSource != null ? blobDataSource.getValue() : new byte[0]);
case TypeTags.STRUCT_TAG:
bjson = EntityBodyHandler.constructJsonDataSource(inRequestEntity);
EntityBodyHandler.addMessageDataSource(inRequestEntity, bjson);
try {
return JSONUtils.convertJSONToStruct(bjson, (BStructType) entityBodyType);
} catch (NullPointerException ex) {
throw new BallerinaConnectorException("cannot convert payload to struct type: " + entityBodyType.getName());
}
}
return null;
}
use of org.ballerinalang.model.values.BXML in project ballerina by ballerina-lang.
the class Copy method execute.
@Override
public void execute(Context ctx) {
BValue result = null;
try {
// Accessing Parameters.
BXML value = (BXML) ctx.getRefArgument(0);
result = value.copy();
} catch (Throwable e) {
ErrorHandler.handleXMLException(OPERATION, e);
}
// Setting output value.
ctx.setReturnValues(result);
}
use of org.ballerinalang.model.values.BXML in project ballerina by ballerina-lang.
the class Elements method execute.
@Override
public void execute(Context ctx) {
BValue result = null;
try {
// Accessing Parameters.
BXML value = (BXML) ctx.getRefArgument(0);
result = value.elements();
} catch (Throwable e) {
ErrorHandler.handleXMLException(OPERATION, e);
}
// Setting output value.
ctx.setReturnValues(result);
}
Aggregations