RolesInterceptorTestpublic class RolesInterceptorTest extends org.apache.struts2.StrutsTestCase
Fields Summary |
---|
private RolesInterceptor | interceptor |
Methods Summary |
---|
public void | setUp()
super.setUp();
interceptor = new RolesInterceptor();
| public void | testHandleRejection()
MockHttpServletResponse response = new MockHttpServletResponse();
response.setExpectedError(response.SC_FORBIDDEN);
interceptor.handleRejection(null, response);
response.verify();
| public void | testIsAllowed()
MockHttpServletRequest request = new MockHttpServletRequest() {
public boolean isUserInRole(String role) {
return "admin".equals(role);
}
};
interceptor.setAllowedRoles("admin");
assertTrue(interceptor.isAllowed(request, null));
interceptor.setAllowedRoles("bar, admin");
assertTrue(interceptor.isAllowed(request, null));
interceptor.setAllowedRoles(null);
assertTrue(interceptor.isAllowed(request, null));
interceptor.setDisallowedRoles("bar");
assertTrue(interceptor.isAllowed(request, null));
interceptor.setDisallowedRoles("bar, admin");
assertTrue(!interceptor.isAllowed(request, null));
| public void | testStringToList()
List list = interceptor.stringToList("foo");
assertNotNull(list);
assertEquals(1, list.size());
list = interceptor.stringToList("foo,bar");
assertEquals(2, list.size());
assertEquals("foo", (String)list.get(0));
list = interceptor.stringToList("foo, bar");
assertEquals(2, list.size());
assertEquals("bar", (String)list.get(1));
list = interceptor.stringToList("foo , bar");
assertEquals(2, list.size());
assertEquals("bar", (String)list.get(1));
|
|