Search in sources :

Example 61 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class HTTPSessionSubMethodsTest method testGetCreateTimeFunctionError.

@Test(description = "Test for GetCreateTime Function error")
public void testGetCreateTimeFunctionError() {
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample2/new3", "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.assertTrue(responseMsgPayload.contains("No such session in progress"));
}
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 62 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class HTTPSessionSubMethodsTest method testIsNewFunctiontwoAttempts.

@Test(description = "Test for isNew Function two attempts")
public void testIsNewFunctiontwoAttempts() {
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample2/new1", "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, "true");
    String cookie = response.getHeader(RESPONSE_COOKIE_HEADER);
    String sessionId = CookieUtils.getCookie(cookie).value;
    cMsg = MessageUtils.generateHTTPMessage("/sample2/new1", "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, "false");
}
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 63 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class HTTPSessionSubMethodsTest method testGetLastAccessedTimeFunctionError.

@Test(description = "Test for GetLastAccessed Function error")
public void testGetLastAccessedTimeFunctionError() {
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample2/new5", "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.assertTrue(responseMsgPayload.contains("No such session in progress"));
}
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 64 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class ServiceTest method testGetFormParamsEmptyresponseMsgPayload.

@Test(description = "Test GetFormParams empty responseMsgPayloads")
public void testGetFormParamsEmptyresponseMsgPayload() {
    String path = "/echo/getFormParams";
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage(path, "POST", "");
    requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_FORM);
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg, "responseMsg message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
    Assert.assertNotNull(bJson);
    Assert.assertNull(bJson.value().get("Name").stringValue());
    Assert.assertNull(bJson.value().get("Team").stringValue());
}
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) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 65 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class ServiceTest method testGetFormParamsForUndefinedKey.

@Test(description = "Test GetFormParams with undefined key")
public void testGetFormParamsForUndefinedKey() {
    String path = "/echo/getFormParams";
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage(path, "POST", "firstName=WSO2&company=BalDance");
    requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_FORM);
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg, "responseMsg message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
    Assert.assertTrue(bJson.value().get("Team").isNull(), "Team variable not set properly.");
}
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) BJSON(org.ballerinalang.model.values.BJSON) 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