public static <T extends Model> CompilationUnit getKiePMMLModelCompilationUnit(final DroolsCompilationDTO<T> droolsCompilationDTO,
                                                                                   final String javaTemplate,
                                                                                   final String modelClassName) {
        logger.trace("getKiePMMLModelCompilationUnit {} {} {}", droolsCompilationDTO.getFields(),
                     droolsCompilationDTO.getModel(), droolsCompilationDTO.getPackageName());
        String className = droolsCompilationDTO.getSimpleClassName();
        CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className,
                                                                                 droolsCompilationDTO.getPackageName(),
                                                                                 javaTemplate,
                                                                                 modelClassName);
        ClassOrInterfaceDeclaration modelTemplate = cloneCU.getClassByName(className)
                .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className));
        MINING_FUNCTION miningFunction = droolsCompilationDTO.getMINING_FUNCTION();
        final ConstructorDeclaration constructorDeclaration =
                modelTemplate.getDefaultConstructor().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, modelTemplate.getName())));
        String targetField = droolsCompilationDTO.getTargetFieldName();
        setConstructor(droolsCompilationDTO.getModel(), constructorDeclaration, modelTemplate.getName(), targetField,
                       miningFunction,
                       droolsCompilationDTO.getPackageName());
        addFieldTypeMapPopulation(constructorDeclaration.getBody(), droolsCompilationDTO.getFieldTypeMap());
         return cloneCU;
    }
@Test
    void getKiePMMLModelCompilationUnit() {
        DataDictionary dataDictionary = new DataDictionary();
        String targetFieldString = "target.field";
         String targetFieldName =targetFieldString;
        dataDictionary.addDataFields(new DataField(targetFieldName, OpType.CONTINUOUS, DataType.DOUBLE));
        String modelName = "ModelName";
        TreeModel model = new TreeModel();
        model.setModelName(modelName);
        model.setMiningFunction(MiningFunction.CLASSIFICATION);
        MiningField targetMiningField = new MiningField(targetFieldName);
        targetMiningField.setUsageType(MiningField.UsageType.TARGET);
        MiningSchema miningSchema = new MiningSchema();
        miningSchema.addMiningFields(targetMiningField);
        model.setMiningSchema(miningSchema);
        Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
        fieldTypeMap.put(targetFieldString, new KiePMMLOriginalTypeGeneratedType(targetFieldString,
                getSanitizedClassName(targetFieldString)));
        String packageName = "net.test";
        PMML pmml = new PMML();
        pmml.setDataDictionary(dataDictionary);
        pmml.addModels(model);
        final CommonCompilationDTO<TreeModel> source =
                CommonCompilationDTO.fromGeneratedPackageNameAndFields(packageName,
                                                                       pmml,
                                                                       model,
                                                                       new PMMLCompilationContextMock(),
                                                                       "FILENAME");
        final DroolsCompilationDTO<TreeModel> droolsCompilationDTO =
                DroolsCompilationDTO.fromCompilationDTO(source, fieldTypeMap);
        CompilationUnit retrieved =
                KiePMMLDroolsModelFactoryUtils.getKiePMMLModelCompilationUnit(droolsCompilationDTO, TEMPLATE_SOURCE,
                        TEMPLATE_CLASS_NAME);
        assertThat(retrieved.getPackageDeclaration().get().getNameAsString()).isEqualTo(droolsCompilationDTO.getPackageName());
        ConstructorDeclaration constructorDeclaration =
                retrieved.getClassByName(modelName).get().getDefaultConstructor().get();
        MINING_FUNCTION miningFunction = MINING_FUNCTION.CLASSIFICATION;
        PMML_MODEL pmmlModel = PMML_MODEL.byName(model.getClass().getSimpleName());
        Map<String, Expression> assignExpressionMap = new HashMap<>();
        assignExpressionMap.put("targetField", new StringLiteralExpr(targetFieldString));
        assignExpressionMap.put("miningFunction",
                new NameExpr(miningFunction.getClass().getName() + "." + miningFunction.name()));
        assignExpressionMap.put("pmmlMODEL", new NameExpr(pmmlModel.getClass().getName() + "." + pmmlModel.name()));
        String expectedKModulePackageName = getSanitizedPackageName(packageName + "." + modelName);
        assignExpressionMap.put("kModulePackageName", new StringLiteralExpr(expectedKModulePackageName));
        assertThat(commonEvaluateAssignExpr(constructorDeclaration.getBody(), assignExpressionMap)).isTrue();
        int expectedMethodCallExprs = assignExpressionMap.size() + fieldTypeMap.size() + 1; // The last "1" is for
        // the super invocation
        commonEvaluateFieldTypeMap(constructorDeclaration.getBody(), fieldTypeMap, expectedMethodCallExprs);
    }