Skip to content

Commit

Permalink
[DROOLS-6635] Move testing sources in specific files (apache#3868)
Browse files Browse the repository at this point in the history
* [DROOLS-6625] Managing missing "required" input data

* [DROOLS-6625] Managing best-effort conversion of input data

* [DROOLS-6625] Managing invalid values - TODO: integration tests

* [DROOLS-6625] Managing invalid values

* [DROOLS-6625] Managing missing values

* [DROOLS-6625] Validate input data

* [DROOLS-6635] Move testing sources in specific files

* [DROOLS-6625] Fix merge with base branch

* [DROOLS-6625] Fix as per PR suggestion

* [DROOLS-6635] Fix merge

* [DROOLS-6635] Fix merge with 7.x
  • Loading branch information
gitgabrio authored Oct 5, 2021
1 parent 0ee8a62 commit 1e6036b
Show file tree
Hide file tree
Showing 80 changed files with 1,089 additions and 1,490 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.kie.pmml.compiler.commons.builders;

import java.io.IOException;
import java.util.List;

import com.github.javaparser.ast.CompilationUnit;
Expand All @@ -33,17 +34,18 @@
import org.kie.pmml.compiler.commons.utils.JavaParserUtils;
import org.kie.pmml.compiler.commons.utils.KiePMMLUtil;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.kie.pmml.compiler.commons.mocks.TestingModelImplementationProvider.KIE_PMML_TEST_MODEL_TEMPLATE;
import static org.kie.pmml.compiler.commons.mocks.TestingModelImplementationProvider.KIE_PMML_TEST_MODEL_TEMPLATE_JAVA;
import static org.kie.pmml.compiler.commons.utils.JavaParserUtils.MAIN_CLASS_NOT_FOUND;
import static org.kie.pmml.compiler.commons.utils.ModelUtils.getFieldsFromDataDictionaryTransformationDictionaryAndModel;
import static org.kie.test.util.filesystem.FileUtils.getFileContent;
import static org.kie.test.util.filesystem.FileUtils.getFileInputStream;

public class KiePMMLModelCodegenUtilsTest {

private static final String MODEL_FILE = "TreeSample.pmml";
private static final String TEST_01_SOURCE = "KiePMMLModelCodegenUtilsTest_01.txt";
private static TransformationDictionary transformationDictionary;
private static Model model;
private static List<Field<?>> fields;
Expand All @@ -65,90 +67,12 @@ public static void setup() throws Exception {
}

@Test
public void init() {
public void init() throws IOException {
ConstructorDeclaration constructorDeclaration = modelTemplate.getDefaultConstructor().get();
KiePMMLModelCodegenUtils.init(modelTemplate, fields, transformationDictionary, model);
BlockStmt body = constructorDeclaration.getBody();
Statement expected = JavaParserUtils.parseConstructorBlock("{\n" +
"super(\"golfing\", Collections.emptyList" +
"());\n" +
" pmmlMODEL = org.kie.pmml.api.enums" +
".PMML_MODEL" +
".TREE_MODEL;\n" +
" transformationDictionary = this" +
".createTransformationDictionary();\n" +
" localTransformations = this" +
".createLocalTransformations();\n" +
" miningFunction = org.kie.pmml.api" +
".enums" +
".MINING_FUNCTION.CLASSIFICATION;\n" +
" targetField = \"whatIdo\";\n" +
" miningFields.add(new org.kie.pmml.api" +
".models" +
".MiningField(\"temperature\", org.kie" +
".pmml.api.enums" +
".FIELD_USAGE_TYPE.ACTIVE, null, org.kie" +
".pmml.api" +
".enums.DATA_TYPE.DOUBLE, null, org.kie" +
".pmml.api" +
".enums.INVALID_VALUE_TREATMENT_METHOD" +
".RETURN_INVALID, null, null, java.util" +
".Arrays.asList" +
"(), java.util.Arrays.asList()));\n" +
" miningFields.add(new org.kie.pmml.api" +
".models" +
".MiningField(\"humidity\", org.kie.pmml" +
".api.enums" +
".FIELD_USAGE_TYPE.ACTIVE, null, org.kie" +
".pmml.api" +
".enums.DATA_TYPE.DOUBLE, null, org.kie" +
".pmml.api" +
".enums.INVALID_VALUE_TREATMENT_METHOD" +
".RETURN_INVALID, null, null, java.util" +
".Arrays.asList" +
"(), java.util.Arrays.asList()));\n" +
" miningFields.add(new org.kie.pmml.api" +
".models" +
".MiningField(\"windy\", org.kie.pmml.api" +
".enums" +
".FIELD_USAGE_TYPE.ACTIVE, null, org.kie" +
".pmml.api" +
".enums.DATA_TYPE.STRING, null, org.kie" +
".pmml.api" +
".enums.INVALID_VALUE_TREATMENT_METHOD" +
".RETURN_INVALID, null, null, java.util" +
".Arrays.asList" +
"(\"true\", \"false\"), java.util.Arrays" +
".asList()));" +
"\n" +
" miningFields.add(new org.kie.pmml.api" +
".models" +
".MiningField(\"outlook\", org.kie.pmml" +
".api.enums" +
".FIELD_USAGE_TYPE.ACTIVE, null, org.kie" +
".pmml.api" +
".enums.DATA_TYPE.STRING, null, org.kie" +
".pmml.api" +
".enums.INVALID_VALUE_TREATMENT_METHOD" +
".RETURN_INVALID, null, null, java.util" +
".Arrays.asList" +
"(\"sunny\", \"overcast\", \"rain\"), java" +
".util" +
".Arrays.asList()));\n" +
" miningFields.add(new org.kie.pmml.api" +
".models" +
".MiningField(\"whatIdo\", org.kie.pmml" +
".api.enums" +
".FIELD_USAGE_TYPE.TARGET, null, org.kie" +
".pmml.api" +
".enums.DATA_TYPE.STRING, null, org.kie" +
".pmml.api" +
".enums.INVALID_VALUE_TREATMENT_METHOD" +
".RETURN_INVALID, null, null, java.util.Arrays.asList" +
"(\"will play\", \"may play\", \"no play\"), java" +
".util.Arrays.asList()));\n" +
"}");
assertEquals(expected.toString(), body.toString());
String text = getFileContent(TEST_01_SOURCE);
Statement expected = JavaParserUtils.parseConstructorBlock(text);
assertTrue(JavaParserUtils.equalsNode(expected, body));
}
}
Loading

0 comments on commit 1e6036b

Please sign in to comment.