Custom Web Context Loader
Base
Test Class to be inherited by the test controllers
Controller
Test Controller
spring-servlet.xml
Actually I dont have the presentation tier(
JSP Pages) ready.And I want to test my controller to verify that it is behaving correctly.
As can be seen in controller the
YGUser model object will be populated from the values in the html form(will be generated by the spring form tag library) in the JSP page.
In such a case I will receive a correctly populated YGUser instance in the controller when actually hitting the request
"..../registerUser.do"
I dont want to use @RequestParam annotation for the method argument YGUser.
When debugging the test controller, I am receiving a YGUser instance but with the instance properties values as null because of the @ModelAttribute annotated method being called first.
I am testing the Spring 2.5 annotation based controllers first time.Above is what I could find on the web for doing the same.
I am stuck at how to proceed ahead, in the sense that how to provide the appropriate populated model objects to MockHttpServletRequest
and verify that I am getting the expected response, the view, etc?
For e.g. in my
testRegisterUser() method, I have created a "testUser" instance (which in real scenario would be created by Spring implicitly
because of the
YGUser model attribute bound to spring's form tag in the JSP page).
But how to pass the same to my test context so that actually when the
registerUser() method in the controller is called the
YGUser is populated with the test values I set in the test method.
Similarly If I want to validate my
YGUser object before saving to the database using Spring Validation API then how to test it in the context mentioned above.
Please help in making it work.
Also, any comments on incorrect usage of API or improving the code using API in an efficient way would be really helpful.