Search in sources :

Example 1 with HasKnowledgeBuilderMock

use of org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock in project drools by kiegroup.

the class ScorecardModelImplementationProviderTest method getKiePMMLModel.

@Test
public void getKiePMMLModel() throws Exception {
    final PMML pmml = getPMML(SOURCE_1);
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, (Scorecard) pmml.getModels().get(0), new HasKnowledgeBuilderMock(knowledgeBuilder));
    final KiePMMLScorecardModel retrieved = PROVIDER.getKiePMMLModel(compilationDTO);
    assertNotNull(retrieved);
    commonVerifyIsDeepCloneable(retrieved);
}
Also used : KiePMMLScorecardModel(org.kie.pmml.models.drools.scorecard.model.KiePMMLScorecardModel) HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) PMML(org.dmg.pmml.PMML) Scorecard(org.dmg.pmml.scorecard.Scorecard) Test(org.junit.Test)

Example 2 with HasKnowledgeBuilderMock

use of org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock in project drools by kiegroup.

the class DroolsModelProviderTest method generateRulesFiles.

@Test
public void generateRulesFiles() {
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, scorecard, new HasKnowledgeBuilderMock(knowledgeBuilder));
    droolsModelProvider.getKiePMMLModelWithSources(compilationDTO);
    String expectedPackageName = compilationDTO.getPackageName();
    PackageDescr packageDescr = knowledgeBuilder.getPackageDescrs(expectedPackageName).get(0);
    final List<GeneratedFile> retrieved = droolsModelProvider.generateRulesFiles(packageDescr);
    assertNotNull(retrieved);
    final String rootPath = expectedPackageName.replace('.', '/') + "/";
    packageDescr.getTypeDeclarations().forEach(typeDeclarationDescr -> {
        String expectedPath = rootPath + typeDeclarationDescr.getTypeName() + ".java";
        assertTrue(retrieved.stream().anyMatch(generatedFile -> generatedFile.getPath().equals(expectedPath)));
    });
    String pkgUUID = packageDescr.getPreferredPkgUUID().get();
    String expectedRule = rootPath + "Rules" + pkgUUID + ".java";
    assertTrue(retrieved.stream().anyMatch(generatedFile -> generatedFile.getPath().equals(expectedRule)));
    String expectedDomain = rootPath + "DomainClassesMetadata" + pkgUUID + ".java";
    assertTrue(retrieved.stream().anyMatch(generatedFile -> generatedFile.getPath().equals(expectedDomain)));
}
Also used : KiePMMLDroolsModel(org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModel) BeforeClass(org.junit.BeforeClass) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) DroolsCompilationDTO(org.kie.pmml.models.drools.dto.DroolsCompilationDTO) Scorecard(org.dmg.pmml.scorecard.Scorecard) KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) HashMap(java.util.HashMap) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) Field(org.dmg.pmml.Field) TransformationDictionary(org.dmg.pmml.TransformationDictionary) PMML_MODEL(org.kie.pmml.api.enums.PMML_MODEL) DerivedField(org.dmg.pmml.DerivedField) Map(java.util.Map) KiePMMLModelUtils.getSanitizedPackageName(org.kie.pmml.commons.utils.KiePMMLModelUtils.getSanitizedPackageName) PMML(org.dmg.pmml.PMML) PACKAGE_NAME(org.kie.pmml.commons.Constants.PACKAGE_NAME) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) DataDictionary(org.dmg.pmml.DataDictionary) Test(org.junit.Test) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) CommonTestingUtils.getFieldsFromDataDictionaryAndTransformationDictionaryAndLocalTransformations(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionaryAndTransformationDictionaryAndLocalTransformations) GeneratedFile(org.drools.modelcompiler.builder.GeneratedFile) HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) DataField(org.dmg.pmml.DataField) TestUtils(org.kie.pmml.compiler.api.testutils.TestUtils) List(java.util.List) CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) Optional(java.util.Optional) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) KiePMMLDroolsAST(org.kie.pmml.models.drools.ast.KiePMMLDroolsAST) KiePMMLDroolsModelWithSources(org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModelWithSources) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) Assert.assertEquals(org.junit.Assert.assertEquals) KiePMMLModelUtils.getSanitizedClassName(org.kie.pmml.commons.utils.KiePMMLModelUtils.getSanitizedClassName) HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) Scorecard(org.dmg.pmml.scorecard.Scorecard) PackageDescr(org.drools.drl.ast.descr.PackageDescr) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) GeneratedFile(org.drools.modelcompiler.builder.GeneratedFile) Test(org.junit.Test)

