use of org.wso2.transport.http.netty.message.HTTPCarbonMessage in project ballerina by ballerina-lang.
the class ResponseNativeFunctionSuccessTest method testGetContentLength.
@Test
public void testGetContentLength() {
BStruct inResponse = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, inResStruct);
HTTPCarbonMessage inResponseMsg = HttpUtil.createHttpCarbonMessage(false);
String payload = "ballerina";
inResponseMsg.setHeader(HttpHeaderNames.CONTENT_LENGTH.toString(), String.valueOf(payload.length()));
inResponseMsg.setProperty(HttpConstants.HTTP_STATUS_CODE, 200);
HttpUtil.addCarbonMsg(inResponse, inResponseMsg);
BStruct entity = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageMime, entityStruct);
BStruct mediaType = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageMime, mediaTypeStruct);
BStruct cacheControl = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, resCacheControlStruct);
ResponseCacheControlStruct cacheControlStruct = new ResponseCacheControlStruct(cacheControl);
HttpUtil.populateInboundResponse(inResponse, entity, mediaType, cacheControlStruct, inResponseMsg);
BValue[] inputArg = { inResponse };
BValue[] returnVals = BRunUtil.invoke(result, "testGetContentLength", inputArg);
Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
Assert.assertEquals(String.valueOf(payload.length()), returnVals[0].stringValue());
}
use of org.wso2.transport.http.netty.message.HTTPCarbonMessage 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.HTTPCarbonMessage in project ballerina by ballerina-lang.
the class ResponseNativeFunctionSuccessTest method testForwardMethod.
@Test
public void testForwardMethod() {
String path = "/hello/11";
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");
}
use of org.wso2.transport.http.netty.message.HTTPCarbonMessage 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.HTTPCarbonMessage in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testHttpOnlyFlagInSessionCookie.
@Test(description = "Test for HttpOnly flag in session cookie")
public void testHttpOnlyFlagInSessionCookie() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample/test1", "GET");
HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(responseMsg);
String cookie = responseMsg.getHeader(RESPONSE_COOKIE_HEADER);
Assert.assertNotNull(cookie);
Assert.assertTrue(CookieUtils.getCookie(cookie).httpOnly);
}
Aggregations