KiePMMLRegressionTableRegressionFactory { static void populateUpdateResult(final ClassOrInterfaceDeclaration tableTemplate, final RegressionModel.NormalizationMethod normalizationMethod) { try { templateEvaluate = getFromFileName(KIE_PMML_UPDATE_RESULT_METHOD_TEMPLATE_JAVA); cloneEvaluate = templateEvaluate.clone(); ClassOrInterfaceDeclaration evaluateTemplateClass = cloneEvaluate.getClassByName(KIE_PMML_UPDATE_RESULT_METHOD_TEMPLATE) .orElseThrow(() -> new RuntimeException(MAIN_CLASS_NOT_FOUND)); String methodName = String.format("update%sResult", normalizationMethod.name()); MethodDeclaration methodDeclaration = evaluateTemplateClass.getMethodsByName(methodName).get(0); final BlockStmt body = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration.getName()))); MethodDeclaration targetMethod = tableTemplate.getMethodsByName("updateResult").get(0); targetMethod.setBody(body); } catch (Exception e) { throw new KiePMMLInternalException("Failed to populate UpdateResult", e); } } private  KiePMMLRegressionTableRegressionFactory(); static LinkedHashMap<String, KiePMMLTableSourceCategory> getRegressionTables(final List<RegressionTable> regressionTables,
                                                                                        final RegressionModel.NormalizationMethod normalizationMethod,
                                                                                        final List<KiePMMLOutputField> outputFields,
                                                                                        final String targetField,
                                                                                        final String packageName); static Map.Entry<String, String> getRegressionTable(final RegressionTable regressionTable,
                                                               final RegressionModel.NormalizationMethod normalizationMethod,
                                                               final List<KiePMMLOutputField> outputFields,
                                                               final String targetField,
                                                               final String packageName); static final String KIE_PMML_REGRESSION_TABLE_REGRESSION_TEMPLATE_JAVA; static final String KIE_PMML_REGRESSION_TABLE_REGRESSION_TEMPLATE; }
@Test public void populateUpdateResultSupported() { SUPPORTED_NORMALIZATION_METHODS.forEach(normalizationMethod -> { KiePMMLRegressionTableRegressionFactory.populateUpdateResult(modelTemplate, normalizationMethod); MethodDeclaration methodDeclaration = modelTemplate.getMethodsByName("updateResult").get(0); BlockStmt body = methodDeclaration.getBody().get(); assertNotNull(body.getStatements()); if (normalizationMethod.equals(RegressionModel.NormalizationMethod.NONE)) { assertTrue(body.getStatements().isEmpty()); } else { assertFalse(body.getStatements().isEmpty()); } }); }
@Test public void populateUpdateResultUnsupported() { UNSUPPORTED_NORMALIZATION_METHODS.forEach(normalizationMethod -> { try { KiePMMLRegressionTableRegressionFactory.populateUpdateResult(modelTemplate, normalizationMethod); fail("Expecting KiePMMLInternalException with normalizationMethod " + normalizationMethod); } catch (Exception e) { assertTrue(e instanceof KiePMMLInternalException); } }); }