<%-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --%><%@ page import="junit.framework.Test, junit.framework.TestSuite, java.util.*, junit.framework.TestCase, java.text.SimpleDateFormat, org.apache.jackrabbit.tck.*, org.apache.jackrabbit.tck.j2ee.RepositoryServlet, java.io.ByteArrayOutputStream, javax.jcr.*, java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.ByteArrayInputStream" %><%@page session="false" %><% // get the repository session for read(config and test results) and write (config and test results) access Session repSession = RepositoryServlet.getSession(); if (repSession == null) { return; } // display mode: // - testnow : new test // - view: view results // - null: blank view String mode = request.getParameter("mode"); %> <% // draw empty test grid if (mode == null || (mode != null && mode.equals("testnow"))) { // prepare test TestFinder tf = new TestFinder(); tf.find(getServletConfig().getServletContext().getResource(RepositoryServlet.getTckWebappJarPath()).openStream(), "TestAll.java"); Iterator tests = tf.getSuites().keySet().iterator(); out.write(""); tests = tf.getSuites().keySet().iterator(); while (tests.hasNext()) { String key = (String) tests.next(); TestSuite t = (TestSuite) tf.getSuites().get(key); Enumeration members = t.tests(); out.write(""); // list tests ordered by key (level1, level2, ....) while (members.hasMoreElements()) { TestSuite aTest = (TestSuite) members.nextElement(); out.write(""); } if (tests.hasNext()) { out.write(""); } } out.write("
" + t.toString() + "
" + aTest.toString() + " "); Enumeration testMethods = aTest.tests(); while (testMethods.hasMoreElements()) { TestCase tc = (TestCase) testMethods.nextElement(); String methodname = tc.getName(); String id = methodname + "(" + aTest.getName() + ")"; out.write(" "); } out.write("
 
"); } // start testing or show results if (mode != null && mode.equals("testnow")) { // exclude list Map tckExcludeList = Collections.EMPTY_MAP; String excludelist = request.getParameter("useExcludeList"); boolean useExcludeList = (excludelist != null && excludelist.equals("no")) ? false : true; if (useExcludeList) { // check if exclude list is up to date or even existing if (repSession.getRootNode().hasNode("excludeList")) { Node excludeListNode = repSession.getRootNode().getNode("excludeList"); String list = excludeListNode.getProperty("list").getString(); if (list != null && !"".equals(list)) { String splittedList[] = list.split(","); tckExcludeList = new HashMap(); for (int i = 0; i < splittedList.length; i++) { String name = splittedList[i]; tckExcludeList.put(name, name); } } } } // start testing Node rootNode = repSession.getRootNode(); Node testResNode = (rootNode.hasNode("testing")) ? rootNode.getNode("testing") : rootNode.addNode("testing", "nt:unstructured"); rootNode.save(); out.write(""); TestFinder testfinder = new TestFinder(); testfinder.find(getServletConfig().getServletContext().getResource(RepositoryServlet.getTckWebappJarPath()).openStream(), "TestAll.java"); TckTestRunner runner = new TckTestRunner(out); String logStr = ""; runner.setLogString(logStr); String interAStr = ""; runner.setInteractionString(interAStr); runner.setNewTestString(""); Tester t = new Tester(testfinder, runner, out, tckExcludeList); t.setfinishedSuiteString(""); long startMillies = System.currentTimeMillis(); t.run(); // saving test results out.write(""); out.write(""); Node results = testResNode.addNode(String.valueOf(startMillies)); testResNode.save(); t.storeResults(results); // test summary out.write(""); out.write(""); Map summary = buildSummary(results, repSession); out.write(""); out.write(""); Iterator itr = summary.keySet().iterator(); out.write(""); String width = String.valueOf(Math.round(100 / summary.size())); while (itr.hasNext()) { out.write(""); } out.write(""); itr = summary.keySet().iterator(); out.write(""); while (itr.hasNext()) { String key = (String) itr.next(); Boolean passed = (Boolean) summary.get(key); String res = (passed.booleanValue()) ? "pass" : "failure"; out.write(""); } out.write(""); out.write("
Test Summary
" + itr.next() + "
" + "
"); out.write(""); out.write(""); out.write(""); out.write(""); } else if (mode != null && mode.equals("view")) { out.write(""); // the test to be viewed is defined by the timestamp String testTimeInMs = request.getParameter("test"); // load "test root" Node testroot = repSession.getRootNode().getNode("testing/" + testTimeInMs); // build summary Map summary = buildSummary(testroot, repSession); // Iterate through all tests TestFinder tf = new TestFinder(); tf.find(getServletConfig().getServletContext().getResource(RepositoryServlet.getTckWebappJarPath()).openStream(), "TestAll.java"); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(Long.parseLong(testTimeInMs)); SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"); String formatedTestTime = formatter.format(cal.getTime()); // test header out.write(""); out.write(""); out.write("
Test: " + formatedTestTime + "
"); // test summary out.write(""); out.write(""); Iterator itr = summary.keySet().iterator(); out.write(""); String width = String.valueOf(Math.round(100 / summary.size())); while (itr.hasNext()) { out.write(""); } out.write(""); itr = summary.keySet().iterator(); out.write(""); while (itr.hasNext()) { String key = (String) itr.next(); Boolean passed = (Boolean) summary.get(key); String res = (passed.booleanValue()) ? "pass" : "failure"; out.write(""); } out.write(""); out.write("
Test Summary
" + itr.next() + "
" + "
"); // all tests in detail out.write(""); out.write(""); out.write(""); // display the test result categorized by the test suites: // - level1 // - level2 // - ..... Iterator tests = tf.getSuites().keySet().iterator(); while (tests.hasNext()) { String key = (String) tests.next(); TestSuite t = (TestSuite) tf.getSuites().get(key); Enumeration members = t.tests(); out.write(""); while (members.hasMoreElements()) { TestSuite aTest = (TestSuite) members.nextElement(); out.write(""); } if (tests.hasNext()) { out.write(""); } } out.write("
 
