0

I am using spring security form based login mechanism,after sucessful login I am storing one object in session. Using that object stored in session to decide the fate on next requests.But now when I am testing that using spring mvc test with security support.I am not able to populate that session object after sucessful authentication. I tried providing session with object populated at time of login but I guess spring security clearing that session.

So How can I set that object into session after sucessful login in spring mvc test.

MasterCode
  • 975
  • 5
  • 21
  • 44

1 Answers1

0

If you want to check session content in MVC Unit Tests, you should fake the session. You can use Mock object for faking session.

Luzan Baral
  • 3,678
  • 5
  • 37
  • 68
Narek Arzumanyan
  • 616
  • 3
  • 11
  • But Spring security clears previous session and creates new session each time you sucessfully authenticate..And my session object is also populated after authetication.So when testing as using formLogin() which do not have provision to accept Mock sessions – MasterCode Jul 07 '15 at 08:51
  • `var user= new User(); var mockSession = new Mock(); mockSession.SetupGet(s => s["CurrentUser"]).Returns(user);` session["CurrentUser"] always returns user – Narek Arzumanyan Jul 07 '15 at 10:01