Search in sources :

Example 1 with MockServletConfig

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

the class TestServletConfiguration method getConfiguration.

@Override
protected AbstractConfiguration getConfiguration() {
    final MockServletConfig config = new MockServletConfig();
    config.setInitParameter("key1", "value1");
    config.setInitParameter("key2", "value2");
    config.setInitParameter("list", "value1, value2");
    config.setInitParameter("listesc", "value1\\,value2");
    final Servlet servlet = new HttpServlet() {

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

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

Example 2 with MockServletConfig

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

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