use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testGetSessionWithInvalidSessionCookie.
@Test(description = "Test getSession with invalid session cookie")
public void testGetSessionWithInvalidSessionCookie() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample/test2", "GET");
cMsg.setHeader(COOKIE_HEADER, SESSION_ID + "A4673299S549242");
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");
Assert.assertTrue(responseMsg.getHeader(RESPONSE_COOKIE_HEADER) == null);
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testGetSessionHappyPathMethod.
@Test(description = "Test getting a session with at first time")
public void testGetSessionHappyPathMethod() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample/test1", "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, "session created");
String cookie = response.getHeader(RESPONSE_COOKIE_HEADER);
String sessionId = CookieUtils.getCookie(cookie).value;
cMsg = MessageUtils.generateHTTPMessage("/sample/test2", "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.assertEquals(responseMsgPayload, "session is returned");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testGetAttributeFunction.
@Test(description = "Test for Get Attribute Function")
public void testGetAttributeFunction() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample/test4", "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, "attribute not available");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testCreateTwoSessionsMethod.
@Test(description = "Test for create two sessions ")
public void testCreateTwoSessionsMethod() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample/test6", "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");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testSessionForStructAttribute.
@Test(description = "Test for struct attribute")
public void testSessionForStructAttribute() {
List<Header> headers = new ArrayList<Header>();
headers.add(new Header(HttpHeaderNames.CONTENT_TYPE.toString(), TEXT_PLAIN));
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample2/myStruct", "POST", headers, "wso2");
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("/sample2/myStruct", "POST", headers, "chamil");
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.assertEquals(responseMsgPayload, "wso2");
}
Aggregations