Search in sources :

Example 1 with CompilationDTO

use of org.kie.pmml.compiler.api.dto.CompilationDTO in project drools by kiegroup.

the class KiePMMLModelFactoryUtilsTest method populateGetCreatedKiePMMLMiningFieldsMethod.

@Test
public void populateGetCreatedKiePMMLMiningFieldsMethod() throws IOException {
    final CompilationDTO compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmmlModel, model, new HasClassLoaderMock());
    KiePMMLModelFactoryUtils.populateGetCreatedKiePMMLMiningFieldsMethod(classOrInterfaceDeclaration, compilationDTO.getMiningSchema().getMiningFields(), compilationDTO.getFields());
    final MethodDeclaration retrieved = classOrInterfaceDeclaration.getMethodsByName(GET_CREATED_KIEPMMLMININGFIELDS).get(0);
    String text = getFileContent(TEST_12_SOURCE);
    BlockStmt expected = JavaParserUtils.parseBlock(text);
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved.getBody().get()));
}
Also used : CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) CompilationDTO(org.kie.pmml.compiler.api.dto.CompilationDTO) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 2 with CompilationDTO

use of org.kie.pmml.compiler.api.dto.CompilationDTO in project drools by kiegroup.

the class KiePMMLModelFactoryUtilsTest method populateGetCreatedMiningFieldsMethod.

@Test
public void populateGetCreatedMiningFieldsMethod() throws IOException {
    final CompilationDTO compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmmlModel, model, new HasClassLoaderMock());
    KiePMMLModelFactoryUtils.populateGetCreatedMiningFieldsMethod(classOrInterfaceDeclaration, compilationDTO.getKieMiningFields());
    final MethodDeclaration retrieved = classOrInterfaceDeclaration.getMethodsByName(GET_CREATED_MININGFIELDS).get(0);
    String text = getFileContent(TEST_14_SOURCE);
    MethodDeclaration expected = JavaParserUtils.parseMethod(text);
    assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
}
Also used : CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) CompilationDTO(org.kie.pmml.compiler.api.dto.CompilationDTO) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 3 with CompilationDTO

use of org.kie.pmml.compiler.api.dto.CompilationDTO in project drools by kiegroup.

the class KiePMMLModelFactoryUtilsTest method commonPopulateGetCreatedKiePMMLMiningFieldsMethod.

@Test
public void commonPopulateGetCreatedKiePMMLMiningFieldsMethod() throws IOException {
    final CompilationDTO compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmmlModel, model, new HasClassLoaderMock());
    final MethodDeclaration methodDeclaration = new MethodDeclaration();
    KiePMMLModelFactoryUtils.commonPopulateGetCreatedKiePMMLMiningFieldsMethod(methodDeclaration, compilationDTO.getMiningSchema().getMiningFields(), compilationDTO.getFields());
    String text = getFileContent(TEST_06_SOURCE);
    MethodDeclaration expected = JavaParserUtils.parseMethod(text);
    assertTrue(JavaParserUtils.equalsNode(expected, methodDeclaration));
}
Also used : CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) CompilationDTO(org.kie.pmml.compiler.api.dto.CompilationDTO) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 4 with CompilationDTO

use of org.kie.pmml.compiler.api.dto.CompilationDTO in project drools by kiegroup.

the class KiePMMLModelFactoryUtilsTest method initStaticGetter.

@Test
public void initStaticGetter() throws IOException {
    final CompilationDTO compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmmlModel, model, new HasClassLoaderMock());
    KiePMMLModelFactoryUtils.initStaticGetter(compilationDTO, classOrInterfaceDeclaration);
    String text = getFileContent(TEST_04_SOURCE);
    MethodDeclaration expected = JavaParserUtils.parseMethod(text);
    assertEquals(expected.toString(), staticGetterMethod.toString());
    assertTrue(JavaParserUtils.equalsNode(expected, staticGetterMethod));
}
Also used : CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) CompilationDTO(org.kie.pmml.compiler.api.dto.CompilationDTO) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Example 5 with CompilationDTO

use of org.kie.pmml.compiler.api.dto.CompilationDTO in project drools by kiegroup.

the class KiePMMLModelFactoryUtilsTest method init.

@Test
public void init() throws IOException {
    final CompilationDTO compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmmlModel, model, new HasClassLoaderMock());
    KiePMMLModelFactoryUtils.init(compilationDTO, classOrInterfaceDeclaration);
    BlockStmt body = constructorDeclaration.getBody();
    String text = getFileContent(TEST_03_SOURCE);
    Statement expected = JavaParserUtils.parseConstructorBlock(text);
    assertTrue(JavaParserUtils.equalsNode(expected, body));
}
Also used : CommonCompilationDTO(org.kie.pmml.compiler.api.dto.CommonCompilationDTO) CompilationDTO(org.kie.pmml.compiler.api.dto.CompilationDTO) Statement(com.github.javaparser.ast.stmt.Statement) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) HasClassLoaderMock(org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock) Test(org.junit.Test)

Aggregations

CompilationDTO (org.kie.pmml.compiler.api.dto.CompilationDTO)10 Test (org.junit.Test)8 CommonCompilationDTO (org.kie.pmml.compiler.api.dto.CommonCompilationDTO)8 HasClassLoaderMock (org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock)8 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)7 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)5 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)3 CompilationUnit (com.github.javaparser.ast.CompilationUnit)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)2 KiePMMLModelFactoryUtils (org.kie.pmml.compiler.commons.codegenfactories.KiePMMLModelFactoryUtils)2 JavaParserUtils (org.kie.pmml.compiler.commons.utils.JavaParserUtils)2 MAIN_CLASS_NOT_FOUND (org.kie.pmml.compiler.commons.utils.JavaParserUtils.MAIN_CLASS_NOT_FOUND)2 JavaParserUtils.getFullClassName (org.kie.pmml.compiler.commons.utils.JavaParserUtils.getFullClassName)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 NodeList (com.github.javaparser.ast.NodeList)1 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)1 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1