use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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.wso2.transport.http.netty.message.HttpMessageDataStreamer 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.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class UriMatrixParametersMatchTest method testErrorReportInURI.
@Test
public void testErrorReportInURI() {
// encoded URI
String path = "/hello/t2/john;age;color=white/foo;a=5;b=10";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 500, "Response code mismatch");
// checking the exception message
String errorMessage = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertNotNull(errorMessage, "Message body null");
Assert.assertTrue(errorMessage.contains("found non-matrix parameter"), "Expected error not found.");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class UriMatrixParametersMatchTest method testNonEncodedUrlDispatching.
@Test
public void testNonEncodedUrlDispatching() {
// encoded URI
String path = "/hello/t2/john;age=2;color=white/foo;a=5;b=10";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 404, "Response code mismatch");
// checking the exception message
String errorMessage = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertNotNull(errorMessage, "Message body null");
Assert.assertTrue(errorMessage.contains("no matching resource found for path"), "Expected error not found.");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class UriMatrixParametersMatchTest method testEncodedPathDispatching.
@Test
public void testEncodedPathDispatching() {
// encoded URI
String path = "/hello/t2/john;age=2;color=white/foo%3Ba%3D5%3Bb%3D10";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("person").asText(), "john");
Assert.assertEquals(bJson.value().get("personParamSize").asText(), "2");
Assert.assertEquals(bJson.value().get("fooParamSize").asText(), "0");
}
Aggregations