I have a simple application that I have setup with spring security using a custom MySql Database. You can check out the complete app on github. Now the problem is I'm writing test cases for it and they seems to fail on login page and anything that works after the login. My question is how do I write test cases for it to check the successful login and the subsequent requests?
My Security Config:
My Custom Success Handler:
After some seraching I tried to write test cases like this but they don't seem to be working:
I searched on the net and there are links WithMockUser and UserDetails, but the problem is as you can see I'm setting a my primary key userId in the session in my custom success handler. So I would also need to get the session in my test. Please tell me the simplest way to write tests that will work, possibly with code since I'm new with security and all such.
I had this problem a while back but I haven't found any solutions. Now I'm having it again.
IMO, the kind testing you're trying to do should not be done at the unit test level. I cringe when I see test code like this because it's difficult to discern right away what you're actually trying to test. All that setup code drowns out the intent of the test. I would test from the browser level using a testing framework like Selenium, and test against a running application. These kind of tests are too slow to be categorized as unit tests anyway. They are really integration tests.