tableRow.addCell("Why?");
dataTable.addRow(tableRow);
DataSourceRequest dataSourceRequest = new DataSourceRequest(
new Query(),
new DataSourceParameters(null),
ULocale.UK);
assertEquals(
"{\"version\":\"0.6\",\"status\":\"ok\",\"sig\":\"1548939605\","
+ "\"table\":{\"cols\":[{\"id\":\"col1\",\"label\":\"column1\","
+ "\"type\":\"number\",\"pattern\":\"\"},"
+ "{\"id\":\"col2\",\"label\":\"column2\",\"type\":\"boolean\",\"pattern\":\"\"},"
+ "{\"id\":\"col3\",\"label\":\"column3\",\"type\":\"string\",\"pattern\":\"\"}],"
+ "\"rows\":[{\"c\":[{\"v\":7.0},{\"v\":false},{\"v\":\"Why?\"}]}]}}",
DataSourceHelper.generateResponse(dataTable, dataSourceRequest));
// With reqId:666;
dataSourceRequest = new DataSourceRequest(
new Query(),
new DataSourceParameters("reqId:666"),
ULocale.UK);
assertEquals(
"{\"version\":\"0.6\",\"reqId\":\"666\",\"status\":\"ok\",\"sig\":\"1548939605\","
+ "\"table\":{\"cols\":[{\"id\":\"col1\",\"label\":\"column1\","
+ "\"type\":\"number\",\"pattern\":\"\"},"
+ "{\"id\":\"col2\",\"label\":\"column2\",\"type\":\"boolean\",\"pattern\":\"\"},"
+ "{\"id\":\"col3\",\"label\":\"column3\",\"type\":\"string\",\"pattern\":\"\"}],"
+ "\"rows\":[{\"c\":[{\"v\":7.0},{\"v\":false},{\"v\":\"Why?\"}]}]}}",
DataSourceHelper.generateResponse(dataTable, dataSourceRequest));
// With out:json;
dataSourceRequest = new DataSourceRequest(
new Query(),
new DataSourceParameters("out:json"),
ULocale.UK);
assertEquals(
"{\"version\":\"0.6\",\"status\":\"ok\",\"sig\":\"1548939605\","
+ "\"table\":{\"cols\":[{\"id\":\"col1\",\"label\":\"column1\","
+ "\"type\":\"number\",\"pattern\":\"\"},"
+ "{\"id\":\"col2\",\"label\":\"column2\",\"type\":\"boolean\",\"pattern\":\"\"},"
+ "{\"id\":\"col3\",\"label\":\"column3\",\"type\":\"string\",\"pattern\":\"\"}],"
+ "\"rows\":[{\"c\":[{\"v\":7.0},{\"v\":false},{\"v\":\"Why?\"}]}]}}",
DataSourceHelper.generateResponse(dataTable, dataSourceRequest));
// With out:jsonp;
dataSourceRequest = new DataSourceRequest(
new Query(),
new DataSourceParameters("out:jsonp"),
ULocale.UK);
assertEquals(
"// Data table response\ngoogle.visualization.Query.setResponse("
+ "{\"version\":\"0.6\",\"status\":\"ok\",\"sig\":\"1548939605\","
+ "\"table\":{\"cols\":[{\"id\":\"col1\",\"label\":\"column1\","
+ "\"type\":\"number\",\"pattern\":\"\"},"
+ "{\"id\":\"col2\",\"label\":\"column2\",\"type\":\"boolean\",\"pattern\":\"\"},"
+ "{\"id\":\"col3\",\"label\":\"column3\",\"type\":\"string\",\"pattern\":\"\"}],"
+ "\"rows\":[{\"c\":[{\"v\":7.0},{\"v\":false},{\"v\":\"Why?\"}]}]}});",
DataSourceHelper.generateResponse(dataTable, dataSourceRequest));
// Now with out:csv;
dataSourceRequest = new DataSourceRequest(
new Query(),
new DataSourceParameters("out:tsv-excel"),
ULocale.UK);
assertEquals(
"\"column1\"\t\"column2\"\t\"column3\"\n7\tfalse\t\"Why?\"\n",
DataSourceHelper.generateResponse(dataTable, dataSourceRequest));
// Now with out:tsv-excel;
dataSourceRequest = new DataSourceRequest(
new Query(),
new DataSourceParameters("out:csv;reqId:7"),
ULocale.UK);
assertEquals(
"\"column1\",\"column2\",\"column3\"\n7,false,\"Why?\"\n",
DataSourceHelper.generateResponse(dataTable, dataSourceRequest));
}