use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class ResponseNativeFunctionSuccessTest method testServiceGetStringPayload.
@Test(description = "Test GetStringPayload function within a service")
public void testServiceGetStringPayload() {
String value = "ballerina";
String path = "/hello/GetStringPayload/" + value;
HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
Assert.assertNotNull(response, "Response message not found");
Assert.assertEquals(StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), value);
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testCheckPathValiditygetSession.
@Test(description = "Test for path limitation with getSession")
public void testCheckPathValiditygetSession() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample2/echoName", "GET");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response);
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
;
Assert.assertNotNull(responseMsgPayload);
Assert.assertEquals(responseMsgPayload, "wso2");
String cookie = response.getHeader(RESPONSE_COOKIE_HEADER);
String sessionId = CookieUtils.getCookie(cookie).value;
cMsg = MessageUtils.generateHTTPMessage("/counter/echo2", "GET");
cMsg.setHeader(COOKIE_HEADER, SESSION_ID + sessionId);
response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response);
responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertNotNull(responseMsgPayload);
Assert.assertTrue(responseMsgPayload.contains("failed to get session: " + "/counter is not an allowed path"));
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testGetAttributeNamesFunction.
@Test(description = "Test for getAttributeNames function")
public void testGetAttributeNamesFunction() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample2/names", "GET");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response);
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertNotNull(responseMsgPayload);
Assert.assertEquals(responseMsgPayload, "arraysize:2");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testGetSessionWithoutSessionIDCheck.
@Test(description = "Test for getting a session without Id at first time")
public void testGetSessionWithoutSessionIDCheck() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample/test2", "GET");
HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(responseMsg);
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(responseMsg).getInputStream());
Assert.assertNotNull(responseMsgPayload);
Assert.assertEquals(responseMsgPayload, "no session id available");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testCheckPathValidity.
@Test(description = "Test for path limitation")
public void testCheckPathValidity() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/counter/echo", "GET");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response);
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
;
Assert.assertNotNull(responseMsgPayload);
Assert.assertEquals(responseMsgPayload, "1");
String cookie = response.getHeader(RESPONSE_COOKIE_HEADER);
String sessionId = CookieUtils.getCookie(cookie).value;
cMsg = MessageUtils.generateHTTPMessage("/sample2/echoName", "GET");
cMsg.setHeader(COOKIE_HEADER, SESSION_ID + sessionId);
response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response);
responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertNotNull(responseMsgPayload);
Assert.assertTrue(responseMsgPayload.contains("failed to get session: /sample2 is not an allowed path"));
}
Aggregations