Detailed Test Report
" + t.toString() + "
" + aTest.toString() + " "); Enumeration testMethods = aTest.tests(); while (testMethods.hasMoreElements()) { TestCase tc = (TestCase) testMethods.nextElement(); String methodname = tc.getName(); // test identifier String keyname = methodname + "(" + aTest.getName() + ")"; // load node containig the test result for one test Node testResultNode; if (testroot.hasNode(key + "/" + keyname)) { testResultNode = testroot.getNode(key + "/" + keyname); } else { continue; } int status = new Long(testResultNode.getProperty("status").getLong()).intValue(); String color; switch (status) { case TestResult.SUCCESS: color = "pass"; break; case TestResult.ERROR: case TestResult.FAILURE: color = "failure"; break; case TestResult.NOT_EXECUTABLE: color = "error"; break; default: color = "clear"; } String testTime = (testResultNode.hasProperty("testtime")) ? String.valueOf(testResultNode.getProperty("testtime").getLong()) : "0"; String errorMsg = (testResultNode.hasProperty("errrormsg")) ? "Error: " + testResultNode.getProperty("errrormsg").getString() : ""; errorMsg = errorMsg.replaceAll("'"," "); errorMsg = errorMsg.replaceAll("\""," "); errorMsg = errorMsg.replaceAll("\n"," "); errorMsg = errorMsg.replaceAll("\r"," "); String testInfo = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" + "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
" + "Test name: " + methodname + "(" + aTest.getName() + ")
" + "Time: " + testTime + "ms
" + errorMsg + "
"; out.write(" "); } out.write("
 
"); out.write(""); out.write(""); } %> <%! public Map buildSummary(Node startNode, Session session) throws RepositoryException, IOException, ParserConfigurationException, SAXException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); session.exportSystemView(startNode.getPath(), baos, false, false); TestResultParser parser = new TestResultParser(); Map summary = parser.interpretResult(baos.toString()); return summary; } %>