Package com.google.visualization.datasource.datatable

Examples of com.google.visualization.datasource.datatable.DataTable


  public void setUp() throws Exception {
    super.setUp();

    colIds = Lists.newArrayList();

    testData = new DataTable();
    ColumnDescription c0 = new ColumnDescription("col0", ValueType.TEXT, "label0");
    ColumnDescription c1 = new ColumnDescription("col1", ValueType.NUMBER, "label1");
    ColumnDescription c2 = new ColumnDescription("col2", ValueType.BOOLEAN, "label2");
    ColumnDescription c3 = new ColumnDescription("col3", ValueType.DATE, "label3");
    ColumnDescription c4 = new ColumnDescription("col4", ValueType.TIMEOFDAY, "label4");
View Full Code Here


    testData = null;
    rows = null;
  }

  public void testEmptyDataTableToHtml() {
    DataTable dataTable = new DataTable();
    String expected =
        "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">" + nl
        + "<html>" + nl
        + "<head>" + nl
        + "<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" + nl
View Full Code Here

  }

  public void testSimpleDataTableToHtml() throws DataSourceException {
    colIds = Lists.newArrayList();

    testData = new DataTable();
    ColumnDescription c0 = new ColumnDescription("A", ValueType.TEXT, "col0");
    ColumnDescription c1 = new ColumnDescription("B", ValueType.NUMBER, "col1");
    ColumnDescription c2 = new ColumnDescription("C", ValueType.BOOLEAN, "col2");

    testData.addColumn(c0);
View Full Code Here

    assertEquals(expected, actual);
  }

  public void testWarnings() throws DataSourceException {
    testData = new DataTable();
    ColumnDescription c0 = new ColumnDescription("A", ValueType.TEXT, "col0");
    ColumnDescription c1 = new ColumnDescription("B", ValueType.NUMBER, "col1");

    testData.addColumn(c0);
    testData.addColumn(c1);
View Full Code Here

* @author Nimrod T.
*/
public class ResponseWriterTest extends TestCase {

  private DataTable getTestDataTable() throws DataSourceException {
    DataTable dataTable = new DataTable();
    ColumnDescription c0 = new ColumnDescription("A", ValueType.TEXT, "col0");
    ColumnDescription c1 = new ColumnDescription("B", ValueType.NUMBER, "col1");
    ColumnDescription c2 = new ColumnDescription("C", ValueType.BOOLEAN, "col2");

    dataTable.addColumn(c0);
    dataTable.addColumn(c1);
    dataTable.addColumn(c2);

    List<TableRow> rows = Lists.newArrayList();

    TableRow row = new TableRow();
    row.addCell(new TableCell("aaa"));
    row.addCell(new TableCell(new NumberValue(222), "222"));
    row.addCell(new TableCell(false));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(""));
    row.addCell(new TableCell(111));
    row.addCell(new TableCell(true));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell((new TextValue("bbb")), "bbb"));
    row.addCell(new TableCell(333));
    row.addCell(new TableCell(true));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell("ddd"));
    row.addCell(new TableCell(222));
    row.addCell(new TableCell(false));
    rows.add(row);
    dataTable.addRows(rows);

    return dataTable;
  }
View Full Code Here

    return dataTable;
  }

  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\","
