java - wicket unit testing : strange behaviour of startPage(Page page) and startPage(Class<Page> pageClass) -


i got strange behaviour of unit tests.

my simple page looks like:

public class registrationpage extends basepage {  public registrationpage(imodel<service> model) {      isuserloggedin();     add(new registrationpanel("registration", model));  }  public registrationpage() {      isuserloggedin(); }  /**  * checks if user logged in.  * if not, user redirected loginpage.  *   */ public void isuserloggedin() {      if (!getsession().issignedin()) {          //  redirecttointerceptpage(new loginpage());         setresponsepage(new loginpage());      } } 

}

now want test page in 2 simple tests: first want check if page renders if no user logged:

    @test public void testregistrationpage() {      wickettester.startpage(registrationpage.class);      // redirect loginpage     wickettester.assertrenderedpage(loginpage.class);  } 

i expect test pass. correct! because of isuserloggedin() method, it's recognized no user logged in , redirected loginpage.

now point want check registrationpage model. ok, next test:

    @test public void testregistrationpage() {      wickettester.startpage(new registrationpage(new model<service>(new service("test", "test", "test"))));      // redirect loginpage     wickettester.assertrenderedpage(loginpage.class);  } 

what expected? expected same in test before. means loginpage should rendered... not!

junit.framework.assertionfailederror: classes not same, expected 'class loginpage', current 'class registrationpage'

it looks startpage(page page) method creates , uses valid session. session accepts user admin/admin credentials.

what difference between 2 startpage(..) methods (class, page)? it's bit strange, same test 1 difference: using model. , fails.

can give advices?

edit:

in session used springsecurity authenticate through ldap. in testcases have repository 2 hardcoded users. admin/admin , user/user. thought session gets costructed if authenticates correctly. dont authenticate in testcases. why there "authenticated" session?!


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -