use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class RequestNativeFunctionSuccessTest method testServiceSetHeader.
@Test(description = "Test SetHeader function within a service")
public void testServiceSetHeader() {
String key = "lang";
String value = "ballerina";
String path = "/hello/setHeader/" + 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(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("value").asText(), value);
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class RequestNativeFunctionSuccessTest method testSetJsonPayload.
@Test
public void testSetJsonPayload() {
BJSON value = new BJSON("{'name':'wso2'}");
BValue[] inputArg = { value };
BValue[] returnVals = BRunUtil.invoke(result, "testSetJsonPayload", inputArg);
Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVals[0] instanceof BStruct);
BStruct entity = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
BJSON bJson = (BJSON) EntityBodyHandler.getMessageDataSource(entity);
Assert.assertEquals(bJson.value().get("name").asText(), "wso2", "Payload is not set properly");
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class RequestNativeFunctionSuccessTest method testServiceSetBinaryPayload.
@Test(description = "Test setBinaryPayload() function within a service")
public void testServiceSetBinaryPayload() {
String value = "Ballerina";
String path = "/hello/SetBinaryPayload/";
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);
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class ResponseNativeFunctionSuccessTest method testServiceRemoveAllHeaders.
@Test(description = "Test RemoveAllHeaders function within a service")
public void testServiceRemoveAllHeaders() {
String path = "/hello/RemoveAllHeaders";
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("value").asText(), "value is null");
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class ResponseNativeFunctionSuccessTest 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(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get(key).asText(), value);
}
Aggregations