<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="Exception.jsp"
%><%@page import="com.fujitsu.iflow.common.Utils"
%><%@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.BufferedReader"
%><%@page import="java.io.File"
%><%@page import="java.io.FileReader"
%><%@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"
%><%@page import="java.util.Vector"
%><%

    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 RunTestFlowPath.jsp");
    }
    testDir = testDir.replace('\\','/');
    session.setAttribute("testDir", testDir);

    String pathPart = request.getParameter("pathPart");
    String totalPath = testDir;
    if (pathPart != null) {
        totalPath = testDir + pathPart;
    }

    File testDirFile = new File(totalPath);
    if (!testDirFile.exists()) {
        throw new Exception("The directory '"+totalPath+"' does not exist!  Please check your configuration");
    }
    if (!testDirFile.isDirectory()) {
        throw new Exception("The path '"+totalPath+"' does not point to a directory!  Please check your configuration");
    }

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

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

    String testType    = request.getParameter("testType");
    String excludeFile = request.getParameter("excludeFile");


    if (excludeFile.length()>0) {
        File excludeFileFile = new File(testDir + "/" + excludeFile);
        if (!excludeFileFile.exists()) {
            throw new Exception("The exclude file '"+testDir + "/" + excludeFile+"' does not exist!  Please check your configuration");
        }
    }

%>
<html>
<head>
<title>Run Flow Path</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>Flow Path <%=pathPart%></h1>
<a href="RunTest.jsp">Return to RunTest</a><br>
<hr>

<table>
            <tr><td colspan="3"><form action="RunTestResult.jsp" method="get">
            <input type="hidden" name="testDir", value="<%=testDir%>">
            <input type="hidden" name="className", value="com.fujitsu.iflowqa.testframe.CollectedFlowPathTests">
            <input type="hidden" name="param0", value="<%=pathPart%>">
            <input type="hidden" name="param1", value="<%=testType%>">
            <input type="hidden" name="param2", value="<%=excludeFile%>">
            <input type="submit" name="go", value="Run All in Directory"><%=pathPart%><br>
            of type '<%=testType%>' excluding files specified in '<%=excludeFile%>'.</form></td>
            </tr>

            <tr><th>Test</th>
            <th>Runs &nbsp;</th>
            <th>Passes &nbsp;</th>
            <th>Fails &nbsp;</th></tr>


<%

    int lineCount = 0;
    try {
        File[] children = testDirFile.listFiles();

        for (int i=0; i<children.length; i++) {
            File child = children[i];
            String childName = child.getName();
            String subPath = pathPart+"/"+childName;

            if (child.isDirectory()) {
                %>
            <tr><td><form action="RunTestFlowPath.jsp" method="get">
            <input type="hidden" name="testDir", value="<%=testDir%>">
            <input type="hidden" name="pathPart", value="<%=subPath%>">
            <input type="hidden" name="testType", value="<%=testType%>">
            <input type="hidden" name="excludeFile", value="<%=excludeFile%>">
            <input type="submit" name="go", value="Scan"><%=subPath%></form></td>
            <td> </td>
            <td> </td>
            <td> </td>
            <td> </td></tr>
                <%
                continue;
            }

            if (childName.endsWith("xpdl")) {
                int[] stats = (int[])TestRecorderText.records.get(subPath);
                if (stats==null) {
                    stats = new int[3];
                    stats[0] = 0;
                    stats[1] = 0;
                    stats[2] = 0;
                }

                %>
            <tr><td><form action="RunTestResult.jsp" method="get">
            <input type="hidden" name="testDir", value="<%=testDir%>">
            <input type="hidden" name="className", value="com.fujitsu.iflowqa.testframe.FlowPath">
            <input type="hidden" name="param0", value="<%=subPath%>">
            <input type="submit" name="go", value="Run"><%=subPath%></form></td>
            <td><%=stats[0]%></td>
            <td><%=stats[1]%></td>
            <%
                if (stats[2]>0) {
            %>
            <td bgcolor="#FF8888">
            <%
                } else {
            %>
            <td>
            <%
                }
            %>
            <%=stats[2]%></td>
            <td><a href="../test/<%=subPath%>">view</a></td>
            </tr>
                <%
                continue;
            }
        }
    }
    catch (Exception e) {
        throw new Exception("Directory' "+pathPart+"' contains a entry that caused an exception"+e.toString());
    }

%>
</table>
<hr>
<hr>

</body>
</html>

