use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.
the class KiePMMLRegressionTableFactoryTest method setStaticGetter.
@Test
public void setStaticGetter() throws IOException {
regressionTable = getRegressionTable(3.5, "professional");
RegressionModel regressionModel = new RegressionModel();
regressionModel.setNormalizationMethod(RegressionModel.NormalizationMethod.CAUCHIT);
regressionModel.addRegressionTables(regressionTable);
regressionModel.setModelName(getGeneratedClassName("RegressionModel"));
String targetField = "targetField";
DataField dataField = new DataField();
dataField.setName(FieldName.create(targetField));
dataField.setOpType(OpType.CATEGORICAL);
DataDictionary dataDictionary = new DataDictionary();
dataDictionary.addDataFields(dataField);
MiningField miningField = new MiningField();
miningField.setUsageType(MiningField.UsageType.TARGET);
miningField.setName(dataField.getName());
MiningSchema miningSchema = new MiningSchema();
miningSchema.addMiningFields(miningField);
regressionModel.setMiningSchema(miningSchema);
PMML pmml = new PMML();
pmml.setDataDictionary(dataDictionary);
pmml.addModels(regressionModel);
String variableName = "variableName";
final CommonCompilationDTO<RegressionModel> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, regressionModel, new HasClassLoaderMock());
final RegressionCompilationDTO compilationDTO = RegressionCompilationDTO.fromCompilationDTORegressionTablesAndNormalizationMethod(source, new ArrayList<>(), regressionModel.getNormalizationMethod());
final MethodDeclaration staticGetterMethod = STATIC_GETTER_METHOD.clone();
KiePMMLRegressionTableFactory.setStaticGetter(regressionTable, compilationDTO, staticGetterMethod, variableName);
String text = getFileContent(TEST_06_SOURCE);
MethodDeclaration expected = JavaParserUtils.parseMethod(text);
assertEquals(expected.toString(), staticGetterMethod.toString());
assertTrue(JavaParserUtils.equalsNode(expected, staticGetterMethod));
List<Class<?>> imports = Arrays.asList(AtomicReference.class, Collections.class, Arrays.class, List.class, Map.class, KiePMMLRegressionTable.class, SerializableFunction.class);
commonValidateCompilationWithImports(staticGetterMethod, imports);
}
use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.
the class KiePMMLCharacteristicsFactoryTest method getKiePMMLCharacteristicsSourcesMap.
@Test
public void getKiePMMLCharacteristicsSourcesMap() {
final CommonCompilationDTO<Scorecard> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, basicComplexPartialScorePmml, basicComplexPartialScore, new HasClassLoaderMock());
ScorecardCompilationDTO compilationDTO = ScorecardCompilationDTO.fromCompilationDTO(source);
final Map<String, String> retrieved = KiePMMLCharacteristicsFactory.getKiePMMLCharacteristicsSourcesMap(compilationDTO);
assertNotNull(retrieved);
assertEquals(1, retrieved.size());
String expected = compilationDTO.getPackageCanonicalCharacteristicsClassName();
assertTrue(retrieved.containsKey(expected));
try {
KieMemoryCompiler.compile(retrieved, Thread.currentThread().getContextClassLoader());
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.kie.pmml.compiler.commons.mocks.HasClassLoaderMock in project drools by kiegroup.
the class KiePMMLCharacteristicsFactoryTest method getKiePMMLCharacteristics.
@Test
public void getKiePMMLCharacteristics() {
final CommonCompilationDTO<Scorecard> source = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, basicComplexPartialScorePmml, basicComplexPartialScore, new HasClassLoaderMock());
final KiePMMLCharacteristics retrieved = KiePMMLCharacteristicsFactory.getKiePMMLCharacteristics(ScorecardCompilationDTO.fromCompilationDTO(source));
assertNotNull(retrieved);
}
Aggregations