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");
}
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);
}
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(), "");
}
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");
}
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);
}
Aggregations