Example 3 with HasKnowledgeBuilderMock

use of org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock in project drools by kiegroup.

the class DroolsModelProviderTest method getKiePMMLModelWithKnowledgeBuilder.

@Test
public void getKiePMMLModelWithKnowledgeBuilder() {
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, scorecard, new HasKnowledgeBuilderMock(knowledgeBuilder));
    KiePMMLDroolsModel retrieved = droolsModelProvider.getKiePMMLModel(compilationDTO);
    assertNotNull(retrieved);
    assertTrue(retrieved instanceof KiePMMLDroolsModelTest);
    KiePMMLDroolsModelTest retrievedTest = (KiePMMLDroolsModelTest) retrieved;
    final List<DataField> originalDataFields = pmml.getDataDictionary().getDataFields();
    final List<DataField> retrievedDataFields = retrievedTest.dataDictionary.getDataFields();
    assertEquals(originalDataFields.size(), retrievedTest.dataDictionary.getDataFields().size());
    originalDataFields.forEach(dataField -> {
        Optional<DataField> optRet = retrievedDataFields.stream().filter(retrievedDataField -> dataField.getName().equals(retrievedDataField.getName())).findFirst();
        assertTrue(optRet.isPresent());
        assertEquals(dataField.getDataType(), optRet.get().getDataType());
    });
    assertEquals(pmml.getTransformationDictionary(), retrievedTest.transformationDictionary);
    assertEquals(scorecard, retrievedTest.model);
    String expectedPackageName = getSanitizedPackageName(PACKAGE_NAME);
    assertEquals(expectedPackageName, retrievedTest.getKModulePackageName());
    assertEquals(PACKAGE_NAME, retrievedTest.getName());
    PackageDescr packageDescr = knowledgeBuilder.getPackageDescrs("packagename").get(0);
    assertTrue(packageDescr instanceof CompositePackageDescr);
}
Also used : KiePMMLDroolsModel(org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModel) BeforeClass(org.junit.BeforeClass) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) DroolsCompilationDTO(org.kie.pmml.models.drools.dto.DroolsCompilationDTO) Scorecard(org.dmg.pmml.scorecard.Scorecard) KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) HashMap(java.util.HashMap) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) Field(org.dmg.pmml.Field) TransformationDictionary(org.dmg.pmml.TransformationDictionary) PMML_MODEL(org.kie.pmml.api.enums.PMML_MODEL) DerivedField(org.dmg.pmml.DerivedField) Map(java.util.Map) KiePMMLModelUtils.getSanitizedPackageName(org.kie.pmml.commons.utils.KiePMMLModelUtils.getSanitizedPackageName) PMML(org.dmg.pmml.PMML) PACKAGE_NAME(org.kie.pmml.commons.Constants.PACKAGE_NAME) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) DataDictionary(org.dmg.pmml.DataDictionary) Test(org.junit.Test) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) CommonTestingUtils.getFieldsFromDataDictionaryAndTransformationDictionaryAndLocalTransformations(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionaryAndTransformationDictionaryAndLocalTransformations) GeneratedFile(org.drools.modelcompiler.builder.GeneratedFile) HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) DataField(org.dmg.pmml.DataField) TestUtils(org.kie.pmml.compiler.api.testutils.TestUtils) List(java.util.List) CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) Optional(java.util.Optional) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) KiePMMLDroolsAST(org.kie.pmml.models.drools.ast.KiePMMLDroolsAST) KiePMMLDroolsModelWithSources(org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModelWithSources) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) Assert.assertEquals(org.junit.Assert.assertEquals) KiePMMLModelUtils.getSanitizedClassName(org.kie.pmml.commons.utils.KiePMMLModelUtils.getSanitizedClassName) HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) KiePMMLDroolsModel(org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModel) DataField(org.dmg.pmml.DataField) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) Scorecard(org.dmg.pmml.scorecard.Scorecard) PackageDescr(org.drools.drl.ast.descr.PackageDescr) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) Test(org.junit.Test)

