use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class MultipartFormDataDecoderTest method testBinaryBodyPart.
@Test(description = "Test sending a multipart request with a binary body part which is kept in memory")
public void testBinaryBodyPart() {
String path = "/test/binarybodypart";
Map<String, Object> messageMap = Util.createPrerequisiteMessages(path, MULTIPART_FORM_DATA, result);
ArrayList<BStruct> bodyParts = new ArrayList<>();
bodyParts.add(Util.getBinaryBodyPart(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(ResponseReader.getReturnValue(response), "Ballerina binary part");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class MultipartFormDataDecoderTest method testTextBodyPartAsFileUpload.
@Test(description = "Test sending a multipart request with a text body part where the content is kept in a file")
public void testTextBodyPartAsFileUpload() {
String path = "/test/textbodypart";
Map<String, Object> messageMap = Util.createPrerequisiteMessages(path, MULTIPART_FORM_DATA, result);
ArrayList<BStruct> bodyParts = new ArrayList<>();
bodyParts.add(Util.getTextFilePart(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(ResponseReader.getReturnValue(response), "Ballerina text as a file part");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class MultipartFormDataDecoderTest method testTextBodyPartWith8BitEncoding.
@Test(description = "Test sending a multipart request with a text body part that has 8 bit transfer encoding")
public void testTextBodyPartWith8BitEncoding() {
String path = "/test/textbodypart";
Map<String, Object> messageMap = Util.createPrerequisiteMessages(path, MULTIPART_FORM_DATA, result);
ArrayList<BStruct> bodyParts = new ArrayList<>();
bodyParts.add(Util.getTextFilePartWithEncoding(CONTENT_TRANSFER_ENCODING_8_BIT, "èlllll", 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(ResponseReader.getReturnValue(response), "èlllll");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class Util method createPrerequisiteMessages.
/**
* Create prerequisite messages that are needed to proceed with the test cases.
*
* @param path Represent path to the ballerina resource
* @param topLevelContentType Content type that needs to be set to the top level message
* @param result Result of ballerina file compilation
* @return A map of relevant messages
*/
static Map<String, Object> createPrerequisiteMessages(String path, String topLevelContentType, CompileResult result) {
Map<String, Object> messageMap = new HashMap<>();
BStruct request = getRequestStruct(result);
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessageForMultiparts(path, HttpConstants.HTTP_METHOD_POST);
HttpUtil.addCarbonMsg(request, cMsg);
BStruct entity = getEntityStruct(result);
MimeUtil.setContentType(getMediaTypeStruct(result), entity, topLevelContentType);
messageMap.put(CARBON_MESSAGE, cMsg);
messageMap.put(BALLERINA_REQUEST, request);
messageMap.put(MULTIPART_ENTITY, entity);
return messageMap;
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class IdentifierLiteralServiceTest method testIdentifierLiteralsInPayload.
@Test(description = "Test identifier literals payload", enabled = false)
public void testIdentifierLiteralsInPayload() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/identifierLiteral/resource2", "GET");
HTTPCarbonMessage response = Services.invokeNew(application, cMsg);
Assert.assertNotNull(response);
String payload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(payload, "hello");
}
Aggregations