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);
}
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)));
}
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);
}
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);
}
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);
}
Aggregations