use of org.apache.sling.junit.TestSelector in project sling by apache.
the class ServletProcessor method doPost.
/** POST request executes tests */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final TestSelector selector = getTestSelector(request);
final boolean forceReload = getForceReloadOption(request);
log.info("POST request, executing tests: {}, {}={}", new Object[] { selector, FORCE_RELOAD_PARAM, forceReload });
final Renderer renderer = rendererSelector.getRenderer(selector);
if (renderer == null) {
throw new ServletException("No Renderer found for " + selector);
}
renderer.setup(response, getClass().getSimpleName());
final List<String> testNames = getTestNames(selector, forceReload);
if (testNames.isEmpty()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "No tests found for " + selector);
}
try {
testsManager.executeTests(testNames, renderer, selector);
} catch (Exception e) {
throw new ServletException(e);
}
renderer.cleanup();
}
use of org.apache.sling.junit.TestSelector in project sling by apache.
the class ServletProcessor method doGet.
/** GET request lists available tests */
public void doGet(final HttpServletRequest request, final HttpServletResponse response, final String servletPath) throws ServletException, IOException {
final boolean forceReload = getForceReloadOption(request);
// Redirect to / if called without it, and serve CSS if requested
{
final String pi = request.getPathInfo();
if (pi == null) {
response.sendRedirect(request.getContextPath() + servletPath + "/");
} else if (pi.endsWith(CSS)) {
sendCss(response);
return;
}
}
final TestSelector selector = getTestSelector(request);
final List<String> testNames = getTestNames(selector, forceReload);
// 404 if no tests found
if (testNames.isEmpty()) {
final String msg = "WARNING: no test classes found for selector " + selector + ", check the requirements of the active " + "TestsProvider services for how to supply tests.";
response.sendError(HttpServletResponse.SC_NOT_FOUND, msg);
return;
}
final Renderer renderer = rendererSelector.getRenderer(selector);
if (renderer == null) {
throw new ServletException("No Renderer found for " + selector);
}
log.debug("GET request: {}", selector);
renderer.setup(response, getClass().getSimpleName());
renderer.info("info", "Test selector: " + selector);
try {
testsManager.listTests(testNames, renderer);
final String postPath = getTestExecutionPath(request, selector, renderer.getExtension());
renderer.link("Execute these tests", postPath, "POST");
} catch (Exception e) {
throw new ServletException(e);
}
renderer.cleanup();
}
Aggregations