package scenic3.tester;
import org.slim3.controller.ControllerConstants;
import org.slim3.controller.ScenicFrontController;
import org.slim3.tester.ControllerTester;
import scenic3.ScenicController;
import scenic3.ScenicPage;
public class PageTester extends ControllerTester {
public PageTester(Class<?> testClass) throws NullPointerException {
super(testClass);
super.frontController = new ScenicFrontController();
}
/**
* Sets up the servlet context.
*/
@Override
protected void setUpServletContext() {
String rootPackageName =
servletContext
.getInitParameter(ControllerConstants.ROOT_PACKAGE_KEY);
if (rootPackageName != null) {
if (rootPackageName
.endsWith(ControllerConstants.SERVER_CONTROLLER_PACKAGE)) {
servletContext.setAttribute(
ControllerConstants.CONTROLLER_PACKAGE_KEY,
ControllerConstants.SERVER_CONTROLLER_PACKAGE);
}
return;
}
String className = testClass.getName();
int pos = className.lastIndexOf(".server.page.");
if (pos < 0) {
pos = className.lastIndexOf(".page.");
if (pos < 0) {
pos = className.lastIndexOf('.');
}
} else {
servletContext.setAttribute(
ControllerConstants.CONTROLLER_PACKAGE_KEY,
"server.controller");
}
rootPackageName = className.substring(0, pos);
servletContext.setInitParameter(
ControllerConstants.ROOT_PACKAGE_KEY,
rootPackageName);
}
public ScenicPage getPage() {
return ((ScenicController) getController()).getPage();
}
public String getActionMethodName() {
return ((ScenicController) getController()).getActionMethodName();
}
}