use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record in project drools by kiegroup.
the class ExampleMCDCTest method test1.
@Test
public void test1() throws Exception {
final String resourceFileName = "example1.dmn";
List<DMNMessage> validate = validator.validate(getReader(resourceFileName), ANALYZE_DECISION_TABLE, COMPUTE_DECISION_TABLE_MCDC);
DTAnalysis analysis = getAnalysis(validate, "_452a0adf-dd49-47c3-b02d-fe0ad45902c7");
Collection<Record> mcdcCases = computeMCDCCases(analysis.getMCDCSelectedBlocks());
assertThat(mcdcCases, hasSize(16));
assertMCDCCases(resourceFileName, analysis.getSource(), mcdcCases);
// debugOutputAndOpenXLSX(analysis.getSource(), analysis.getMCDCSelectedBlocks());
String mcdc2tck = MCDC2TCKGenerator.mcdc2tck(analysis.getSource(), analysis.getMCDCSelectedBlocks());
// debugTCKXML(analysis.getSource(), mcdc2tck);
}
use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record in project drools by kiegroup.
the class MCDC2TCKGenerator method mcdc2tck.
public static String mcdc2tck(DecisionTable dt, List<PosNegBlock> selectedBlocks) throws JAXBException {
ObjectFactory factory = new ObjectFactory();
TestCases testCases = factory.createTestCases();
Set<Record> mcdcRecords = new LinkedHashSet<>();
int testCaseId = 1;
for (PosNegBlock b : selectedBlocks) {
boolean add = mcdcRecords.add(b.posRecord);
if (add) {
appendRecordToTestCases(dt, testCases, String.valueOf(testCaseId), b.posRecord);
testCaseId++;
}
for (Record negRecord : b.negRecords) {
add = mcdcRecords.add(negRecord);
if (add) {
appendRecordToTestCases(dt, testCases, String.valueOf(testCaseId), negRecord);
testCaseId++;
}
}
}
JAXBContext jaxbContext = JAXBContext.newInstance(TestCases.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(testCases, sw);
return sw.toString();
}
use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record in project drools by kiegroup.
the class ExampleMCDCTest method assertMCDCCases.
private void assertMCDCCases(final String resourceFileName, DecisionTable sourceDT, Collection<Record> mcdcCases) {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime(resourceFileName, ExampleMCDCTest.class);
MCDCListener mcdcListener = new MCDCListener();
runtime.addListener(mcdcListener);
DMNModel dmnModel = runtime.getModels().get(0);
assertThat(dmnModel, notNullValue());
for (Record mcdcCase : mcdcCases) {
mcdcListener.selectedRule.clear();
DMNContext context = runtime.newContext();
for (int i = 0; i < mcdcCase.enums.length; i++) {
context.set(sourceDT.getInput().get(i).getInputExpression().getText(), mcdcCase.enums[i]);
}
DMNResult evaluateAll = runtime.evaluateAll(dmnModel, context);
LOG.debug("{}", evaluateAll);
assertThat(mcdcListener.selectedRule, hasItems(mcdcCase.ruleIdx + 1));
}
}
use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record in project drools by kiegroup.
the class ExampleMCDCTest method test2.
@Test
public void test2() throws Exception {
final String resourceFileName = "example2.dmn";
List<DMNMessage> validate = validator.validate(getReader(resourceFileName), ANALYZE_DECISION_TABLE, COMPUTE_DECISION_TABLE_MCDC);
DTAnalysis analysis = getAnalysis(validate, "_e31c78b7-63ef-4112-a0bc-b0546043ebe9");
Collection<Record> mcdcCases = computeMCDCCases(analysis.getMCDCSelectedBlocks());
assertThat(mcdcCases, hasSize(14));
assertMCDCCases(resourceFileName, analysis.getSource(), mcdcCases);
// debugOutputAndOpenXLSX(analysis.getSource(), analysis.getMCDCSelectedBlocks());
String mcdc2tck = MCDC2TCKGenerator.mcdc2tck(analysis.getSource(), analysis.getMCDCSelectedBlocks());
// debugTCKXML(analysis.getSource(), mcdc2tck);
}
use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record in project drools by kiegroup.
the class ExampleMCDCTest method debugOutputAndOpenXLSX.
public static void debugOutputAndOpenXLSX(DecisionTable dt, List<PosNegBlock> selectedBlocks) {
XSSFWorkbook wb = new XSSFWorkbook();
CreationHelper ch = wb.getCreationHelper();
CellStyle styleColumn = wb.createCellStyle();
styleColumn.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
styleColumn.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Font font = wb.createFont();
font.setColor(IndexedColors.RED.getIndex());
CellStyle styleRepeated = wb.createCellStyle();
styleRepeated.setFont(font);
Sheet sheet = wb.createSheet("MC DC Analysis");
int r = 0, c = 0;
Row row = sheet.createRow(r++);
row.createCell(c++).setCellValue(ch.createRichTextString("Rule:"));
for (InputClause input : dt.getInput()) {
row.createCell(c++).setCellValue(input.getInputExpression().getText());
}
for (OutputClause output : dt.getOutput()) {
row.createCell(c++).setCellValue(dt.getOutputLabel());
}
row.createCell(c++).setCellValue(ch.createRichTextString("Rule:"));
for (InputClause input : dt.getInput()) {
row.createCell(c++).setCellValue(input.getInputExpression().getText());
}
for (OutputClause output : dt.getOutput()) {
row.createCell(c++).setCellValue(dt.getOutputLabel());
}
Set<Record> mcdcRecords = new LinkedHashSet<>();
for (PosNegBlock b : selectedBlocks) {
row = sheet.createRow(r++);
c = 0;
boolean add = mcdcRecords.add(b.posRecord);
Cell ruleIdxCell = row.createCell(c++);
ruleIdxCell.setCellValue(b.posRecord.ruleIdx + 1);
if (!add) {
ruleIdxCell.setCellStyle(styleRepeated);
}
for (int i = 0; i < b.posRecord.enums.length; i++) {
Object en = b.posRecord.enums[i];
Cell enCell = row.createCell(c++);
enCell.setCellValue(en.toString());
if (!add) {
enCell.setCellStyle(styleRepeated);
}
if (b.cMarker == i) {
enCell.setCellStyle(styleColumn);
}
}
for (Object out : b.posRecord.output) {
Cell outCell = row.createCell(c++);
outCell.setCellValue(out.toString());
if (!add) {
outCell.setCellStyle(styleRepeated);
}
}
for (int i = 0; i < b.negRecords.size(); i++) {
Record negRecord = b.negRecords.get(i);
if (i != 0) {
row = sheet.createRow(r++);
c = 0 + 1 + b.posRecord.enums.length + b.posRecord.output.size();
}
add = mcdcRecords.add(negRecord);
ruleIdxCell = row.createCell(c++);
ruleIdxCell.setCellValue(negRecord.ruleIdx + 1);
if (!add) {
ruleIdxCell.setCellStyle(styleRepeated);
}
for (Object en : negRecord.enums) {
Cell enCell = row.createCell(c++);
enCell.setCellValue(en.toString());
if (!add) {
enCell.setCellStyle(styleRepeated);
}
}
for (Object out : negRecord.output) {
Cell outCell = row.createCell(c++);
outCell.setCellValue(out.toString());
if (!add) {
outCell.setCellStyle(styleRepeated);
}
}
}
}
File file;
try {
file = Files.createTempFile("mcdc " + dt.getOutputLabel(), ".xlsx").toFile();
OutputStream fileOut = new FileOutputStream(file);
wb.write(fileOut);
wb.close();
} catch (IOException e) {
e.printStackTrace();
// terminate early;
return;
}
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().open(file);
} catch (IOException e) {
e.printStackTrace();
}
} else {
throw new UnsupportedOperationException();
}
LOG.trace(System.getProperty("java.io.tmpdir"));
}
Aggregations