Search in sources :

Example 1 with MockHttpServletRequest

use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.

the class ServletActionContextTest method setUp.

public void setUp() {
    Map<String, Object> extraContext = new HashMap<>();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    servletContext = new MockServletContext();
    extraContext.put(HTTP_REQUEST, request);
    extraContext.put(HTTP_RESPONSE, response);
    extraContext.put(SERVLET_CONTEXT, servletContext);
    actionContext = ActionContext.of(extraContext).bind();
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequest(com.mockobjects.servlet.MockHttpServletRequest) MockHttpServletResponse(com.mockobjects.servlet.MockHttpServletResponse) MockServletContext(com.mockobjects.servlet.MockServletContext)

Example 2 with MockHttpServletRequest

use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.

the class RolesInterceptorTest method testIsAllowed_userAllowedAndGuestDisallowed.

public void testIsAllowed_userAllowedAndGuestDisallowed() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest() {

        public boolean isUserInRole(String role) {
            return "user".equals(role) || "guest".equals(role);
        }
    };
    // has to be a user
    interceptor.setAllowedRoles("user");
    // and not a guest
    interceptor.setDisallowedRoles("guest");
    assertFalse(interceptor.isAllowed(request, null));
}
Also used : MockHttpServletRequest(com.mockobjects.servlet.MockHttpServletRequest)

Example 3 with MockHttpServletRequest

use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.

the class RolesInterceptorTest method testIsAllowed.

public void testIsAllowed() throws Exception {
    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));
}
Also used : MockHttpServletRequest(com.mockobjects.servlet.MockHttpServletRequest)

Example 4 with MockHttpServletRequest

use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.

the class RolesInterceptorTest method testIsAllowed_sameRoleAllowedAndDisallowed.

public void testIsAllowed_sameRoleAllowedAndDisallowed() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest() {

        public boolean isUserInRole(String role) {
            return "admin".equals(role);
        }
    };
    interceptor.setAllowedRoles("admin");
    interceptor.setDisallowedRoles("admin");
    assertFalse(interceptor.isAllowed(request, null));
}
Also used : MockHttpServletRequest(com.mockobjects.servlet.MockHttpServletRequest)

Example 5 with MockHttpServletRequest

use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.

the class Restful2ActionMapperTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mapper = new Restful2ActionMapper();
    mapper.setExtensions("");
    req = new MockHttpServletRequest();
    req.setupGetParameterMap(new HashMap());
    req.setupGetContextPath("/my/namespace");
    config = new DefaultConfiguration();
    PackageConfig pkg = new PackageConfig.Builder("myns").namespace("/my/namespace").build();
    PackageConfig pkg2 = new PackageConfig.Builder("my").namespace("/my").build();
    config.addPackageConfig("mvns", pkg);
    config.addPackageConfig("my", pkg2);
    configManager = new ConfigurationManager(Container.DEFAULT_NAME) {

        public Configuration getConfiguration() {
            return config;
        }
    };
}
Also used : Configuration(com.opensymphony.xwork2.config.Configuration) DefaultConfiguration(com.opensymphony.xwork2.config.impl.DefaultConfiguration) HashMap(java.util.HashMap) MockHttpServletRequest(com.mockobjects.servlet.MockHttpServletRequest) DefaultConfiguration(com.opensymphony.xwork2.config.impl.DefaultConfiguration) ConfigurationManager(com.opensymphony.xwork2.config.ConfigurationManager) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Aggregations

MockHttpServletRequest (com.mockobjects.servlet.MockHttpServletRequest)10 HashMap (java.util.HashMap)3 Configuration (com.opensymphony.xwork2.config.Configuration)2 ConfigurationManager (com.opensymphony.xwork2.config.ConfigurationManager)2 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)2 DefaultConfiguration (com.opensymphony.xwork2.config.impl.DefaultConfiguration)2 MockHttpServletResponse (com.mockobjects.servlet.MockHttpServletResponse)1 MockServletContext (com.mockobjects.servlet.MockServletContext)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Semaphore (java.util.concurrent.Semaphore)1 ServletRequest (javax.servlet.ServletRequest)1 ConfigurationMap (org.apache.commons.configuration2.ConfigurationMap)1 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)1 StrutsMockHttpServletRequest (org.apache.struts2.views.jsp.StrutsMockHttpServletRequest)1