Search in sources :

Example 1 with ReportRunner

use of nl.nn.testtool.run.ReportRunner in project iaf by ibissource.

the class ReportNameComparator method doPipe.

@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
    XmlBuilder results = new XmlBuilder("Results");
    int reportsPassed = 0;
    List<Report> reports = new ArrayList<Report>();
    try {
        List<Integer> storageIds = testStorage.getStorageIds();
        for (Integer storageId : storageIds) {
            Report report = testStorage.getReport(storageId);
            String fullReportPath = (report.getPath() != null ? report.getPath() : "") + report.getName();
            if (excludeRegexPattern == null || !excludeRegexPattern.matcher(fullReportPath).matches()) {
                reports.add(report);
            }
        }
    } catch (StorageException e) {
        addExceptionElement(results, e);
    }
    ReportRunner reportRunner = new ReportRunner();
    reportRunner.setTestTool(testTool);
    reportRunner.setDebugStorage(debugStorage);
    reportRunner.setSecurityContext(new IbisSecurityContext(session, checkRoles));
    Collections.sort(reports, reportNameComparator);
    long startTime = System.currentTimeMillis();
    boolean reportGeneratorEnabledOldValue = testTool.isReportGeneratorEnabled();
    if (enableReportGenerator) {
        testTool.setReportGeneratorEnabled(true);
        testTool.sendReportGeneratorStatusUpdate();
    }
    reportRunner.run(reports, false, true);
    if (enableReportGenerator) {
        testTool.setReportGeneratorEnabled(reportGeneratorEnabledOldValue);
        testTool.sendReportGeneratorStatusUpdate();
    }
    long endTime = System.currentTimeMillis();
    for (Report report : reports) {
        RunResult runResult = reportRunner.getResults().get(report.getStorageId());
        long originalDuration = report.getEndTime() - report.getStartTime();
        long duration = -1;
        boolean equal = false;
        String error = "";
        if (runResult.errorMessage != null) {
            error = runResult.errorMessage;
        } else {
            Report runResultReport = null;
            try {
                runResultReport = reportRunner.getRunResultReport(runResult.correlationId);
            } catch (StorageException e) {
                addExceptionElement(results, e);
            }
            if (runResultReport == null) {
                error = "Result report not found. Report generator not enabled?";
            } else {
                duration = runResultReport.getEndTime() - runResultReport.getStartTime();
                report.setGlobalReportXmlTransformer(reportXmlTransformer);
                runResultReport.setGlobalReportXmlTransformer(reportXmlTransformer);
                runResultReport.setTransformation(report.getTransformation());
                runResultReport.setReportXmlTransformer(report.getReportXmlTransformer());
                if (report.toXml(reportRunner).equals(runResultReport.toXml(reportRunner))) {
                    equal = true;
                    reportsPassed++;
                }
            }
        }
        XmlBuilder result = new XmlBuilder("Result");
        results.addSubElement(result);
        result.addSubElement("Path", report.getPath());
        result.addSubElement("Name", report.getName());
        result.addSubElement("OriginalDuration", "" + originalDuration);
        if (duration > -1)
            result.addSubElement("Duration", "" + duration);
        result.addSubElement("Equal", "" + equal);
        if (!error.isEmpty())
            result.addSubElement("Error", error);
        if (writeToLog || writeToSystemOut) {
            writeToLogOrSysOut("Path=\"" + report.getPath() + "\", " + "Name=\"" + report.getName() + "\", " + "OriginalDuration=\"" + originalDuration + "\", " + ((duration > -1) ? "Duration=\"" + duration + "\", " : "") + "Equal=\"" + equal + "\"" + (!error.isEmpty() ? ", Error=\"" + error + "\"" : ""));
        }
    }
    boolean allReportsPassed = reportsPassed == reports.size();
    if (writeToLog || writeToSystemOut) {
        writeToLogOrSysOut("Total=\"" + reports.size() + "\", " + "Passed=\"" + reportsPassed + "\", " + "Failed=\"" + (reports.size() - reportsPassed) + "\", " + "TotalDuration=\"" + (endTime - startTime) + "\", " + "Equal=\"" + allReportsPassed + "\"");
    }
    PipeForward forward = allReportsPassed ? getSuccessForward() : failureForward;
    return new PipeRunResult(forward, results.toXML());
}
Also used : Report(nl.nn.testtool.Report) ArrayList(java.util.ArrayList) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) StorageException(nl.nn.testtool.storage.StorageException) ReportRunner(nl.nn.testtool.run.ReportRunner) RunResult(nl.nn.testtool.run.RunResult) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult)

Aggregations

ArrayList (java.util.ArrayList)1 PipeForward (nl.nn.adapterframework.core.PipeForward)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)1 Report (nl.nn.testtool.Report)1 ReportRunner (nl.nn.testtool.run.ReportRunner)1 RunResult (nl.nn.testtool.run.RunResult)1 StorageException (nl.nn.testtool.storage.StorageException)1