Search in sources :

Example 46 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest 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"));
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 47 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest 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);
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 48 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest 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");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 49 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest 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");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 50 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest 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"));
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Aggregations

HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)243 Test (org.testng.annotations.Test)241 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)233 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)172 BJSON (org.ballerinalang.model.values.BJSON)108 BString (org.ballerinalang.model.values.BString)32 ArrayList (java.util.ArrayList)26 BStruct (org.ballerinalang.model.values.BStruct)16 Header (org.wso2.carbon.messaging.Header)15 InputStream (java.io.InputStream)4 ExecutorService (java.util.concurrent.ExecutorService)4 Semaphore (java.util.concurrent.Semaphore)4 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 MimeTypeParseException (javax.activation.MimeTypeParseException)2 BValue (org.ballerinalang.model.values.BValue)2 BXMLItem (org.ballerinalang.model.values.BXMLItem)2 RequestCacheControlStruct (org.ballerinalang.net.http.caching.RequestCacheControlStruct)2 StringDataSource (org.ballerinalang.runtime.message.StringDataSource)2