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());
}
use of org.springframework.mock.web.MockServletConfig in project opennms by OpenNMS.
the class HttpRemotingContextIT method testLoadContext.
public void testLoadContext() throws Throwable {
DaoTestConfigBean bean = new DaoTestConfigBean();
bean.afterPropertiesSet();
MockDatabase db = new MockDatabase(true);
DataSourceFactory.setInstance(db);
servletContext = new MockServletContext("file:src/main/webapp");
servletContext.addInitParameter("contextConfigLocation", "classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " + "classpath:/META-INF/opennms/applicationContext-soa.xml " + "classpath:/META-INF/opennms/applicationContext-mockDao.xml " + "classpath*:/META-INF/opennms/component-service.xml " + "classpath*:/META-INF/opennms/component-dao.xml " + // Contexts within this project
"/WEB-INF/applicationContext-common.xml " + "/WEB-INF/applicationContext-serviceRegistryRemoting.xml " + "/WEB-INF/applicationContext-spring-security.xml " + "/WEB-INF/applicationContext-svclayer.xml ");
servletContext.addInitParameter("parentContextKey", "daoContext");
ServletContextEvent e = new ServletContextEvent(servletContext);
contextListener = new ContextLoaderListener();
contextListener.contextInitialized(e);
servletContext.setContextPath(contextPath);
servletConfig = new MockServletConfig(servletContext, "dispatcher");
servletConfig.addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
servletConfig.addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest");
try {
MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
filter = new OpenSessionInViewFilter();
filter.init(filterConfig);
} catch (ServletException se) {
throw se.getRootCause();
}
}
use of org.springframework.mock.web.MockServletConfig in project freemarker by apache.
the class FreemarkerServletTest method assertResponseContentTypeEquals.
private void assertResponseContentTypeEquals(String exptectContentType, String ctInitParam, String overrideCTInitParam, String templateName, String responseCT) throws ServletException, IOException {
MockHttpServletRequest request = createMockHttpServletRequest(servletContext, templateName, null);
MockHttpServletResponse response = new MockHttpServletResponse();
if (responseCT != null) {
response.setContentType(responseCT);
assertEquals(responseCT, response.getContentType());
} else {
assertNull(response.getContentType());
}
MockServletConfig servletConfig = new MockServletConfig(servletContext);
servletConfig.addInitParameter(Configuration.DEFAULT_ENCODING_KEY, "UTF-8");
if (ctInitParam != null) {
servletConfig.addInitParameter(INIT_PARAM_CONTENT_TYPE, ctInitParam);
}
if (overrideCTInitParam != null) {
servletConfig.addInitParameter(INIT_PARAM_OVERRIDE_RESPONSE_CONTENT_TYPE, overrideCTInitParam);
}
TestFreemarkerServlet freemarkerServlet = new TestFreemarkerServlet();
try {
freemarkerServlet.init(servletConfig);
freemarkerServlet.doGet(request, response);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
assertEquals(exptectContentType, response.getContentType());
} finally {
freemarkerServlet.destroy();
}
}
use of org.springframework.mock.web.MockServletConfig in project archiva by apache.
the class RssFeedServletTest method setUp.
@Before
@Override
public void setUp() throws Exception {
final MockServletContext mockServletContext = new MockServletContext();
WebApplicationContext webApplicationContext = new TestWebapplicationContext(applicationContext, mockServletContext);
mockServletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
MockServletConfig mockServletConfig = new MockServletConfig() {
@Override
public ServletContext getServletContext() {
return mockServletContext;
}
};
rssFeedServlet.init(mockServletConfig);
}
Aggregations