Search in sources :

Example 76 with HttpCarbonMessage

use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.

the class ConnectionNativeFunctionTest method testRedirect.

@Test(description = "Test whether the headers and status codes are set correctly.")
public void testRedirect() {
    String path = "/hello/redirect";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 301);
    Assert.assertEquals(response.getHeader("Location"), "location1");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 77 with HttpCarbonMessage

use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.

the class ServiceEndpointTest method testGetProtocolConnectionStruct.

@Test(description = "Test the protocol value of ServiceEndpoint struct within a service")
public void testGetProtocolConnectionStruct() {
    String protocolValue = "http";
    String path = "/hello/protocol";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 200);
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("protocol").asText(), protocolValue);
}
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 78 with HttpCarbonMessage

use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.

the class RequestNativeFunctionNegativeTest method testGetMethodNegative.

@Test
public void testGetMethodNegative() {
    BStruct inRequest = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, reqStruct);
    HTTPCarbonMessage inRequestMsg = HttpUtil.createHttpCarbonMessage(true);
    HttpUtil.addCarbonMsg(inRequest, inRequestMsg);
    BValue[] inputArg = { inRequest };
    BValue[] returnVals = BRunUtil.invoke(result, "testGetMethod", inputArg);
    Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
    Assert.assertEquals(returnVals[0].stringValue(), "");
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) BValue(org.ballerinalang.model.values.BValue) Test(org.testng.annotations.Test)

Example 79 with HttpCarbonMessage

use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.

the class RequestNativeFunctionNegativeTest method testGetRequestURLNegative.

@Test
public void testGetRequestURLNegative() {
    BStruct inRequest = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, reqStruct);
    HTTPCarbonMessage inRequestMsg = HttpUtil.createHttpCarbonMessage(true);
    HttpUtil.addCarbonMsg(inRequest, inRequestMsg);
    BValue[] inputArg = { inRequest };
    BValue[] returnVals = BRunUtil.invoke(result, "testGetRequestURL", inputArg);
    Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
    Assert.assertEquals(returnVals[0].stringValue(), "no url");
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) BValue(org.ballerinalang.model.values.BValue) Test(org.testng.annotations.Test)

Example 80 with HttpCarbonMessage

use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.

the class RequestNativeFunctionSuccessTest method testServiceGetStringPayload.

@Test(description = "Test GetStringPayload function within a service")
public void testServiceGetStringPayload() {
    String value = "ballerina";
    String path = "/hello/GetStringPayload";
    List<Header> headers = new ArrayList<>();
    headers.add(new Header(HttpHeaderNames.CONTENT_TYPE.toString(), TEXT_PLAIN));
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_POST, headers, value);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(ResponseReader.getReturnValue(response), value);
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) Header(org.wso2.carbon.messaging.Header) ArrayList(java.util.ArrayList) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Aggregations

HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)308 Test (org.testng.annotations.Test)247 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)233 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)179 BJSON (org.ballerinalang.model.values.BJSON)108 BString (org.ballerinalang.model.values.BString)45 BStruct (org.ballerinalang.model.values.BStruct)43 Request (org.wso2.msf4j.Request)34 ArrayList (java.util.ArrayList)25 BValue (org.ballerinalang.model.values.BValue)19 Header (org.wso2.carbon.messaging.Header)14 Tracer (org.ballerinalang.util.tracer.Tracer)11 HttpCarbonMessage (org.wso2.transport.http.netty.message.HttpCarbonMessage)10 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)9 IOException (java.io.IOException)8 ResponseCacheControlStruct (org.ballerinalang.net.http.caching.ResponseCacheControlStruct)7 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)5 Semaphore (java.util.concurrent.Semaphore)5 APIMgtSecurityException (org.wso2.carbon.apimgt.rest.api.common.exception.APIMgtSecurityException)5 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)4