com.mockobjects.servlet.MockServletContext Java Examples
The following examples show how to use
com.mockobjects.servlet.MockServletContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TagTestUtils.java From uyuni with GNU General Public License v2.0 | 6 votes |
/** * Setup the TagTestHelper class with the * appropriate infrastructure. * @param tag The Tag lib to test. * @param url URL to be passed into the Mock Servlet Context. * @param request The request that was created by the test to be used * by this helper * @return TagTestHelper * @see com.mockobjects.helpers.TagTestHelper */ public static TagTestHelper setupTagTest(Tag tag, URL url, RhnMockHttpServletRequest request) { TagTestHelper tth = new TagTestHelper(tag); MockPageContext mpc = tth.getPageContext(); MockServletContext ctx = (MockServletContext) mpc.getServletContext(); if (request == null) { request = TestUtils.getRequestWithSessionAndUser(); } request.setRequestURL("http://localhost:8080/rhnjava/index.jsp"); request.addAttribute("requestedUri", "http://localhost:8080/rhnjava/index.jsp"); request.setSession(new RhnMockHttpSession()); mpc.setRequest(request); mpc.setJspWriter(new RhnMockJspWriter()); if (url != null) { ctx.setupGetResource(url); } return tth; }
Example #2
Source File: TagTestUtils.java From spacewalk with GNU General Public License v2.0 | 6 votes |
/** * Setup the TagTestHelper class with the * appropriate infrastructure. * @param tag The Tag lib to test. * @param url URL to be passed into the Mock Servlet Context. * @param request The request that was created by the test to be used * by this helper * @return TagTestHelper * @see com.mockobjects.helpers.TagTestHelper */ public static TagTestHelper setupTagTest(Tag tag, URL url, RhnMockHttpServletRequest request) { TagTestHelper tth = new TagTestHelper(tag); MockPageContext mpc = tth.getPageContext(); MockServletContext ctx = (MockServletContext) mpc.getServletContext(); if (request == null) { request = TestUtils.getRequestWithSessionAndUser(); } request.setRequestURL("http://localhost:8080/rhnjava/index.jsp"); request.addAttribute("requestedUri", "http://localhost:8080/rhnjava/index.jsp"); request.setSession(new RhnMockHttpSession()); mpc.setRequest(request); mpc.setJspWriter(new RhnMockJspWriter()); if (url != null) { ctx.setupGetResource(url); } return tth; }
Example #3
Source File: TestServletContextConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
@Override protected AbstractConfiguration getEmptyConfiguration() { // create a servlet context final ServletContext context = new MockServletContext() { @Override public Enumeration<?> getInitParameterNames() { return new Properties().keys(); } }; return new ServletContextConfiguration(context); }
Example #4
Source File: TestServletContextConfiguration.java From commons-configuration with Apache License 2.0 | 4 votes |
@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; }