TestableResponse resp = tester.renderPageAndReturnResponse("SecuredMethod");
EasyMock.verify(MockFactory.getInstance().getMockedObjects());
assertEquals(500,resp.getStatus()); //err not allowed!
// login..! (wrong role)
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user1","user1","ROLE_DENIED"));
EasyMock.reset(MockFactory.getInstance().getMockedObjects());
EasyMock.replay(MockFactory.getInstance().getMockedObjects());
try {
tester.renderPage("securedmethod");
fail("Should not render a document");
} catch (Exception e) {
}
EasyMock.verify(MockFactory.getInstance().getMockedObjects());
// status = 200 , output = '', coz of redirect to login page
assertEquals(200,resp.getStatus()); //err not allowed!
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user1","user1","ROLE_LOGGEDIN"));
EasyMock.reset(MockFactory.getInstance().getMockedObjects());
EasyMock.replay(MockFactory.getInstance().getMockedObjects());
assertTrue(tester.renderPage("securedmethod").toString().contains("Welcome back user !"));