• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Integration testing of Spring 2.5 Annotation based controller using web context

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jignesh,

I am running in the same problem now. have you got any resolution for the same??

It will be great if you can share the solution if you got any?

Cheers,
Raj
 
raj londonboy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have got all this sorted now. I was sending mock response null which was leading to test failures. Its working for me now.

Working Context Loader:




reply
    Bookmark Topic Watch Topic
  • New Topic