View Full Code Here

    assertEquals("babylon(" + expected + ");", JsonRenderer.renderJsonResponse(
        dsParamsJsonP, responseStatus, data).toString());
  }

  public void testGenerateJsonResponseError() throws DataSourceException {
    DataTable data = getTestDataTable();
    DataSourceParameters dsParamsJson =
        new DataSourceParameters("reqId:90210;responseHandler:babylon;");
    ResponseStatus responseStatus = new ResponseStatus(
        StatusType.ERROR,
        ReasonType.INTERNAL_ERROR,
View Full Code Here

      // Split the query.
      QueryPair query = DataSourceHelper.splitQuery(dsRequest.getQuery(),
          dtGenerator.getCapabilities());

      // Generate the data table.
      DataTable dataTable = dtGenerator.generateDataTable(query.getDataSourceQuery(), req);

      // Apply the completion query to the data table.
      DataTable newDataTable = DataSourceHelper.applyQuery(query.getCompletionQuery(), dataTable,
          dsRequest.getUserLocale());

      // Set the response.
      setServletResponse(newDataTable, dsRequest, resp);
    } catch (DataSourceException e) {
View Full Code Here

* @author Yaniv S.
*/
public class DataSourceHelperTest extends TestCase {

  private DataTable createData() throws TypeMismatchException {
    DataTable data = new DataTable();
    ArrayList<ColumnDescription> cd = new ArrayList<ColumnDescription>();
    cd.add(new ColumnDescription("name", ValueType.TEXT, "Animal name"));
    cd.add(new ColumnDescription("link", ValueType.TEXT, "Link to wikipedia"));
    cd.add(new ColumnDescription("population", ValueType.NUMBER, "Population size"));
    cd.add(new ColumnDescription("vegeterian", ValueType.BOOLEAN, "Vegeterian?"));

    data.addColumns(cd);

    // Fill the data-table. addRow() needs to be implemented as taking unknown
    // number of arguments for this to work.
    data.addRowFromValues("Aye-aye", "http://en.wikipedia.org/wiki/Aye-aye", 100, true);
    data.addRowFromValues("Sloth", "http://en.wikipedia.org/wiki/Sloth", 300, true);
    data.addRowFromValues("Leopard", "http://en.wikipedia.org/wiki/Leopard", 50, false);
    data.addRowFromValues("Tiger", "http://en.wikipedia.org/wiki/Tiger", 80, false);

    return data;
  }
View Full Code Here

  /**
   * Test applyQuery method.
   */
  public void testApplyQuery() throws InvalidQueryException, DataSourceException,
          TypeMismatchException {
    DataTable data = createData();

    // Test select.
    DataTable result = DataSourceHelper.applyQuery(DataSourceHelper.parseQuery("select population"),
        data, ULocale.US);
    assertEquals(1, result.getNumberOfColumns());
    assertEquals(4, result.getNumberOfRows());
    assertEquals(new NumberValue(300), result.getRow(1).getCell(0).getValue());

    data = createData();

    // Test where.
    result = DataSourceHelper.applyQuery(DataSourceHelper.parseQuery(
        "select name,vegeterian where population > 100"), data, ULocale.US);
    assertEquals(2, result.getNumberOfColumns());
    assertEquals(1, result.getNumberOfRows());
    assertEquals(new TextValue("Sloth"), result.getRow(0).getCell(0).getValue());
    assertEquals(BooleanValue.TRUE, result.getRow(0).getCell(1).getValue());

    data = createData();

    // Test group by.
    result = DataSourceHelper.applyQuery(DataSourceHelper.parseQuery(
        "select vegeterian,sum(population) group by vegeterian"), data, ULocale.US);
    assertEquals(2, result.getNumberOfColumns());
    assertEquals(2, result.getNumberOfRows());
    assertEquals(BooleanValue.FALSE, result.getRow(0).getCell(0).getValue());
    assertEquals(new NumberValue(130), result.getRow(0).getCell(1).getValue());

    data = createData();

    // Test pivot.
    result = DataSourceHelper.applyQuery(DataSourceHelper.parseQuery(
        "select sum(population) pivot vegeterian"), data, ULocale.US);
    assertEquals(2, result.getNumberOfColumns());
    assertEquals(1, result.getNumberOfRows());
    assertEquals("false", result.getColumnDescription(0).getLabel());
    assertEquals(new NumberValue(130), result.getRow(0).getCell(0).getValue());

    data = createData();

    // Test order by.
    result = DataSourceHelper.applyQuery(DataSourceHelper.parseQuery(
        "select name order by population"), data, ULocale.US);
    assertEquals(1, result.getNumberOfColumns());
    assertEquals(4, result.getNumberOfRows());
    assertEquals(new TextValue("Leopard"), result.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("Tiger"), result.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("Aye-aye"), result.getRow(2).getCell(0).getValue());
    assertEquals(new TextValue("Sloth"), result.getRow(3).getCell(0).getValue());

    data = createData();

    // Test limit and offset.
    result = DataSourceHelper.applyQuery(DataSourceHelper.parseQuery("limit 1 offset 1"), data,
        ULocale.US);
    assertEquals(4, result.getNumberOfColumns());
    assertEquals(1, result.getNumberOfRows());
    assertEquals(new TextValue("Sloth"), result.getRow(0).getCell(0).getValue());

    data = createData();

    // Test label and format.
    result = DataSourceHelper.applyQuery(DataSourceHelper.parseQuery(
        "label population 'Population size (thousands)' format population \"'$'#'k'\""), data,
        ULocale.US);
    assertEquals(4, result.getNumberOfColumns());
    assertEquals(4, result.getNumberOfRows(), 4);
    assertEquals("Population size (thousands)",
        result.getColumnDescription("population").getLabel());
    int populationIndex = result.getColumnIndex("population");
    assertEquals("$100k", result.getRow(0).getCell(populationIndex).getFormattedValue());

    // Test that validation can fail
    try {
      DataSourceHelper.parseQuery("select min(min(a))");
      fail();
View Full Code Here

TOP

Related Classes of com.google.visualization.datasource.datatable.DataTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.