Search in sources :

Example 1 with ObjectFactory

use of org.kie.dmn.validation.dtanalysis.mcdc.dmntck.ObjectFactory in project drools by kiegroup.

the class MCDC2TCKGenerator method appendRecordToTestCases.

private static void appendRecordToTestCases(DecisionTable dt, TestCases testCases, String withId, Record record) {
    ObjectFactory factory = new ObjectFactory();
    TestCase testCase = factory.createTestCasesTestCase().withId("mcdc_" + withId).withName("Test case " + withId);
    testCase.withDescription(record.toString());
    for (int i = 0; i < record.enums.length; i++) {
        Object en = record.enums[i];
        String inputName = dt.getInput().get(i).getInputExpression().getText();
        InputNode inputNode = factory.createTestCasesTestCaseInputNode().withName(inputName);
        testCase.withInputNode(inputNode);
        JAXBElement<Object> jaxbElement = factory.createValueTypeValue(en);
        inputNode.withValue(jaxbElement);
    }
    if (record.output.size() == 1) {
        Object out = record.output.get(0);
        String outputName = dt.getOutputLabel();
        ResultNode resultNode = factory.createTestCasesTestCaseResultNode().withName(outputName);
        testCase.withResultNode(resultNode);
        JAXBElement<Object> jaxbElement = factory.createValueTypeValue(out);
        resultNode.withExpected(factory.createValueType().withValue(jaxbElement));
    } else {
        throw new UnsupportedOperationException();
    }
    testCases.withTestCase(testCase);
}
Also used : InputNode(org.kie.dmn.validation.dtanalysis.mcdc.dmntck.TestCases.TestCase.InputNode) ObjectFactory(org.kie.dmn.validation.dtanalysis.mcdc.dmntck.ObjectFactory) TestCase(org.kie.dmn.validation.dtanalysis.mcdc.dmntck.TestCases.TestCase) ResultNode(org.kie.dmn.validation.dtanalysis.mcdc.dmntck.TestCases.TestCase.ResultNode)

Example 2 with ObjectFactory

use of org.kie.dmn.validation.dtanalysis.mcdc.dmntck.ObjectFactory 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)

Aggregations

ObjectFactory (org.kie.dmn.validation.dtanalysis.mcdc.dmntck.ObjectFactory)2 StringWriter (java.io.StringWriter)1 LinkedHashSet (java.util.LinkedHashSet)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 PosNegBlock (org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock)1 Record (org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record)1 TestCases (org.kie.dmn.validation.dtanalysis.mcdc.dmntck.TestCases)1 TestCase (org.kie.dmn.validation.dtanalysis.mcdc.dmntck.TestCases.TestCase)1 InputNode (org.kie.dmn.validation.dtanalysis.mcdc.dmntck.TestCases.TestCase.InputNode)1 ResultNode (org.kie.dmn.validation.dtanalysis.mcdc.dmntck.TestCases.TestCase.ResultNode)1