FileDocCategorySizeDatePackage
RolesInterceptorTest.javaAPI DocExample3094Mon Jul 23 13:26:18 BST 2007org.apache.struts2.interceptor

RolesInterceptorTest

public class RolesInterceptorTest extends org.apache.struts2.StrutsTestCase

Fields Summary
private RolesInterceptor
interceptor
Constructors Summary
Methods Summary
public voidsetUp()


         
        super.setUp();
        interceptor = new RolesInterceptor();
    
public voidtestHandleRejection()

        MockHttpServletResponse response = new MockHttpServletResponse();
        response.setExpectedError(response.SC_FORBIDDEN);
        interceptor.handleRejection(null, response);
        response.verify();
    
public voidtestIsAllowed()

        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 voidtestStringToList()

        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));