use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.
the class RequestNativeFunctionSuccessTest method testServiceAddHeader.
@Test(description = "Test addHeader function within a service")
public void testServiceAddHeader() {
String key = "lang";
String value = "ballerina";
String path = "/hello/addheader/" + key + "/" + value;
HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(ResponseReader.getReturnValue(response));
Assert.assertEquals(bJson.value().get(key).asText(), value);
}
use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.
the class RequestNativeFunctionSuccessTest method testGetRequestURL.
@Test
public void testGetRequestURL() {
String path = "/hello/12";
HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
Assert.assertNotNull(response, "Response message not found");
Assert.assertEquals(StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), path);
}
use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.
the class RequestNativeFunctionSuccessTest method testServiceGetHeader.
@Test(description = "Test GetHeader function within a service")
public void testServiceGetHeader() {
String path = "/hello/getHeader";
HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
inRequestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_FORM);
HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("value").asText(), APPLICATION_FORM);
}
use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.
the class RequestNativeFunctionSuccessTest method testServiceGetJsonPayload.
@Test(description = "Test GetJsonPayload function within a service")
public void testServiceGetJsonPayload() {
String key = "lang";
String value = "ballerina";
String path = "/hello/getJsonPayload";
String jsonString = "{\"" + key + "\":\"" + value + "\"}";
List<Header> headers = new ArrayList<>();
headers.add(new Header(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_JSON));
HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_POST, headers, jsonString);
HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
Assert.assertNotNull(response, "Response message not found");
Assert.assertEquals(new BJSON(ResponseReader.getReturnValue(response)).value().stringValue(), value);
}
use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.
the class RequestNativeFunctionSuccessTest method testServiceSetXmlPayload.
@Test(description = "Test SetXmlPayload function within a service")
public void testServiceSetXmlPayload() {
String value = "Ballerina";
String path = "/hello/SetXmlPayload/";
HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("lang").asText(), value);
}
Aggregations