Created
December 14, 2011 20:35
-
-
Save anonymous/1478384 to your computer and use it in GitHub Desktop.
AppFuse's Tapestry 5 BasePageTestCase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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