I try to write a junit test for tapestry 5.4 page rendering:
import org.apache.tapestry5.test.PageTester;
public class LoadTest {
private final String PAGE_NAME = "Login";
private final String APP_NAME = "";
private final String context = "src/main/webapp";
private PageTester tester;
@Before
public void init() {
String appPackage = "hu.webapp";
tester = new PageTester(appPackage, APP_NAME, context, AppModule.class);
}
@Test
public void confirmIndexIsLoaded() {
Document document = new Document();
document = tester.renderPage(PAGE_NAME);
assertNotNull(document);
}
}
But I got an RuntimeException
, and it said Request was not handled: 'Login' may not be a valid page name.
But this is a working page in my webapp, and it renders well.
Have somebody any idea(s) what's wrong with test or can somebody shows me a similar working test code?
Thanks in advance!
Generally speaking, this only happens when you inform the wrong package
for your page's package. Take a look (it works for me):
import org.apache.tapestry5.test.PageTester;
public class LoadTest {
private final String PAGE_NAME = "Login"; // It has to be right too!
private final String APP_NAME = "app"; // Where was your app name?
private final String context = "src/main/webapp"; // Is that path right in your project?
private PageTester tester;
@Before
public void init() {
String appPackage = "hu.webapp"; // Check if that's really correct!!!
tester = new PageTester(appPackage, APP_NAME, context);
}
@Test
public void confirmIndexIsLoaded() {
Document document = tester.renderPage(PAGE_NAME);
assertNotNull(document);
}
}
Also, check your app
name, it should have been configured at your web.xml as the Tapestry filter, like in, e.g.:
<filter>
<filter-name>app</filter-name>
<filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>app</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>