Search in sources :

Example 56 with HTTPTestRequest

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);
}
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 57 with HTTPTestRequest

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");
}
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 58 with HTTPTestRequest

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");
}
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 59 with HTTPTestRequest

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");
}
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 60 with HTTPTestRequest

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");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) Header(org.wso2.carbon.messaging.Header) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) ArrayList(java.util.ArrayList) 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