Questions about integration tests with SeamTest
piotr.sobczyk Feb 12, 2010 9:46 PMI'm a newbie in topic integration testing with SeamTest. I have two questions that seem to be easy:
1. In many test cases from Seam examples I noticed such assertion in afterRequest method:
assert !isRenderResponseBegun();
What exactly it is supposed to check? There is no documentation for these methods and it's hard to find it out.
I will paste an excerpt from Blog example to give it a context:
String id = new FacesRequest(){ @Override protected void updateModelValues() throws Exception { ( (SearchService) getInstance(SearchService.class) ).setSearchPattern("seam"); } @Override protected String getInvokeApplicationOutcome() { return "/search.xhtml"; } @Override protected void afterRequest() { assert !isRenderResponseBegun(); } }.run();
Why Render Response phase should not begun in this test?
2. I noticed that there is exception when I'm trying to put (Non)FacesRequest object inside method annotated as @BeforeClass:
@BeforeClass public void startup() throws Exception{ new FacesRequest(){ @Override protected void updateModelValues() throws Exception { setValue("#{identity.username}","user"); setValue("#{identity.password}","secret"); } @Override protected void invokeApplication() throws Exception{ invokeMethod("#{identity.login}"); } }.run(); }
And there is an exception:
java.lang.NullPointerException at org.jboss.seam.mock.MockExternalContext$3.getAttribute(MockExt.java:369) at org.jboss.seam.mock.MockExternalContext$AttributeMap.get(Mockext.java:393) at org.jboss.seam.contexts.BasicContext.get(BasicContext.java:49 at org.jboss.seam.Component.getInstance(Component.java:1999) at org.jboss.seam.Component.getInstance(Component.java:1994) at org.jboss.seam.Component.getInstance(Component.java:1967) at org.jboss.seam.web.Session.getInstance(Session.java:122) at org.jboss.seam.contexts.FacesLifecycle.endRequest(FacesLifecycle.java:126) at org.jboss.seam.mock.AbstractSeamTest$Request.run(AbstractSeam
It seems that inside @AfterClass,@BeforeMethod and @AfterMethod methods everything works allright.
So what is the pattern to extract code common for all test cases that need to make request (logging in is the best example) to the one place if @BeforeClass method is wrong place? I didn't see any attempts to do so in example tests but it's kind of a must in real life applications. Any hints?