Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #10 from vinodkiran/master

External API clean-up;removal of sys-outs; addition of loggers and other changes
  • Loading branch information...
commit 96d5bcdd61ae86c5693083f3ebb62054bad094f4 2 parents d5c1da9 + dda16a1
@sotty sotty authored
Showing with 119 additions and 160 deletions.
  1. +0 −24 drools-scorecards/src/main/java/org/drools/scorecards/EventDataCollector.java
  2. +77 −54 drools-scorecards/src/main/java/org/drools/scorecards/ScorecardCompiler.java
  3. +1 −5 drools-scorecards/src/main/java/org/drools/scorecards/parser/AbstractScorecardParser.java
  4. +1 −1  drools-scorecards/src/main/java/org/drools/scorecards/parser/xls/ExcelScorecardValidator.java
  5. +1 −1  drools-scorecards/src/main/java/org/drools/scorecards/parser/xls/MergedCellRange.java
  6. +1 −4 drools-scorecards/src/main/java/org/drools/scorecards/parser/xls/XLSEventDataCollector.java
  7. +1 −6 drools-scorecards/src/main/java/org/drools/scorecards/parser/xls/XLSKeywords.java
  8. +2 −4 drools-scorecards/src/main/java/org/drools/scorecards/parser/xls/XLSScorecardParser.java
  9. +0 −2  drools-scorecards/src/main/java/org/drools/scorecards/pmml/PMMLExtensionNames.java
  10. +2 −1  drools-scorecards/src/test/java/org/drools/scorecards/DrlFromPMMLTest.java
  11. +8 −18 drools-scorecards/src/test/java/org/drools/scorecards/ExternalObjectModelTest.java
  12. +6 −16 drools-scorecards/src/test/java/org/drools/scorecards/PMMLDocumentTest.java
  13. +5 −3 drools-scorecards/src/test/java/org/drools/scorecards/ScorecardParseErrorsTest.java
  14. +14 −21 drools-scorecards/src/test/java/org/drools/scorecards/ScorecardReasonCodeTest.java
  15. BIN  drools-scorecards/src/test/resources/scoremodel_externalmodel.xls
