private void assertElements(Category category, Element element) { assertEquals(category.getId(), element.getId()); assertEquals(category.getName(DEFAULT_LOCALE), element.getName()); assertEquals(category.getDescription(DEFAULT_LOCALE), element.getDescription()); assertFalse(element.getIsQueryElement()); assertNull(element.getParentId()); }
protected org.pentaho.metadata.datatable.Column createDataTableColumn(Element qColumn) { String id = qColumn.getId(); if ("element1".equals(id)) { return new org.pentaho.metadata.datatable.Column("element1", "Element 1", "string"); } if ("element2".equals(id)) { return new org.pentaho.metadata.datatable.Column("element2", "Element 2", "number"); } return null; }
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; }
private Query createMockQuery(String domainName, String modelId, String columnId) { Element elem = new Element(); elem.setSelectedAggregation("SUM"); elem.setId(columnId); Condition condition = mock(Condition.class); doReturn("test_condition").when(condition).getCondition("String", null); doReturn("AND").when(condition).getCombinationType(); doReturn(columnId).when(condition).getElementId(); Order order = mock(Order.class); doReturn(columnId).when(order).getElementId(); doReturn("ASC").when(order).getOrderType(); Parameter paramater = mock(Parameter.class); doReturn(new String[] {"val_0", "val_1"}).when(paramater).getValue(); doReturn("parameter_name").when(paramater).getName(); doReturn(columnId).when(paramater).getElementId(); Query srcQuery = mock(Query.class); doReturn(new Element[] {elem}).when(srcQuery).getElements(); doReturn(new Condition[] {condition}).when(srcQuery).getConditions(); doReturn(Boolean.FALSE).when(srcQuery).getDisableDistinct(); doReturn(new Order[] {order}).when(srcQuery).getOrders(); doReturn(new Parameter[] {paramater}).when(srcQuery).getParameters(); return srcQuery; }
private void assertColumns(LogicalColumn lcolumn, Element column, String categoryId) { assertEquals(lcolumn.getId(), column.getId()); assertEquals(lcolumn.getName(DEFAULT_LOCALE), column.getName()); assertEquals(lcolumn.getDescription(DEFAULT_LOCALE), column.getDescription()); assertEquals(categoryId, column.getParentId()); assertEquals(lcolumn.getDataType().getName().toUpperCase(), column.getDataType()); assertEquals(lcolumn.getFieldType().name(), column.getElementType()); Assert.assertArrayEquals( new String[] {"SUM", "COUNT", "AVERAGE"}, column.getAvailableAggregations()); assertEquals(lcolumn.getAggregationType().name(), column.getDefaultAggregation()); assertEquals(lcolumn.getAggregationType().name(), column.getSelectedAggregation()); assertEquals("LEFT", column.getHorizontalAlignment()); assertEquals("test_mask", column.getFormatMask()); Assert.assertFalse(column.isHiddenForUser()); }
@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); }
private Model createModel() { // only one model for this... ModelInfo info = createModelInfo(); Model model = new Model(); Element elements[] = new Element[3]; HashMap<String, String> elementCapabilities = new HashMap<String, String>(); elementCapabilities.put(Element.CAPABILITY_CAN_SEARCH, "false"); elementCapabilities.put(Element.CAPABILITY_CAN_SORT, "false"); Element groupElement = new Element(); groupElement.setElementType(FieldType.DIMENSION.name()); groupElement.setHorizontalAlignment(Alignment.LEFT.name()); groupElement.setId("element1"); groupElement.setName("Element 1"); groupElement.setDescription("Description 1"); groupElement.setDataType(Types.TYPE_STRING.toString()); groupElement.setCapabilities(elementCapabilities); groupElement.setIsQueryElement(false); elements[0] = groupElement; Element element1 = new Element(); element1.setElementType(FieldType.DIMENSION.name()); element1.setHorizontalAlignment(Alignment.LEFT.name()); element1.setId("element1"); element1.setName("Element 1"); element1.setDataType(Types.TYPE_STRING.toString()); element1.setCapabilities(elementCapabilities); element1.setIsQueryElement(true); elements[1] = element1; elementCapabilities.put(Element.CAPABILITY_CAN_FILTER, "false"); Element element2 = new Element(); element2.setElementType(FieldType.FACT.name()); element2.setHorizontalAlignment(Alignment.RIGHT.name()); element2.setId("element2"); element2.setName("Element 2"); element2.setDataType(Types.TYPE_NUMERIC.toString()); element2.setFormatMask("#,###.00"); element2.setCapabilities(elementCapabilities); element2.setIsQueryElement(true); element2.setAvailableAggregations(new String[] {"SUM", "MIN"}); element2.setDefaultAggregation("SUM"); element2.setHiddenForUser(false); element2.setParentId("element1"); elements[2] = element2; model.setElements(elements); model.setGroupId(info.getGroupId()); model.setDescription(info.getDescription()); model.setModelId(info.getModelId()); model.setName(info.getName()); model.setProvider(provider); HashMap<String, String> capabilities = new HashMap<String, String>(); capabilities.put("across-axis", "true"); capabilities.put("across-axis-customizable", "true"); capabilities.put("down-axis", "false"); capabilities.put("down-axis-customizable", "false"); capabilities.put("filter-axis", "false"); capabilities.put("filter-axis-customizable", "false"); capabilities.put("sortable", "false"); model.setCapabilities(capabilities); return model; }