Search in sources :

Example 1 with KiePMMLDroolsModel

use of org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModel 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)

Aggregations

IOException (java.io.IOException)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 DataDictionary (org.dmg.pmml.DataDictionary)1 DataField (org.dmg.pmml.DataField)1 DerivedField (org.dmg.pmml.DerivedField)1 Field (org.dmg.pmml.Field)1 PMML (org.dmg.pmml.PMML)1 TransformationDictionary (org.dmg.pmml.TransformationDictionary)1 Scorecard (org.dmg.pmml.scorecard.Scorecard)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 GeneratedFile (org.drools.modelcompiler.builder.GeneratedFile)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertTrue (org.junit.Assert.assertTrue)1