use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class GlobalVarServiceTest method testAccessingChangedGlobalVarInAnotherResourceInAnotherService.
@Test(description = "Test accessing changed global var in another resource in different service", enabled = false)
public void testAccessingChangedGlobalVarInAnotherResourceInAnotherService() {
HTTPTestRequest cMsgChange = MessageUtils.generateHTTPMessage("/globalvar/change-resource-level", "GET");
Services.invokeNew(result, cMsgChange);
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-second/get-changed-resource-level", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarFloatChange":77.87}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarFloatChange").asText(), "77.87");
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class GlobalVarServiceTest method testDefiningGlobalVarInService.
@Test(description = "Test defining global variables in services", enabled = false)
public void testDefiningGlobalVarInService() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar/defined", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarInt":800, "glbVarString":"value", "glbVarFloat":99.34323}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarInt").asText(), "800");
Assert.assertEquals(bJson.value().get("glbVarString").asText(), "value");
Assert.assertEquals(bJson.value().get("glbVarFloat").asText(), "99.34323");
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class GlobalVarServiceTest method testAccessingGlobalVarInServiceLevel.
@Test(description = "Test accessing global variables in service level", enabled = false)
public void testAccessingGlobalVarInServiceLevel() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar/access-service-level", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"serviceVarFloat":99.34323}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("serviceVarFloat").asText(), "99.34323");
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class BJSONValueTest method testUpdateNestedElement.
// @Test
// public void testJsonArrayWithVariable() {
// BValue[] returns = BLangFunctions.invoke(bLangProgram, "testJsonArrayWithVariable");
// Assert.assertTrue(returns[0] instanceof BJSON);
// Assert.assertEquals(returns[0].stringValue(), "[\"a\",\"b\",\"c\",{\"name\":\"supun\"}]");
// }
@Test
public void testUpdateNestedElement() {
BValue[] returns = BRunUtil.invoke(compileResult, "testUpdateNestedElement");
Assert.assertTrue(returns[0] instanceof BJSON);
BJSON json = ((BJSON) returns[0]);
Assert.assertEquals(json.toString(), "{\"details\":{\"fname\":\"Supun\",\"lname\":\"Setunga\"}}");
}
use of org.ballerinalang.model.values.BJSON in project ballerina by ballerina-lang.
the class BJSONValueTest method testUpdateJsonArrayInArray.
@Test
public void testUpdateJsonArrayInArray() {
BValue[] returns = BRunUtil.invoke(compileResult, "testUpdateJsonArrayInArray");
Assert.assertTrue(returns[0] instanceof BJSON);
BJSON json = ((BJSON) returns[0]);
Assert.assertEquals(json.toString(), "[\"a\",[1,2,3],\"c\"]");
}
Aggregations