use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testBogusConsumesAnnotation.
@Test(description = "Test bogus Consumes annotation with URL. /echo66/test1 ")
public void testBogusConsumesAnnotation() {
String path = "/echo66/test1";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), ",:vhjv");
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");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testProducesAnnotationWithSubTypeWildCard.
@Test(description = "Test Produces with sub type wildcard header with URL. /echo66/test2 ")
public void testProducesAnnotationWithSubTypeWildCard() {
String path = "/echo66/test2";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
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("msg").asText(), "wso22", "media type matched");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testProducesConsumeAnnotation.
@Test(description = "Test Produces and Consumes with URL. /echo66/test3 ")
public void testProducesConsumeAnnotation() {
String path = "/echo66/test3";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
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("msg").asText(), "wso222", "media types matched");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testProducesAnnotationWithWildCard.
@Test(description = "Test Produces with wildcard header with URL. /echo66/test2 ")
public void testProducesAnnotationWithWildCard() {
String path = "/echo66/test2";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "*/*, 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("msg").asText(), "wso22", "media type matched");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testIncorrectProducesConsumeAnnotation.
@Test(description = "Test Incorrect Produces and Consumes with URL. /echo66/test3 ")
public void testIncorrectProducesConsumeAnnotation() {
String path = "/echo66/test3";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "text/plain ; charset=ISO-8859-4");
cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "compileResult/xml, text/html");
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, 406, "Not acceptable");
}
Aggregations