public void testSetServletResponseJson() throws DataSourceException {
// Basic test 1.
DataTable data = getTestDataTable();
DataSourceParameters dsParamsJson =
new DataSourceParameters("responseHandler:babylon;out:json");
ResponseStatus responseStatus = new ResponseStatus(StatusType.OK, null, null);
String expected = "{\"version\":\"0.6\",\"status\":\"ok\","
+ "\"sig\":\"2087475733\",\"table\":"
+ "{\"cols\":[{\"id\":\"A\",\"label\":\"col0\",\"type\":\"string\",\"pattern\":\"\"},"
+ "{\"id\":\"B\",\"label\":\"col1\",\"type\":\"number\",\"pattern\":\"\"},"
+ "{\"id\":\"C\",\"label\":\"col2\",\"type\":\"boolean\",\"pattern\":\"\"}],"
+ "\"rows\":[{\"c\":[{\"v\":\"aaa\"},{\"v\":222.0,\"f\":\"222\"},{\"v\":false}]},"
+ "{\"c\":[{\"v\":\"\"},{\"v\":111.0},{\"v\":true}]},"
+ "{\"c\":[{\"v\":\"bbb\"},{\"v\":333.0},{\"v\":true}]},"
+ "{\"c\":[{\"v\":\"ddd\"},{\"v\":222.0},{\"v\":false}]}]}}";
assertEquals(expected, JsonRenderer.renderJsonResponse(
dsParamsJson, responseStatus, data).toString());
DataSourceParameters dsParamsJsonP =
new DataSourceParameters("responseHandler:babylon;out:jsonp");
assertEquals("babylon(" + expected + ");", JsonRenderer.renderJsonResponse(
dsParamsJsonP, responseStatus, data).toString());
// Basic test 2.
data = getTestDataTable();
dsParamsJson = new DataSourceParameters("reqId:90210;responseHandler:babylon;");
responseStatus = new ResponseStatus(StatusType.OK, null, null);
expected = "{\"version\":\"0.6\",\"reqId\":\"90210\",\"status\":\"ok\","
+ "\"sig\":\"2087475733\",\"table\":"
+ "{\"cols\":[{\"id\":\"A\",\"label\":\"col0\",\"type\":\"string\",\"pattern\":\"\"},"
+ "{\"id\":\"B\",\"label\":\"col1\",\"type\":\"number\",\"pattern\":\"\"},"