@Test public void testConvertQuery() { String domainName = "test_domain"; String modelId = "model_id"; String columnId = "column_id"; LogicalColumn mockColumn = mock(LogicalColumn.class); doReturn(DataType.STRING).when(mockColumn).getDataType(); doReturn(columnId).when(mockColumn).getId(); LogicalModel mockModel = mock(LogicalModel.class); doReturn(mockColumn).when(mockModel).findLogicalColumn(columnId); Domain mockDomain = mock(Domain.class); doReturn(mockModel).when(mockDomain).findLogicalModel(modelId); IMetadataDomainRepository mockRepo = mock(IMetadataDomainRepository.class); doReturn(mockDomain).when(mockRepo).getDomain(domainName); org.pentaho.metadata.model.Category category = mock(org.pentaho.metadata.model.Category.class); doReturn(category).when(spyMetadataServiceUtil).getCategory(columnId, mockModel); doReturn(mockRepo).when(spyMetadataServiceUtil).getDomainRepository(); Query srcQuery = createMockQuery(domainName, modelId, columnId); ModelInfo info = new ModelInfo(); info.setGroupId(domainName); info.setModelId(modelId); org.pentaho.metadata.query.model.Query result = spyMetadataServiceUtil.convertQuery(srcQuery, info); assertNotNull(result); assertEquals(mockDomain, result.getDomain()); assertFalse(result.getDisableDistinct()); assertEquals(mockModel, result.getLogicalModel()); assertEquals(1, result.getSelections().size()); Selection selection = result.getSelections().get(0); assertEquals(mockColumn, selection.getLogicalColumn()); assertEquals(category, selection.getCategory()); assertEquals(AggregationType.SUM, selection.getActiveAggregationType()); assertEquals(AggregationType.SUM, selection.getAggregationType()); assertEquals(1, result.getConstraints().size()); Constraint constraint = result.getConstraints().get(0); assertEquals(CombinationType.AND, constraint.getCombinationType()); assertNull(constraint.getFormula()); assertEquals(1, result.getOrders().size()); org.pentaho.metadata.query.model.Order resOrder = result.getOrders().get(0); assertEquals(selection, resOrder.getSelection()); assertEquals(Type.ASC, resOrder.getType()); assertEquals(1, result.getParameters().size()); org.pentaho.metadata.query.model.Parameter param = result.getParameters().get(0); assertEquals("parameter_name", param.getName()); assertEquals("val_0", param.getDefaultValue()); assertEquals(DataType.STRING, param.getType()); }
@Override public ModelInfo[] getModelList(String providerId, String groupId, String match) { ModelInfo modelInfo = createModelInfo(); if (providerId != null && !providerId.equals(PROVIDER_ID)) { return new ModelInfo[0]; } if (groupId != null && !groupId.equals(modelInfo.getGroupId())) { return new ModelInfo[0]; } String str = (match == null) ? null : match.toLowerCase(); if (str == null || modelInfo.getId().contains(str) || modelInfo.getName().contains(str) || modelInfo.getDescription().contains(str)) { return new ModelInfo[] {modelInfo}; } return new ModelInfo[0]; }
private ModelInfo createModelInfo() { ModelInfo info = new ModelInfo(); info.setGroupId(GROUP_ID); info.setDescription("Test model description"); info.setModelId(MODEL_ID); info.setName("Test model name"); info.setProvider(provider); return info; }
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; }