Search in sources :

Example 46 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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 47 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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 48 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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 49 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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 50 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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

HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)176 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)172 Test (org.testng.annotations.Test)172 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)172 BJSON (org.ballerinalang.model.values.BJSON)104 BString (org.ballerinalang.model.values.BString)21 ArrayList (java.util.ArrayList)5 Header (org.wso2.carbon.messaging.Header)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ExecutorService (java.util.concurrent.ExecutorService)4 Semaphore (java.util.concurrent.Semaphore)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MimeTypeParseException (javax.activation.MimeTypeParseException)2 BStruct (org.ballerinalang.model.values.BStruct)2 StringDataSource (org.ballerinalang.runtime.message.StringDataSource)2 MIMEPart (org.jvnet.mimepull.MIMEPart)2 EncoderException (io.netty.handler.codec.EncoderException)1 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1