use of org.springframework.mock.web.MockServletConfig in project gocd by gocd.
the class DelegatingServletTest method shouldDelegateToTheGivenServlet.
@Test
public void shouldDelegateToTheGivenServlet() throws IOException, ServletException {
MockServletContext ctx = new MockServletContext();
ctx.addInitParameter(DelegatingListener.DELEGATE_SERVLET, DummyServlet.class.getCanonicalName());
ServletContextEvent evt = new ServletContextEvent(ctx);
DelegatingListener listener = new DelegatingListener();
listener.contextInitialized(evt);
assertThat((DummyServlet) ctx.getAttribute(DelegatingListener.DELEGATE_SERVLET), isA(DummyServlet.class));
DelegatingServlet servlet = new DelegatingServlet();
servlet.init(new MockServletConfig(ctx));
servlet.service(httpServletRequest, new MockHttpServletResponse());
verify(servletRequestWrapper).setRequestURI("/go/stuff/action");
}
use of org.springframework.mock.web.MockServletConfig in project opennms by OpenNMS.
the class AbstractSpringJerseyRestTestCase method setUp.
@Before
public void setUp() throws Throwable {
beforeServletStart();
setUser("admin", new String[] { "ROLE_ADMIN" });
DaoTestConfigBean bean = new DaoTestConfigBean();
bean.afterPropertiesSet();
MockDatabase db = new MockDatabase(true);
DataSourceFactory.setInstance(db);
XADataSourceFactory.setInstance(db);
try {
MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
setFilter(new OpenSessionInViewFilter());
getFilter().init(filterConfig);
// Jersey
/*
setServletConfig(new MockServletConfig(servletContext, "dispatcher"));
getServletConfig().addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
getServletConfig().addInitParameter("com.sun.jersey.config.property.packages", "org.codehaus.jackson.jaxrs;org.opennms.web.rest;org.opennms.web.rest.config");
getServletConfig().addInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter");
getServletConfig().addInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.GZIPContentEncodingFilter");
setDispatcher(new SpringServlet());
getDispatcher().init(getServletConfig());
*/
// Apache CXF
setServletConfig(new MockServletConfig(servletContext, "dispatcher"));
getServletConfig().addInitParameter("config-location", m_cxfContextPath);
CXFServlet servlet = new CXFServlet();
setDispatcher(servlet);
getDispatcher().init(getServletConfig());
} catch (ServletException se) {
throw se.getRootCause();
}
afterServletStart();
System.err.println("------------------------------------------------------------------------------");
}
use of org.springframework.mock.web.MockServletConfig in project grails-core by grails.
the class GrailsLayoutDecoratorMapperTests method testDecoratedByActionConvention.
public void testDecoratedByActionConvention() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext) webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/test2/testAction.gsp", "<html><body><g:layoutBody /></body></html>");
MockHttpServletRequest request = (MockHttpServletRequest) webRequest.getCurrentRequest();
request.setMethod("GET");
request.setRequestURI("orders/list");
ServletContext context = webRequest.getServletContext();
GroovyClassLoader gcl = new GroovyClassLoader();
// create mock controller
GroovyObject controller = (GroovyObject) gcl.parseClass("class Test2Controller {\n" + "def controllerName = 'test2'\n" + "def actionUri = '/test2/testAction'\n" + "}").newInstance();
request.setAttribute(GrailsApplicationAttributes.CONTROLLER, controller);
GrailsLayoutDecoratorMapper m = new GrailsLayoutDecoratorMapper();
com.opensymphony.module.sitemesh.Config c = new com.opensymphony.module.sitemesh.Config(new MockServletConfig(context));
m.init(c, null, null);
HTMLPageParser parser = new HTMLPageParser();
String html = "<html><head><title>Test title</title></head><body>here is the body</body></html>";
Page page = parser.parse(html.toCharArray());
Decorator d = m.getDecorator(request, page);
assertNotNull(d);
assertEquals("/layouts/test2/testAction.gsp", d.getPage());
assertEquals("test2/testAction", d.getName());
}
use of org.springframework.mock.web.MockServletConfig in project grails-core by grails.
the class GrailsLayoutDecoratorMapperTests method testDecoratedByApplicationConventionForViewsNotRenderedByAController.
public void testDecoratedByApplicationConventionForViewsNotRenderedByAController() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext) webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/application.gsp", "<html><body><h1>Default Layout</h1><g:layoutBody /></body></html>");
MockHttpServletRequest request = (MockHttpServletRequest) webRequest.getCurrentRequest();
request.setMethod("GET");
request.setRequestURI("/");
ServletContext context = webRequest.getServletContext();
GrailsLayoutDecoratorMapper m = new GrailsLayoutDecoratorMapper();
com.opensymphony.module.sitemesh.Config c = new com.opensymphony.module.sitemesh.Config(new MockServletConfig(context));
m.init(c, null, null);
HTMLPageParser parser = new HTMLPageParser();
String html = "<html><head><title>Foo title</title></head><body>here is the body</body></html>";
Page page = parser.parse(html.toCharArray());
Decorator d = m.getDecorator(request, page);
assertNotNull(d);
assertEquals("/layouts/application.gsp", d.getPage());
assertEquals("application", d.getName());
}
use of org.springframework.mock.web.MockServletConfig in project grails-core by grails.
the class GrailsLayoutDecoratorMapperTests method testDecoratedByApplicationConvention.
public void testDecoratedByApplicationConvention() throws Exception {
GrailsWebRequest webRequest = buildMockRequest(null);
webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
MockApplicationContext appCtx = (MockApplicationContext) webRequest.getApplicationContext();
appCtx.registerMockResource("/grails-app/views/layouts/application.gsp", "<html><body><h1>Default Layout</h1><g:layoutBody /></body></html>");
MockHttpServletRequest request = (MockHttpServletRequest) webRequest.getCurrentRequest();
request.setMethod("GET");
request.setRequestURI("orders/list");
ServletContext context = webRequest.getServletContext();
GroovyClassLoader gcl = new GroovyClassLoader();
// create mock controller
GroovyObject controller = (GroovyObject) gcl.parseClass("class FooController {\n" + "def controllerName = 'foo'\n" + "def actionUri = '/foo/fooAction'\n" + "}").newInstance();
request.setAttribute(GrailsApplicationAttributes.CONTROLLER, controller);
GrailsLayoutDecoratorMapper m = new GrailsLayoutDecoratorMapper();
com.opensymphony.module.sitemesh.Config c = new com.opensymphony.module.sitemesh.Config(new MockServletConfig(context));
m.init(c, null, null);
HTMLPageParser parser = new HTMLPageParser();
String html = "<html><head><title>Foo title</title></head><body>here is the body</body></html>";
Page page = parser.parse(html.toCharArray());
Decorator d = m.getDecorator(request, page);
assertNotNull(d);
assertEquals("/layouts/application.gsp", d.getPage());
assertEquals("application", d.getName());
}
Aggregations