Hi,
I'm using Spring 3.1.0.RELEASE with spring security 3.1. I'm trying to test my login controller but running into some problems. Does anyone know what request URI I should be using? My JUnit class is
The clause, "handlerMapping.getHandler(request)" is returning null, causing my test to crash. In the past, I have noticed this is because the request URI isn't correct. Here is my spring-security.xml file ...Code:@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "file:src/main/webapp/WEB-INF/dispatcher-servlet.xml", "file:src/main/webapp/WEB-INF/spring-security.xml"}) public class LoginControllerTest { private MockHttpServletRequest request; private MockHttpServletResponse response; ... @Autowired private RequestMappingHandlerAdapter handlerAdapter; @Autowired private RequestMappingHandlerMapping handlerMapping; @Before public void setUp() { ... request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); } // setUp @Test public void loginSuccessfully() throws Exception { request.setRequestURI("j_spring_security_check"); request.setMethod("POST"); request.setParameter("username", user.getUsername()); request.setParameter("password", user.getPassword()); final Object handler = handlerMapping.getHandler(request).getHandler(); final ModelAndView mav = handlerAdapter.handle(request, response, handler); assertViewName(mav, "welcome"); } // loginSuccessfully
Everything works fine when I run my application in the container, so I know its something specific about my setup. Thanks for any insights, - DaveCode:<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> <http pattern="/user/**" security="none"/> <http auto-config="true"> <intercept-url pattern="/welcome*" access="ROLE_USER" /> <form-login login-page="/login" default-target-url="/welcome" authentication-failure-url="/loginfailed" /> <logout logout-success-url="/logout" /> </http> <authentication-manager> <authentication-provider user-service-ref="customUserDetailsService"> <password-encoder ref="encoder" /> </authentication-provider> </authentication-manager> </beans:beans>


Reply With Quote