<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="Exception.jsp"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpmcore.BPMSessionImpl"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="com.fujitsu.iflow.server.dataobjects.FilterEnum"
%><%@page import="com.fujitsu.iflow.server.dataobjects.ProcessInstanceStatesEnum"
%><%@page import="com.fujitsu.iflowqa.testframe.TestDriver"
%><%@page import="com.fujitsu.iflowqa.testframe.TestRecorder"
%><%@page import="com.fujitsu.iflowqa.testframe.TestRecorderText"
%><%@page import="java.io.File"
%><%@page import="java.io.Writer"
%><%@page import="java.text.SimpleDateFormat"
%><%@page import="java.util.Date"
%><%@page import="java.util.Enumeration"
%><%@page import="java.util.Hashtable"
%><%

    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
    if (bps == null) {
        %><jsp:include page="PasswordPanel.jsp" flush="true"/><%
        return;
    }

    String testDir = request.getParameter("testDir");
    if (testDir == null) {
        throw new Exception("The parameters 'testDir' must be set for the page RunTestResult.jsp");
    }
    testDir = testDir.replace('\\','/');
    File testDirFile = new File(testDir);
    if (!testDirFile.exists()) {
        throw new Exception("The directory '"+testDir+"' does not exist!  Please check your configuration");
    }
    session.setAttribute("testDir", testDir);

    String className = request.getParameter("className");
    if (className == null) {
        throw new Exception("The parameters 'className' must be set for the page RunTestResult.jsp");
    }
    session.setAttribute("className", className);
    int numParams = 0;
    String param0 = request.getParameter("param0");
    String param1 = request.getParameter("param1");
    String param2 = request.getParameter("param2");
    String[] args = null;

    if (param0 != null && param0.length()>0) {
        numParams = 1;
        if (param1 != null && param1.length()>0) {
            numParams = 2;
            if (param2 != null && param2.length()>0) {
                numParams = 3;
                args = new String[4];
                args[3] = param2;
            }
            else {
                args = new String[3];
            }
            args[2] = param1;
        }
        else {
            args = new String[2];
        }
        args[1] = param0;
    }
    else {
        args = new String[1];
    }
    args[0] = className;

    if (TestRecorderText.records==null) {
        TestRecorderText.records = new Hashtable();
    }

    String[] bcolor = {"evenrow","oddrow"};
    int nextColor = 0;
    String rowColor = bcolor[nextColor];

%>
<html>
<head>
<title>Run Test Results</title>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="javascript" src="styles/clockscripts.js"></script>
</head>

<body class="bodyClass">


<jsp:include page="Header.jsp" flush="true"/><br>

<h1>Running Tests <%=className%></h1>
<table><tr>
<td><a href="RunTest.jsp">Return to RunTest</a></td>
<td><form action="ProcessInstance.jsp" method="get">
        <input type="submit" value="View Process Id:">
        <input type="text" name="piId" value="">
    </form>
</tr></table>
<hr>
<pre>

<%
    TestRecorderText tr = new TestRecorderText(out, true, args, testDir);
    try {
        TestDriver.DriveTests(tr, args);
        out.flush();
    }
    catch (Exception e) {
        out.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
        out.write("Fatal Error, in "+className+"\n");
        TestDriver.deparenthesize(out, e.toString());
        java.io.PrintWriter pw = new java.io.PrintWriter(out);
        e.printStackTrace(pw);
        out.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
    }

    out.write("\nSummary: "+tr.passedCount());
    out.write(" passed, "+tr.failedCount());
    out.write(" failed, "+tr.fatalCount());
    out.write(" fatal errors in ");
    out.write(className);
    if (args.length > 1) {
        out.write(" ");
        out.write(args[1]);
    }
    out.write("\n");
    out.flush();

    //since this test recorded was created above, there are no "previous"
    //values to pass in,  just pass 0 and 0.
    tr.recordResults(param0, 0, 0);

    if (tr.fatalCount() > 0) {
        out.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
        out.write("Printing configuration since there was a fatal test\n");
        Enumeration enum1 = tr.getProps().propertyNames();
        while (enum1.hasMoreElements()) {
            String aName = (String) enum1.nextElement();
            String val = tr.getProps().getProperty(aName);
            out.write(aName+"="+val+"\n");
        }
        out.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");

    }
    out.flush();
%>
</pre>
<hr>

</body>
</html>