View
24 drools-scorecards/src/main/java/org/drools/scorecards/EventDataCollector.java
@@ -1,24 +0,0 @@
-/*
- * Copyright 2012 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.scorecards;
-
-import org.dmg.pmml_4_1.Scorecard;
-
-public interface EventDataCollector {
-
- public Scorecard getScorecard();
-}
View
131 drools-scorecards/src/main/java/org/drools/scorecards/ScorecardCompiler.java
@@ -16,89 +16,113 @@
package org.drools.scorecards;
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.InputStream;
+import java.io.StringWriter;
import java.util.List;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
import org.dmg.pmml_4_1.PMML;
import org.drools.scorecards.drl.DeclaredTypesDRLEmitter;
import org.drools.scorecards.drl.ExternalModelDRLEmitter;
import org.drools.scorecards.parser.AbstractScorecardParser;
import org.drools.scorecards.parser.ScorecardParseException;
-import org.drools.scorecards.parser.xls.XLSEventDataCollector;
import org.drools.scorecards.parser.xls.XLSScorecardParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ScorecardCompiler {
private PMML pmmlDocument = null;
public static final String DEFAULT_SHEET_NAME = "scorecards";
- private EventDataCollector eventDataCollector;
private List<ScorecardError> scorecardErrors;
+ private DrlType drlType;
+ private final static Logger logger = LoggerFactory.getLogger(ScorecardCompiler.class);
- public ScorecardCompiler() {
-
- }
-
- public boolean compileFromExcel(final String classPathResource) {
- return compile(classPathResource, ScorecardFormat.XLS, DEFAULT_SHEET_NAME);
+ public ScorecardCompiler(DrlType drlType) {
+ this.drlType = drlType;
}
- public boolean compileFromExcel(final String classPathResource, final String worksheetName) {
- return compile(classPathResource, ScorecardFormat.XLS, worksheetName);
+ public ScorecardCompiler() {
+ this(DrlType.INTERNAL_DECLARED_TYPES);
}
- public boolean compileFromExcel(final InputStream stream) {
- return compile(stream, ScorecardFormat.XLS, DEFAULT_SHEET_NAME);
+ /* method for use from Guvnor */
+ protected void setPMMLDocument(PMML pmmlDocument){
+ this.pmmlDocument = pmmlDocument;
}
- public boolean compileFromExcel(final InputStream stream, final String worksheetName) {
- return compile(stream, ScorecardFormat.XLS, worksheetName);
+ public boolean compileFromExcel(final String pathToFile) {
+ return compileFromExcel(pathToFile, DEFAULT_SHEET_NAME);
}
- public boolean compile(final String classPathResource, ScorecardFormat format) {
- return compile(classPathResource, format, DEFAULT_SHEET_NAME);
- }
-
- public boolean compile(final InputStream stream, ScorecardFormat format) {
- return compile(stream, format, DEFAULT_SHEET_NAME);
+ public boolean compileFromExcel(final String pathToFile, final String worksheetName) {
+ FileInputStream inputStream = null;
+ BufferedInputStream bufferedInputStream = null;
+ try {
+ inputStream = new FileInputStream(pathToFile);
+ bufferedInputStream = new BufferedInputStream(inputStream);
+ return compileFromExcel(bufferedInputStream, worksheetName);
+ } catch (FileNotFoundException e) {
+ logger.error(e.getMessage(), e);
+ } finally {
+ closeStream(bufferedInputStream);
+ closeStream(inputStream);
+ }
+ return false;
}
- public boolean compile(final String classPathResource, ScorecardFormat format, final String worksheetName) {
- InputStream is = getClass().getResourceAsStream(classPathResource);
- return compile(is, format, worksheetName);
+ public boolean compileFromExcel(final InputStream stream) {
+ return compileFromExcel(stream, DEFAULT_SHEET_NAME);
}
- public EventDataCollector getEventDataCollector() {
- return eventDataCollector;
+ public boolean compileFromExcel(final InputStream stream, final String worksheetName) {
+ try {
+ AbstractScorecardParser parser = new XLSScorecardParser();
+ scorecardErrors = parser.parseFile(stream, worksheetName);
+ if ( scorecardErrors.isEmpty() ) {
+ pmmlDocument = parser.getPMMLDocument();
+ return true;
+ }
+ } catch (ScorecardParseException e) {
+ logger.error(e.getMessage(), e);
+ } finally {
+ closeStream(stream);
+ }
+ return false;
}
public PMML getPMMLDocument() {
return pmmlDocument;
}
- public boolean compile(final InputStream stream, ScorecardFormat format, final String worksheetName) {
- if (format == ScorecardFormat.XLS) {
- AbstractScorecardParser parser = new XLSScorecardParser();
- try {
- this.eventDataCollector = new XLSEventDataCollector();
- scorecardErrors = parser.parseFile(eventDataCollector, stream, worksheetName);
- if ( scorecardErrors.isEmpty() ) {
- pmmlDocument = parser.getPMMLDocument();
- return true;
- }
- } catch (ScorecardParseException e) {
- e.printStackTrace();
- } finally {
- closeStream(stream);
- }
+ public String getPMML(){
+ if (pmmlDocument == null ) {
+ return null;
}
- return false;
+ // create a JAXBContext for the PMML class
+ JAXBContext ctx = null;
+ try {
+ ctx = JAXBContext.newInstance(PMML.class);
+ Marshaller marshaller = ctx.createMarshaller();
+ // the property JAXB_FORMATTED_OUTPUT specifies whether or not the
+ // marshalled XML data is formatted with linefeeds and indentation
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ // marshal the data in the Java content tree
+ StringWriter stringWriter = new StringWriter();
+ marshaller.marshal(pmmlDocument, stringWriter);
+ return stringWriter.toString();
+ } catch (JAXBException e) {
+ logger.error(e.getMessage(), e);
+ }
+ return null;
}
public String getDRL(){
- return getDRL(DrlType.INTERNAL_DECLARED_TYPES);
- }
-
- public String getDRL(DrlType drlType){
if (pmmlDocument != null) {
if (drlType == DrlType.INTERNAL_DECLARED_TYPES) {
return new DeclaredTypesDRLEmitter().emitDRL(pmmlDocument);
@@ -106,18 +130,17 @@ public String getDRL(DrlType drlType){
return new ExternalModelDRLEmitter().emitDRL(pmmlDocument);
}
}
- return null;
+ return null;
}
- public static String convertToDRL(PMML pmml, DrlType drlType){
+ /* convienence method for use from Guvnor*/
+ public static String convertToDRL(PMML pmml, DrlType drlType) {
if (pmml != null) {
- if (drlType == DrlType.INTERNAL_DECLARED_TYPES) {
- return new DeclaredTypesDRLEmitter().emitDRL(pmml);
- } else if (drlType == DrlType.EXTERNAL_OBJECT_MODEL) {
- return new ExternalModelDRLEmitter().emitDRL(pmml);
- }
+ ScorecardCompiler scorecardCompiler = new ScorecardCompiler(drlType);
+ scorecardCompiler.setPMMLDocument(pmml);
+ return scorecardCompiler.getDRL();
}
- return null;
+ return null;
}
public List<ScorecardError> getScorecardParseErrors() {
@@ -130,7 +153,7 @@ private void closeStream(final InputStream stream) {
stream.close();
}
} catch (final Exception e) {
- System.err.print("WARNING: Wasn't able to " + "correctly close stream for scorecard. " + e.getMessage());
+ logger.error(e.getMessage(), e);
}
}
View
6 drools-scorecards/src/main/java/org/drools/scorecards/parser/AbstractScorecardParser.java
@@ -20,15 +20,11 @@
import java.util.List;
import org.dmg.pmml_4_1.PMML;
-import org.drools.scorecards.EventDataCollector;
import org.drools.scorecards.ScorecardError;
public abstract class AbstractScorecardParser {
- /**
- * Parse an input stream, store the resulting rulebase.
- */
- public abstract List<ScorecardError> parseFile(EventDataCollector eventDataCollector, InputStream inStream, String worksheetName) throws ScorecardParseException;
+ public abstract List<ScorecardError> parseFile(InputStream inStream, String worksheetName) throws ScorecardParseException;
public abstract PMML getPMMLDocument();
}
View
2  drools-scorecards/src/main/java/org/drools/scorecards/parser/xls/ExcelScorecardValidator.java
@@ -28,7 +28,7 @@
import org.drools.scorecards.pmml.PMMLExtensionNames;
import org.drools.scorecards.pmml.ScorecardPMMLUtils;
-public class ExcelScorecardValidator {
+class ExcelScorecardValidator {
private Scorecard scorecard;
private List<ScorecardError> parseErrors;
View
2  drools-scorecards/src/main/java/org/drools/scorecards/parser/xls/MergedCellRange.java
@@ -16,7 +16,7 @@
package org.drools.scorecards.parser.xls;
-public class MergedCellRange {
+class MergedCellRange {
private int firstRow;
private int firstCol;
View
5 drools-scorecards/src/main/java/org/drools/scorecards/parser/xls/XLSEventDataCollector.java
@@ -33,17 +33,15 @@
import org.dmg.pmml_4_1.Output;
import org.dmg.pmml_4_1.Scorecard;
import org.drools.core.util.StringUtils;
-import org.drools.scorecards.EventDataCollector;
import org.drools.scorecards.ScorecardError;
import org.drools.scorecards.parser.ScorecardParseException;
import org.drools.scorecards.pmml.PMMLExtensionNames;
import org.drools.scorecards.pmml.ScorecardPMMLUtils;
-public class XLSEventDataCollector implements EventDataCollector {
+class XLSEventDataCollector {
private List<DataExpectation> expectations = new ArrayList<DataExpectation>();
private List<MergedCellRange> cellRangeList;
- //private String worksheetName;
private Scorecard scorecard;
private Characteristics characteristics;
private Characteristic _characteristic; //stateMachine variables
@@ -270,7 +268,6 @@ private void addExpectation(int row, int column, String property, Object ref, St
public void newCell(int currentRowCtr, int currentColCtr, String stringCellValue) throws ScorecardParseException {
setAdditionalExpectation(currentRowCtr, currentColCtr, stringCellValue);
- //System.out.println(currentRowCtr+", "+currentColCtr+" : "+stringCellValue);
fulfillExpectation(currentRowCtr, currentColCtr, stringCellValue, String.class);
}
View
7 drools-scorecards/src/main/java/org/drools/scorecards/parser/xls/XLSKeywords.java
@@ -16,12 +16,9 @@
package org.drools.scorecards.parser.xls;
-public class XLSKeywords {
+public interface XLSKeywords {
public static final String SCORECARD_NAME = "Scorecard Name";
- //public static final String SCORECARD_TYPE = "Scorecard Type";
- //public static final String SCORECARD_OBJECT = "Object";
- //public static final String SCORECARD_BOUND_VARIABLE = "Bound Variable";
public static final String SCORECARD_RESULTANT_SCORE_CLASS = "Resultant Score Class";
public static final String SCORECARD_RESULTANT_SCORE_FIELD = "Resultant Score Field";
public static final String SCORECARD_CHARACTERISTIC_EXTERNAL_CLASS = "Full Class Name";
@@ -36,8 +33,6 @@
public static final String SCORECARD_CHARACTERISTIC_NAME = "Name";
public static final String SCORECARD_CHARACTERISTIC_DATATYPE = "Data Type";
public static final String SCORECARD_CHARACTERISTIC_BASELINE_SCORE = "Baseline Score";
- //public static final String SCORECARD_GROUP_REASONCODE = "Reason Code";
- //public static final String SCORECARD_CHARACTERISTIC_WEIGHT = "Weight";
public static final String SCORECARD_CHARACTERISTIC_BIN_ATTRIBUTE = "Characteristic";
public static final String SCORECARD_CHARACTERISTIC_BIN_OPERATOR = "Operator";
View
6 drools-scorecards/src/main/java/org/drools/scorecards/parser/xls/XLSScorecardParser.java
@@ -29,7 +29,6 @@
import org.apache.poi.ss.util.CellRangeAddress;
import org.dmg.pmml_4_1.PMML;
import org.dmg.pmml_4_1.Scorecard;
-import org.drools.scorecards.EventDataCollector;
import org.drools.scorecards.ScorecardError;
import org.drools.scorecards.parser.AbstractScorecardParser;
import org.drools.scorecards.parser.ScorecardParseException;
@@ -44,9 +43,9 @@
private HSSFSheet currentWorksheet;
@Override
- public List<ScorecardError> parseFile(EventDataCollector eventDataCollector, InputStream inStream, String worksheetName) throws ScorecardParseException {
+ public List<ScorecardError> parseFile(InputStream inStream, String worksheetName) throws ScorecardParseException {
try {
- excelDataCollector = (XLSEventDataCollector) eventDataCollector;
+ excelDataCollector = new XLSEventDataCollector();
excelDataCollector.setParser(this);
HSSFWorkbook workbook = new HSSFWorkbook(inStream);
HSSFSheet worksheet = workbook.getSheet(worksheetName);
@@ -93,7 +92,6 @@ private void processSheet(HSSFSheet worksheet) throws ScorecardParseException {
}
break;
case Cell.CELL_TYPE_BOOLEAN:
- //System.out.println(currentColCtr+" "+currentRowCtr+" "+Boolean.valueOf(cell.getBooleanCellValue()).toString());
excelDataCollector.newCell(currentRowCtr, currentColCtr, Boolean.valueOf(cell.getBooleanCellValue()).toString());
break;
case Cell.CELL_TYPE_FORMULA:
View
2  drools-scorecards/src/main/java/org/drools/scorecards/pmml/PMMLExtensionNames.java
@@ -23,8 +23,6 @@
public static final String SCORECARD_CELL_REF = "cellRef";
public static final String SCORECARD_RESULTANT_SCORE_FIELD = "final";
public static final String SCORECARD_RESULTANT_SCORE_CLASS = "externalClass";
-
- //public static final String SCORECARD_BOUND_VAR_NAME = "boundVariableName";
public static final String SCORECARD_IMPORTS = "importsFromDelimitedString";
public static final String CHARACTERTISTIC_EXTERNAL_CLASS = "externalClass";
View
3  drools-scorecards/src/test/java/org/drools/scorecards/DrlFromPMMLTest.java
@@ -14,6 +14,7 @@
import org.junit.Test;
import static junit.framework.Assert.*;
+import static org.drools.scorecards.ScorecardCompiler.DrlType.INTERNAL_DECLARED_TYPES;
public class DrlFromPMMLTest {
@@ -21,7 +22,7 @@
@Before
public void setUp() throws Exception {
- ScorecardCompiler scorecardCompiler = new ScorecardCompiler();
+ ScorecardCompiler scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
if (scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_c.xls")) ) {
PMML pmmlDocument = scorecardCompiler.getPMMLDocument();
assertNotNull(pmmlDocument);
View
26 drools-scorecards/src/test/java/org/drools/scorecards/ExternalObjectModelTest.java
@@ -1,9 +1,6 @@
package org.drools.scorecards;
-import java.io.StringWriter;
import java.util.List;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Marshaller;
import org.dmg.pmml_4_1.Extension;
import org.dmg.pmml_4_1.Output;
@@ -25,18 +22,19 @@
import org.junit.Test;
import static junit.framework.Assert.*;
+import static org.drools.scorecards.ScorecardCompiler.DrlType.*;
public class ExternalObjectModelTest {
private static String drl;
private PMML pmmlDocument;
-
+ private static ScorecardCompiler scorecardCompiler;
@Before
public void setUp() throws Exception {
- ScorecardCompiler scorecardCompiler = new ScorecardCompiler();
+ scorecardCompiler = new ScorecardCompiler(EXTERNAL_OBJECT_MODEL);
if (scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_externalmodel.xls")) ) {
pmmlDocument = scorecardCompiler.getPMMLDocument();
assertNotNull(pmmlDocument);
- drl = scorecardCompiler.getDRL(ScorecardCompiler.DrlType.EXTERNAL_OBJECT_MODEL);
+ drl = scorecardCompiler.getDRL();
//System.out.println(drl);
} else {
fail("failed to parse scoremodel Excel.");
@@ -50,17 +48,9 @@ public void testPMMLNotNull() throws Exception {
@Test
public void testPMMLToString() throws Exception {
- // create a JAXBContext for the PMML class
- JAXBContext ctx = JAXBContext.newInstance(PMML.class);
- Marshaller marshaller = ctx.createMarshaller();
- // the property JAXB_FORMATTED_OUTPUT specifies whether or not the
- // marshalled XML data is formatted with linefeeds and indentation
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- // marshal the data in the Java content tree
- StringWriter stringWriter = new StringWriter();
- marshaller.marshal(pmmlDocument, stringWriter);
- assertTrue(stringWriter.toString().length() > 0);
- System.out.println(stringWriter.toString());
+ String pmml = scorecardCompiler.getPMML();
+ assertNotNull(pmml);
+ assertTrue(pmml.length() > 0);
}
@Test
@@ -94,7 +84,7 @@ public void testPMMLCustomOutput() throws Exception {
public void testDrlNoNull() throws Exception {
assertNotNull(drl);
assertTrue(drl.length() > 0);
- System.out.println(drl);
+ //System.out.println(drl);
}
@Test
View
22 drools-scorecards/src/test/java/org/drools/scorecards/PMMLDocumentTest.java
@@ -1,9 +1,5 @@
package org.drools.scorecards;
-import java.io.StringWriter;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Marshaller;
-
import junit.framework.Assert;
import org.dmg.pmml_4_1.Attribute;
import org.dmg.pmml_4_1.Characteristics;
@@ -19,14 +15,16 @@
import org.junit.Test;
import static junit.framework.Assert.*;
+import static org.drools.scorecards.ScorecardCompiler.DrlType.*;
public class PMMLDocumentTest {
private static PMML pmmlDocument;
+ private static ScorecardCompiler scorecardCompiler;
@Before
public void setUp() throws Exception {
- ScorecardCompiler scorecardCompiler = new ScorecardCompiler();
+ scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_c.xls"));
pmmlDocument = scorecardCompiler.getPMMLDocument();
}
@@ -34,17 +32,9 @@ public void setUp() throws Exception {
@Test
public void testPMMLDocument() throws Exception {
Assert.assertNotNull(pmmlDocument);
- // create a JAXBContext for the PMML class
- JAXBContext ctx = JAXBContext.newInstance(PMML.class);
- Marshaller marshaller = ctx.createMarshaller();
- // the property JAXB_FORMATTED_OUTPUT specifies whether or not the
- // marshalled XML data is formatted with linefeeds and indentation
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- // marshal the data in the Java content tree
- StringWriter stringWriter = new StringWriter();
- marshaller.marshal(pmmlDocument, stringWriter);
- assertTrue(stringWriter.toString().length() > 0);
- //System.out.println(stringWriter.toString());
+ String pmml = scorecardCompiler.getPMML();
+ Assert.assertNotNull(pmml);
+ Assert.assertTrue(pmml.length() > 0);
}
@Test
View
8 drools-scorecards/src/test/java/org/drools/scorecards/ScorecardParseErrorsTest.java
@@ -3,11 +3,13 @@
import junit.framework.Assert;
import org.junit.Test;
+import static org.drools.scorecards.ScorecardCompiler.DrlType.INTERNAL_DECLARED_TYPES;
+
public class ScorecardParseErrorsTest {
@Test
public void testErrorCount() throws Exception {
- ScorecardCompiler scorecardCompiler = new ScorecardCompiler();
+ ScorecardCompiler scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
boolean compileResult = scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_errors.xls"));
Assert.assertFalse(compileResult);
Assert.assertEquals(4, scorecardCompiler.getScorecardParseErrors().size());
@@ -36,7 +38,7 @@ public void testWrongData() throws Exception {
@Test
public void testMissingDataType() throws Exception {
- ScorecardCompiler scorecardCompiler = new ScorecardCompiler();
+ ScorecardCompiler scorecardCompiler = new ScorecardCompiler(ScorecardCompiler.DrlType.INTERNAL_DECLARED_TYPES);
boolean compileResult = scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_errors.xls"), "missingDataType");
// for(ScorecardError error : scorecardCompiler.getScorecardParseErrors()){
// System.out.println("testMissingDataType :"+error.getErrorLocation()+"->"+error.getErrorMessage());
@@ -49,7 +51,7 @@ public void testMissingDataType() throws Exception {
@Test
public void testMissingAttributes() throws Exception {
- ScorecardCompiler scorecardCompiler = new ScorecardCompiler();
+ ScorecardCompiler scorecardCompiler = new ScorecardCompiler(ScorecardCompiler.DrlType.INTERNAL_DECLARED_TYPES);
boolean compileResult = scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_errors.xls"), "incomplete_noAttr");
Assert.assertFalse(compileResult);
// Assert.assertEquals(2, scorecardCompiler.getScorecardParseErrors().size());
View
35 drools-scorecards/src/test/java/org/drools/scorecards/ScorecardReasonCodeTest.java
@@ -1,9 +1,5 @@
package org.drools.scorecards;
-import java.io.StringWriter;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Marshaller;
-
import junit.framework.Assert;
import org.dmg.pmml_4_1.Attribute;
import org.dmg.pmml_4_1.Characteristic;
@@ -23,44 +19,41 @@
import org.junit.Test;
import static junit.framework.Assert.*;
+import static org.drools.scorecards.ScorecardCompiler.DrlType.*;
public class ScorecardReasonCodeTest {
private static PMML pmmlDocument;
private static String drl;
-
+ private static ScorecardCompiler scorecardCompiler;
@Before
public void setUp() throws Exception {
- ScorecardCompiler scorecardCompiler = new ScorecardCompiler();
+ scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
boolean compileResult = scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_reasoncodes.xls"));
if (!compileResult) {
for(ScorecardError error : scorecardCompiler.getScorecardParseErrors()){
System.out.println("setup :"+error.getErrorLocation()+"->"+error.getErrorMessage());
}
}
- pmmlDocument = scorecardCompiler.getPMMLDocument();
drl = scorecardCompiler.getDRL();
+ Assert.assertNotNull(drl);
+ assertTrue(drl.length() > 0);
//System.out.println(drl);
}
@Test
public void testPMMLDocument() throws Exception {
+ pmmlDocument = scorecardCompiler.getPMMLDocument();
Assert.assertNotNull(pmmlDocument);
- // create a JAXBContext for the PMML class
- JAXBContext ctx = JAXBContext.newInstance(PMML.class);
- Marshaller marshaller = ctx.createMarshaller();
- // the property JAXB_FORMATTED_OUTPUT specifies whether or not the
- // marshalled XML data is formatted with linefeeds and indentation
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- // marshal the data in the Java content tree
- StringWriter stringWriter = new StringWriter();
- marshaller.marshal(pmmlDocument, stringWriter);
- assertTrue(stringWriter.toString().length() > 0);
- //System.out.println(stringWriter.toString());
+
+ String pmml = scorecardCompiler.getPMML();
+ Assert.assertNotNull(pmml);
+ assertTrue(pmml.length() > 0);
+ //System.out.println(pmml);
}
@Test
public void testAbsenceOfReasonCodes() throws Exception {
- ScorecardCompiler scorecardCompiler = new ScorecardCompiler();
+ ScorecardCompiler scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_c.xls"));
PMML pmml = scorecardCompiler.getPMMLDocument();
for (Object serializable : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels()){
@@ -134,7 +127,7 @@ public void testMissingReasonCodes() throws Exception {
@Test
public void testMissingBaselineScores() throws Exception {
- ScorecardCompiler scorecardCompiler = new ScorecardCompiler();
+ ScorecardCompiler scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_reasoncodes.xls"), "scorecards_reason_error");
assertEquals(3, scorecardCompiler.getScorecardParseErrors().size());
assertEquals("$D$30", scorecardCompiler.getScorecardParseErrors().get(2).getErrorLocation());
@@ -142,7 +135,7 @@ public void testMissingBaselineScores() throws Exception {
@Test
public void testReasonCodesCombinations() throws Exception {
- ScorecardCompiler scorecardCompiler = new ScorecardCompiler();
+ ScorecardCompiler scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_reasoncodes.xls"), "scorecards_char_reasoncode");
assertEquals(0, scorecardCompiler.getScorecardParseErrors().size());
String drl = scorecardCompiler.getDRL();
View
BIN  drools-scorecards/src/test/resources/scoremodel_externalmodel.xls
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.