// return;
// }
final ProcessingContextFactory pcf = (ProcessingContextFactory) SpringContextSingleton.
getInstance().getContext().getBean(ProcessingContextFactory.class.getName());
ProcessingContext ctx = null;
try {
// should send response wrapper !
ctx = pcf.getContext(httpServletRequest, httpServletResponse, servletContext);
} catch (JahiaException e) {
logger.error("Error while trying to build ProcessingContext", e);
return;
}
try {
ctx.setOperationMode(ParamBean.EDIT);
// ctx.setEntryLoadRequest(new EntryLoadRequest(EntryLoadRequest.STAGING_WORKFLOW_STATE, 0, ctx.getLocales()));
JahiaUser admin = JahiaAdminUser.getAdminUser(0);
JCRSessionFactory.getInstance().setCurrentUser(admin);
ctx.setTheUser(admin);
} catch (JahiaException e) {
logger.error("Error getting user", e);
}
try {
String pathInfo = StringUtils.substringAfter(httpServletRequest.getPathInfo(), "/test");
if (StringUtils.isNotEmpty(pathInfo)) {
final Set<String> ignoreTests = getIgnoreTests();
// Execute one test
String className = pathInfo.substring(pathInfo.lastIndexOf('/')+1);
try {
JUnitCore junitcore = new JUnitCore();
SurefireJUnitXMLResultFormatter xmlResultFormatter = new SurefireJUnitXMLResultFormatter(httpServletResponse.getOutputStream());
junitcore.addListener(xmlResultFormatter);
Class testClass = Class.forName(className);
List<Class> classes = getTestClasses(testClass, new ArrayList<Class>());
if (classes.isEmpty()) {
Description description = Description.createSuiteDescription(testClass);
xmlResultFormatter.testRunStarted(description);
xmlResultFormatter.testRunFinished(new Result());
} else {
junitcore.run(new FilterRequest(Request.classes(classes
.toArray(new Class[classes.size()])), new Filter() {
@Override
public boolean shouldRun(Description description) {
return !ignoreTests.contains(description.getDisplayName());
}
@Override
public String describe() {
return "Filter out Jahia configured methods";
}
}));
}
} catch (Exception e) {
logger.error("Error executing test", e);
}
} else {
WebApplicationContext webApplicationContext = (WebApplicationContext) servletContext.getAttribute(WebApplicationContext.class.getName() + ".jahiaModules");
Map<String,TestBean> testBeans = webApplicationContext.getBeansOfType(TestBean.class);
PrintWriter pw = httpServletResponse.getWriter();
// Return the lists of available tests
List<String> tests = new LinkedList<String>();
SortedSet<TestBean> s = new TreeSet<TestBean>(testBeans.values());
for (TestBean testBean : s) {
for (String o : testBean.getTestCases()) {
tests.add(o);
}
}
for (String c : tests) {
pw.println(c);
}
}
} finally {
try {
ctx.setUserGuest();
} catch (JahiaException e) {
logger.error(e.getMessage(), e);
}
}