Skip to content

Instantly share code, notes, and snippets.

Created December 14, 2011 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1478384 to your computer and use it in GitHub Desktop.
Save anonymous/1478384 to your computer and use it in GitHub Desktop.
AppFuse's Tapestry 5 BasePageTestCase
@ContextConfiguration(locations = {
"classpath:/applicationContext-resources.xml", "classpath:/applicationContext-dao.xml",
"classpath:/applicationContext-service.xml", "classpath*:/applicationContext.xml",
"/WEB-INF/applicationContext*.xml"})
public abstract class BasePageTestCase extends AbstractTransactionalJUnit4SpringContextTests {
protected PageTester tester;
protected Document doc;
protected Map<String, String> fieldValues;
protected final Log log = LogFactory.getLog(getClass());
protected static final String MESSAGES = Constants.BUNDLE_KEY;
private int smtpPort = 25250;
@Before
public void onSetUp() {
String appPackage = "org.appfuse.webapp";
String appName = "app";
final MockServletContext servletContext = new MockServletContext("");
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
//servletContext.addInitParameter(SpringConstants.USE_EXTERNAL_SPRING_CONTEXT, "true");
tester = new PageTester(appPackage, appName, "src/main/webapp") {
@Override
protected ModuleDef[] provideExtraModuleDefs() {
return new ModuleDef[]{new SpringModuleDef(servletContext)};
}
};
fieldValues = new HashMap<String, String>();
smtpPort = smtpPort + (int) (Math.random() * 100);
// change the port on the mailSender so it doesn't conflict with an
// existing SMTP server on localhost
JavaMailSenderImpl mailSender = (JavaMailSenderImpl) applicationContext.getBean("mailSender");
mailSender.setPort(getSmtpPort());
mailSender.setHost("localhost");
}
@After
public void onTearDown() {
if (tester != null) {
tester.shutdown();
}
tester = null;
}
protected int getSmtpPort() {
return smtpPort;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment