Search in sources :

Example 1 with PosNegBlock

use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock in project drools by kiegroup.

the class DMNDTAnalyser method dmnDTAnalysis.

private DTAnalysis dmnDTAnalysis(DMNModel model, DecisionTable dt, Set<Validation> flags) {
    DDTATable ddtaTable = new DDTATable();
    compileTableInputClauses(model, dt, ddtaTable);
    compileTableOutputClauses(model, dt, ddtaTable);
    compileTableRules(dt, ddtaTable);
    compileTableComputeColStringMissingEnum(model, dt, ddtaTable);
    printDebugTableInfo(ddtaTable);
    DTAnalysis analysis = new DTAnalysis(dt, ddtaTable);
    analysis.computeOutputInLOV();
    if (!dt.getHitPolicy().equals(HitPolicy.COLLECT)) {
        if (ddtaTable.getColIDsStringWithoutEnum().isEmpty()) {
            LOG.debug("findGaps");
            findGaps(analysis, ddtaTable, 0, new Interval[ddtaTable.inputCols()], Collections.emptyList());
        } else {
            LOG.debug("findGaps Skipped because getColIDsStringWithoutEnum is not empty: {}", ddtaTable.getColIDsStringWithoutEnum());
        }
        LOG.debug("findOverlaps");
        findOverlaps(analysis, ddtaTable, 0, new Interval[ddtaTable.inputCols()], Collections.emptyList());
    } else {
        LOG.debug("findGaps(), findOverlaps() are Skipped because getHitPolicy is COLLECT.");
    }
    LOG.debug("computeMaskedRules");
    analysis.computeMaskedRules();
    LOG.debug("computeMisleadingRules");
    analysis.computeMisleadingRules();
    LOG.debug("normalize");
    analysis.normalize();
    LOG.debug("computeSubsumptions");
    analysis.computeSubsumptions();
    LOG.debug("computeContractions");
    analysis.computeContractions();
    LOG.debug("compute1stNFViolations");
    analysis.compute1stNFViolations();
    LOG.debug("compute2ndNFViolations");
    analysis.compute2ndNFViolations();
    LOG.debug("computeHitPolicyRecommender");
    analysis.computeHitPolicyRecommender();
    if (flags.contains(Validation.COMPUTE_DECISION_TABLE_MCDC)) {
        LOG.debug("mcdc.");
        List<PosNegBlock> selectedBlocks = new MCDCAnalyser(ddtaTable, dt).compute();
        analysis.setMCDCSelectedBlocks(selectedBlocks);
    }
    return analysis;
}
Also used : DDTATable(org.kie.dmn.validation.dtanalysis.model.DDTATable) PosNegBlock(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock) MCDCAnalyser(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis)

Example 2 with PosNegBlock

use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock 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();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Marshaller(javax.xml.bind.Marshaller) ObjectFactory(org.kie.dmn.validation.dtanalysis.mcdc.dmntck.ObjectFactory) StringWriter(java.io.StringWriter) TestCases(org.kie.dmn.validation.dtanalysis.mcdc.dmntck.TestCases) PosNegBlock(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock) Record(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record) JAXBContext(javax.xml.bind.JAXBContext)

Example 3 with PosNegBlock

use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock 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"));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) PosNegBlock(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Font(org.apache.poi.ss.usermodel.Font) OutputClause(org.kie.dmn.model.api.OutputClause) FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Record(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) File(java.io.File) InputClause(org.kie.dmn.model.api.InputClause)

Aggregations

PosNegBlock (org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock)3 LinkedHashSet (java.util.LinkedHashSet)2 Record (org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 StringWriter (java.io.StringWriter)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 Cell (org.apache.poi.ss.usermodel.Cell)1 CellStyle (org.apache.poi.ss.usermodel.CellStyle)1 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)1 Font (org.apache.poi.ss.usermodel.Font)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1 InputClause (org.kie.dmn.model.api.InputClause)1 OutputClause (org.kie.dmn.model.api.OutputClause)1 MCDCAnalyser (org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser)1