use of org.apache.sling.junit.Renderer in project sling by apache.
the class JUnitHealthCheck method execute.
public Result execute() {
final String extension = "json";
final FormattingResultLog resultLog = new FormattingResultLog();
final CustomRunListener listener = new CustomRunListener(resultLog);
final Renderer r = new CustomRenderer(listener, extension, resultLog);
final Collection<String> testNames = testsManager.getTestNames(testSelector);
if (testNames.isEmpty()) {
resultLog.warn("No tests found for selector {}", testSelector);
} else {
try {
testsManager.executeTests(testNames, r, testSelector);
if (listener.nTests == 0) {
resultLog.warn("No tests executed by {}", testSelector);
}
} catch (Exception e) {
resultLog.warn("Exception while executing tests (" + testSelector + ")" + e);
}
}
return new Result(resultLog);
}
use of org.apache.sling.junit.Renderer 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.Renderer 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();
}
use of org.apache.sling.junit.Renderer in project sling by apache.
the class RendererSelectorImpl method getRenderer.
public Renderer getRenderer(TestSelector selector) {
if (renderersTracker.getTrackingCount() != renderersTrackerTrackingCount) {
log.debug("Rebuilding list of {}", Renderer.class.getSimpleName());
renderersTrackerTrackingCount = renderersTracker.getTrackingCount();
final ServiceReference[] refs = renderersTracker.getServiceReferences();
renderers.clear();
if (refs != null) {
for (ServiceReference ref : refs) {
renderers.add((Renderer) bundleContext.getService(ref));
}
}
log.info("List of {} rebuilt: {}", Renderer.class.getSimpleName(), renderers);
}
for (Renderer r : renderers) {
if (r.appliesTo(selector)) {
if (r instanceof RendererFactory) {
return ((RendererFactory) r).createRenderer();
}
throw new UnsupportedOperationException("Renderers must implement RendererFactory, this one does not:" + r);
}
}
return null;
}
Aggregations