You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Neo Anderson <ja...@yahoo.co.uk> on 2009/09/02 16:00:46 UTC

missing behavior definition for the preceeding method call getCookies()


I encounter a problem when testing shiro using easymock. The error message
is : 

java.lang.IllegalStateException: missing behavior definition for the
preceeding method call getCookies()
	at
org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:30)
	at
org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:61)
	at $Proxy15.getContextPath(Unknown Source)
	at
org.apache.shiro.web.attr.CookieAttribute.calculatePath(CookieAttribute.java:301)
	at
org.apache.shiro.web.attr.CookieAttribute.onStoreValue(CookieAttribute.java:322)
	at
org.apache.shiro.web.attr.AbstractWebAttribute.storeValue(AbstractWebAttribute.java:239)
	at
org.apache.shiro.web.WebRememberMeManager.rememberSerializedIdentity(WebRememberMeManager.java:226)
	at
org.apache.shiro.mgt.AbstractRememberMeManager.rememberIdentity(AbstractRememberMeManager.java:182)
	at
org.apache.shiro.mgt.AbstractRememberMeManager.rememberIdentity(AbstractRememberMeManager.java:169)
	at
org.apache.shiro.mgt.AbstractRememberMeManager.rememberIdentity(AbstractRememberMeManager.java:164)
	at
org.apache.shiro.mgt.AbstractRememberMeManager.onSuccessfulLogin(AbstractRememberMeManager.java:154)
	at
org.apache.shiro.mgt.DefaultSecurityManager.rememberMeSuccessfulLogin(DefaultSecurityManager.java:295)
	at
org.apache.shiro.mgt.DefaultSecurityManager.onSuccessfulLogin(DefaultSecurityManager.java:378)
	at
org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:360)


I follow the example of  WebRememberMeManagerTest.java to setup mock web
environment, as below:

		HttpServletRequest mockRequest = createNiceMock(HttpServletRequest.class);
		WebUtils.bind(mockRequest);
		HttpServletResponse mockResponse =
createNiceMock(HttpServletResponse.class);
		WebUtils.bind(mockResponse);

		Configurator configurator = Configurator.createConfigurator();

		securityService = (IAuthentication)
configurator.createService(SecurityService.SHIRO_AUTH_SERVICE);
		Boolean isSuccessful = securityService.login("u1@hotmail.com", "u1");

Where SecurityService contains logic to do login procedure.

		JpaRealm jparealm = (JpaRealm)
configurator.createService(JpaRealm.JPA_REALM);
		DefaultSecurityManager securityManager = (DefaultSecurityManager)
configurator.createService(DEFAULT_WEB_SECURITY_MANAGER);
       		securityManager.setRealm(jparealm);
		SecurityUtils.setSecurityManager(securityManager);

		...
		UsernamePasswordToken token = new UsernamePasswordToken(id, password);	
		token.setRememberMe(true);
		try{ 
				securityManager.login(token);	
		}(....){}

What is the correct procedure (or what needs to be setup) to setup mock web
environment for shiro so that the unit test can get passed?

Thank you.










-- 
View this message in context: http://n2.nabble.com/missing-behavior-definition-for-the-preceeding-method-call-getCookies-tp3566719p3566719.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: missing behavior definition for the preceeding method call getCookies()

Posted by Neo Anderson <ja...@yahoo.co.uk>.
If I add the following extra lines in the test

		expect(mockRequest.getCookies()).andReturn(null);
		expect(mockRequest.getContextPath()).andReturn("/");

 		replay(mockRequest);

the error becomes 

java.lang.NullPointerException
	at
org.apache.shiro.web.session.ServletContainerSessionManager.createSession(ServletContainerSessionManager.java:95)
	at
org.apache.shiro.session.mgt.AbstractSessionManager.start(AbstractSessionManager.java:115)
	at
org.apache.shiro.session.mgt.AbstractSessionManager.start(AbstractSessionManager.java:111)
	at
org.apache.shiro.mgt.SessionsSecurityManager.start(SessionsSecurityManager.java:274)
	at
org.apache.shiro.subject.DelegatingSubject.getSession(DelegatingSubject.java:284)
	at
org.apache.shiro.subject.DelegatingSubject.getSession(DelegatingSubject.java:273)
	at
org.apache.shiro.mgt.SessionSubjectBinder.bindToSession(SessionSubjectBinder.java:87)
	at
org.apache.shiro.mgt.SessionSubjectBinder.bind(SessionSubjectBinder.java:81)
	at
org.apache.shiro.mgt.DefaultSecurityManager.bind(DefaultSecurityManager.java:288)
	at
org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:373)

Is there anything required to be setup before executing login in web env?

Many thanks,


Neo Anderson wrote:
> 
> 
> 
> I follow the example of  WebRememberMeManagerTest.java to setup mock web
> environment, as below:
> 
> 		HttpServletRequest mockRequest =
> createNiceMock(HttpServletRequest.class);
> 		WebUtils.bind(mockRequest);
> 		HttpServletResponse mockResponse =
> createNiceMock(HttpServletResponse.class);
> 		WebUtils.bind(mockResponse);
> 
> 		securityService = (IAuthentication)
> configurator.createService(SecurityService.SHIRO_AUTH_SERVICE);
> 		Boolean isSuccessful = securityService.login("u1@hotmail.com", "u1");
> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/missing-behavior-definition-for-the-preceeding-method-call-getCookies-tp3566719p3566740.html
Sent from the Shiro User mailing list archive at Nabble.com.