@Test
 public void testDeserializeJsonQuery() {
   String json =
       "{\"class\":\"org.pentaho.metadata.model.thin.Query\",\"conditions\":[{\"class\":\"org.pentaho.metadata.model.thin.Condition\","
           + "\"combinationType\":\"AND\",\"elementId\":\"MY_ELEM_ID\",\"operator\":\"EQUAL\",\"parameterized\":false,"
           + "\"parentId\":\"MY_PARENT_ID\",\"selectedAggregation\":\"SUM\",\"value\":[\"Val_0\"]}],\"defaultParameterMap\":null,"
           + "\"disableDistinct\":false,\"elements\":[{\"availableAggregations\":null,\"capabilities\":{},"
           + "\"class\":\"org.pentaho.metadata.model.thin.Element\",\"dataType\":null,\"defaultAggregation\":\"NONE\","
           + "\"description\":null,\"elementType\":null,\"formatMask\":null,\"hiddenForUser\":false,\"horizontalAlignment\":\"LEFT\","
           + "\"id\":\"MY_ELEM_ID\",\"isQueryElement\":true,\"name\":null,\"parentId\":\"PARENT_ID\",\"selectedAggregation\":\"SUM\"}],"
           + "\"orders\":[{\"class\":\"org.pentaho.metadata.model.thin.Order\",\"elementId\":\"MY_ELEM_ID\",\"orderType\":\"ASC\","
           + "\"parentId\":\"MY_PARENT_ID\"}],\"parameters\":[],\"sourceId\":\"MY_DOMAIN_ID\"}";
   Query result = spyMetadataServiceUtil.deserializeJsonQuery(json);
   assertNotNull(result);
   assertEquals("MY_DOMAIN_ID", result.getSourceId());
   assertFalse(result.getDisableDistinct());
   assertEquals(1, result.getElements().length);
   Element column = result.getElements()[0];
   assertEquals("MY_ELEM_ID", column.getId());
   assertNull(column.getName());
   assertNull(column.getDescription());
   assertNull(column.getElementType());
   assertNull(column.getFormatMask());
   assertNull(column.getDataType());
   assertFalse(column.isHiddenForUser());
   assertEquals("NONE", column.getDefaultAggregation());
   assertEquals("PARENT_ID", column.getParentId());
   assertEquals("LEFT", column.getHorizontalAlignment());
   assertEquals("SUM", column.getSelectedAggregation());
   assertEquals(1, result.getConditions().length);
   Condition condition = result.getConditions()[0];
   assertEquals("MY_PARENT_ID", condition.getParentId());
   assertEquals("MY_ELEM_ID", condition.getElementId());
   assertEquals("AND", condition.getCombinationType());
   assertEquals("EQUAL", condition.getOperator());
   assertFalse(condition.isParameterized());
   assertEquals("SUM", condition.getSelectedAggregation());
   Assert.assertArrayEquals(new String[] {"Val_0"}, condition.getValue());
   assertEquals(1, result.getOrders().length);
   Order order = result.getOrders()[0];
   assertEquals("MY_ELEM_ID", order.getElementId());
   assertEquals("MY_PARENT_ID", order.getParentId());
   assertEquals("ASC", order.getOrderType());
   assertEquals(0, result.getParameters().length);
 }
  public DataTable executeQuery(Query query, int rowLimit) {

    // find out which stats are being requested
    Element qColumns[] = query.getElements();
    List<org.pentaho.metadata.datatable.Column> tableColumnList =
        new ArrayList<org.pentaho.metadata.datatable.Column>();
    for (Element qColumn : qColumns) {
      org.pentaho.metadata.datatable.Column col = createDataTableColumn(qColumn);
      if (col != null) {
        tableColumnList.add(col);
      }
    }

    Cell cells[] = new Cell[tableColumnList.size()];

    int idx = 0;
    for (Element element : qColumns) {
      if ("element1".equals(element.getId())) {
        cells[idx] = new Cell(null, "text value 1");
      } else if ("element2".equals(element.getId())) {
        cells[idx] = new Cell(new BigDecimal(99), null);
      }

      idx++;
    }

    Row row = new Row(cells);
    List<Row> rowList = new ArrayList<Row>();
    rowList.add(row);

    org.pentaho.metadata.datatable.Column tableColumns[] =
        tableColumnList.toArray(new org.pentaho.metadata.datatable.Column[tableColumnList.size()]);
    Row rows[] = rowList.toArray(new Row[rowList.size()]);
    DataTable dataTable = new DataTable();
    dataTable.setCols(tableColumns);
    dataTable.setRows(rows);
    return dataTable;
  }