use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class DataBindingTest method testDataBindingWhenPathParamExist.
@Test(description = "Test data binding when path param exists")
public void testDataBindingWhenPathParamExist() {
HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/body2/hello", "POST", "WSO2");
requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), TEXT_PLAIN);
HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_EP, requestMsg);
Assert.assertNotNull(responseMsg, "responseMsg message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
Assert.assertEquals(bJson.value().get("Key").asText(), "hello", "Key variable not set properly.");
Assert.assertEquals(bJson.value().get("Person").asText(), "WSO2", "Person variable not set properly.");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class DataBindingTest method testDataBindingIncompatibleStructPayload.
@Test(expectedExceptions = BallerinaConnectorException.class, expectedExceptionsMessageRegExp = ".*failed to create json: unrecognized token 'ballerina'.*")
public void testDataBindingIncompatibleStructPayload() {
HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/body6", "POST", "ballerina");
requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), TEXT_PLAIN);
Services.invokeNew(compileResult, TEST_EP, requestMsg);
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testWithoutProducesConsumeAnnotation.
@Test(description = "Test without Pro-Con annotation with URL. /echo67/echo1 ")
public void testWithoutProducesConsumeAnnotation() {
String path = "/echo67/echo1";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "text/plain; charset=ISO-8859-4");
cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "text/*;q=0.3, text/html;Level=1;q=0.7");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("echo33").asText(), "echo1", "No media types");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testProducesAnnotation.
@Test(description = "Test Produces annotation with URL. /echo66/test2 ")
public void testProducesAnnotation() {
String path = "/echo66/test2";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "text/xml;q=0.3, multipart/*;Level=1;q=0.7");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("msg").asText(), "wso22", "media type matched");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testIncorrectConsumesAnnotation.
@Test(description = "Test incorrect Consumes annotation with URL. /echo66/test1 ")
public void testIncorrectConsumesAnnotation() {
String path = "/echo66/test1";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "compileResult/json");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
int trueResponse = (int) response.getProperty(HttpConstants.HTTP_STATUS_CODE);
Assert.assertEquals(trueResponse, 415, "Unsupported media type");
}
Aggregations