Example 4 with HasKnowledgeBuilderMock

use of org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock in project drools by kiegroup.

the class DroolsModelProviderTest method getRulesSourceMap.

@Test
public void getRulesSourceMap() {
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, scorecard, new HasKnowledgeBuilderMock(knowledgeBuilder));
    droolsModelProvider.getKiePMMLModelWithSources(compilationDTO);
    String expectedPackageName = compilationDTO.getPackageName();
    PackageDescr packageDescr = knowledgeBuilder.getPackageDescrs(expectedPackageName).get(0);
    final Map<String, String> retrieved = droolsModelProvider.getRulesSourceMap(packageDescr);
    assertNotNull(retrieved);
    final String rootPath = expectedPackageName + ".";
    commonVerifyRulesSourcesMap(retrieved, packageDescr, rootPath);
}
Also used : HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) Scorecard(org.dmg.pmml.scorecard.Scorecard) PackageDescr(org.drools.drl.ast.descr.PackageDescr) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) Test(org.junit.Test)

Example 5 with HasKnowledgeBuilderMock

use of org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock in project drools by kiegroup.

the class TreeModelImplementationProviderTest method getKiePMMLModel.

@Test
public void getKiePMMLModel() throws Exception {
    final PMML pmml = getPMML(SOURCE_1);
    KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
    final CommonCompilationDTO<TreeModel> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, (TreeModel) pmml.getModels().get(0), new HasKnowledgeBuilderMock(knowledgeBuilder));
    final KiePMMLTreeModel retrieved = PROVIDER.getKiePMMLModel(compilationDTO);
    assertNotNull(retrieved);
    commonVerifyIsDeepCloneable(retrieved);
}
Also used : TreeModel(org.dmg.pmml.tree.TreeModel) KiePMMLTreeModel(org.kie.pmml.models.drools.tree.model.KiePMMLTreeModel) HasKnowledgeBuilderMock(org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock) KiePMMLTreeModel(org.kie.pmml.models.drools.tree.model.KiePMMLTreeModel) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) PMML(org.dmg.pmml.PMML) Test(org.junit.Test)

Aggregations

KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)14 Test (org.junit.Test)14 HasKnowledgeBuilderMock (org.kie.pmml.models.drools.commons.implementations.HasKnowledgeBuilderMock)14 Scorecard (org.dmg.pmml.scorecard.Scorecard)9 PMML (org.dmg.pmml.PMML)6 TreeModel (org.dmg.pmml.tree.TreeModel)5 KiePMMLDroolsModelWithSources (org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModelWithSources)5 KiePMMLTreeModel (org.kie.pmml.models.drools.tree.model.KiePMMLTreeModel)5 HashMap (java.util.HashMap)4 DataDictionary (org.dmg.pmml.DataDictionary)4 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)4 PackageDescr (org.drools.drl.ast.descr.PackageDescr)4 PMML_MODEL (org.kie.pmml.api.enums.PMML_MODEL)4 KiePMMLOriginalTypeGeneratedType (org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType)4 IOException (java.io.IOException)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 DataField (org.dmg.pmml.DataField)2