Search in sources :

Example 1 with MockServletContext

use of com.mockobjects.servlet.MockServletContext 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 MockServletContext

use of com.mockobjects.servlet.MockServletContext in project commons-configuration by apache.

the class TestServletContextConfiguration method getConfiguration.

@Override
protected AbstractConfiguration getConfiguration() {
    final Properties parameters = new Properties();
    parameters.setProperty("key1", "value1");
    parameters.setProperty("key2", "value2");
    parameters.setProperty("list", "value1, value2");
    parameters.setProperty("listesc", "value1\\,value2");
    // create a servlet context
    final ServletContext context = new MockServletContext() {

        @Override
        public String getInitParameter(final String key) {
            return parameters.getProperty(key);
        }

        @Override
        public Enumeration<?> getInitParameterNames() {
            return parameters.keys();
        }
    };
    // create a servlet config
    final MockServletConfig config = new MockServletConfig();
    config.setServletContext(context);
    // create a servlet
    final Servlet servlet = new HttpServlet() {

        /**
         * Serial version UID.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public ServletConfig getServletConfig() {
            return config;
        }
    };
    final ServletContextConfiguration resultConfig = new ServletContextConfiguration(servlet);
    resultConfig.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return resultConfig;
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) HttpServlet(javax.servlet.http.HttpServlet) MockServletContext(com.mockobjects.servlet.MockServletContext) ServletContext(javax.servlet.ServletContext) MockServletConfig(com.mockobjects.servlet.MockServletConfig) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) Properties(java.util.Properties) MockServletContext(com.mockobjects.servlet.MockServletContext)

Aggregations

MockServletContext (com.mockobjects.servlet.MockServletContext)2 MockHttpServletRequest (com.mockobjects.servlet.MockHttpServletRequest)1 MockHttpServletResponse (com.mockobjects.servlet.MockHttpServletResponse)1 MockServletConfig (com.mockobjects.servlet.MockServletConfig)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 Servlet (javax.servlet.Servlet)1 ServletContext (javax.servlet.ServletContext)1 HttpServlet (javax.servlet.http.HttpServlet)1 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)1