本文整理汇总了Java中org.springframework.mock.web.MockServletConfig类的典型用法代码示例。如果您正苦于以下问题:Java MockServletConfig类的具体用法?Java MockServletConfig怎么用?Java MockServletConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockServletConfig类属于org.springframework.mock.web包,在下文中一共展示了MockServletConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: before
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
@Before
public void before() throws Exception {
servlet = new CrnkServlet();
servletContext = new MockServletContext();
((MockServletContext) servletContext).setContextPath("");
MockServletConfig servletConfig = new MockServletConfig(servletContext);
servletConfig
.addInitParameter(CrnkProperties.RESOURCE_SEARCH_PACKAGE, RESOURCE_SEARCH_PACKAGE);
servletConfig
.addInitParameter(CrnkProperties.RESOURCE_DEFAULT_DOMAIN, RESOURCE_DEFAULT_DOMAIN);
servletConfig
.addInitParameter(CrnkProperties.REJECT_PLAIN_JSON, String.valueOf(true));
servlet.init(servletConfig);
nodeRepository = new NodeRepository();
}
示例2: startRepository
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
protected void startRepository()
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;
}
};
unauthenticatedRepositoryServlet.init( mockServletConfig );
}
示例3: setUp
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
@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 );
}
示例4: createMockMvc
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
protected final MockMvc createMockMvc(Filter[] filters, MockServletConfig servletConfig,
WebApplicationContext webAppContext, RequestBuilder defaultRequestBuilder,
List<ResultMatcher> globalResultMatchers, List<ResultHandler> globalResultHandlers,
Boolean dispatchOptions) {
ServletContext servletContext = webAppContext.getServletContext();
TestDispatcherServlet dispatcherServlet = new TestDispatcherServlet(webAppContext);
dispatcherServlet.setDispatchOptionsRequest(dispatchOptions);
try {
dispatcherServlet.init(servletConfig);
}
catch (ServletException ex) {
// should never happen..
throw new MockMvcBuildException("Failed to initialize TestDispatcherServlet", ex);
}
MockMvc mockMvc = new MockMvc(dispatcherServlet, filters, servletContext);
mockMvc.setDefaultRequest(defaultRequestBuilder);
mockMvc.setGlobalResultMatchers(globalResultMatchers);
mockMvc.setGlobalResultHandlers(globalResultHandlers);
return mockMvc;
}
示例5: SessionServletTest
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
/**
* Constructor for SessionServletTest, calls superclass constructor and sets up servlet
* @param name
*/
public SessionServletTest(String name) {
super(name);
_servlet = new SessionServlet();
// Create mock objects for servlet context & config
MockServletContext context = new MockServletContext("/");
MockServletConfig config = new MockServletConfig(context);
config.addInitParameter("s2s-session-directory", "/tmp/s2s/sessions");
try {
_servlet.init(config);
} catch (ServletException e) {
fail("Could not instantiate SessionServlet");
}
}
示例6: setUp
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
requestPayload = readResource("request_add.txt");
responsePayload = readResource("response_add.txt");
MockServletContext servletContext = new MockServletContext(new ResourceLoaderSupport());
MockServletConfig servletConfig = new MockServletConfig(servletContext);
applicationContext = new XmlWebApplicationContext();
applicationContext.setServletContext(servletContext);
applicationContext.setServletConfig(servletConfig);
applicationContext.setConfigLocations(new String[] { "src/main/webapp/WEB-INF/exporter-servlet.xml",
"src/main/webapp/WEB-INF/applicationContext.xml" });
applicationContext.refresh();
handlerMapping = (SimpleUrlHandlerMapping) applicationContext
.getBean("org.springframework.web.servlet.handler.SimpleUrlHandlerMapping");
}
示例7: createMockMvc
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
protected final MockMvc createMockMvc(Filter[] filters, MockServletConfig servletConfig,
WebApplicationContext webAppContext, RequestBuilder defaultRequestBuilder,
List<ResultMatcher> globalResultMatchers, List<ResultHandler> globalResultHandlers, Boolean dispatchOptions) {
ServletContext servletContext = webAppContext.getServletContext();
TestDispatcherServlet dispatcherServlet = new TestDispatcherServlet(webAppContext);
dispatcherServlet.setDispatchOptionsRequest(dispatchOptions);
try {
dispatcherServlet.init(servletConfig);
}
catch (ServletException ex) {
// should never happen..
throw new MockMvcBuildException("Failed to initialize TestDispatcherServlet", ex);
}
MockMvc mockMvc = new MockMvc(dispatcherServlet, filters, servletContext);
mockMvc.setDefaultRequest(defaultRequestBuilder);
mockMvc.setGlobalResultMatchers(globalResultMatchers);
mockMvc.setGlobalResultHandlers(globalResultHandlers);
return mockMvc;
}
示例8: testRequest
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
@Test
public void testRequest() throws Exception {
MockServletConfig config = new MockServletConfig();
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
config.addInitParameter("contextConfigLocation", "classpath:spring-web-test.xml");
req.setMethod("GET");
req.setRequestURI("/");
req.setRemoteAddr("1.2.3.4");
DispatcherServlet servlet = new DispatcherServlet();
servlet.init(config);
servlet.service(req, res);
Method method = FrameworkServlet.class.getDeclaredMethod("doGet", HttpServletRequest.class, HttpServletResponse.class);
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTrace(Expectations.event(SPRING_MVC, method));
verifier.verifyTraceCount(0);
}
示例9: testMockWebContext
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
@Test
public void testMockWebContext() throws ServletException, IOException {
// create mock context that loads from the classpath
MockServletConfig config = new MockServletConfig();
MockHttpServletRequest request = new MockHttpServletRequest(config.getServletContext());
request.setContentType("text/x-gwt-rpc");
request.setCharacterEncoding("UTF-8");
request.setContent(("6|0|10|http://apps.geomajas.org/explorer/be.geosparc.Explorer/"
+ "|54044FB0C988344F1715C8B91330B0A2|org.geomajas.gwt.client.GeomajasService|"
+ "execute|org.geomajas.gwt.client.command.GwtCommand/4093389776|command.configuration.GetMap|"
+ "org.geomajas.command.dto.GetMapConfigurationRequest/104733661|explorer|mainMap|"
+ "ss.TqRPfHFh24NVxB|1|2|3|4|1|5|5|6|7|8|9|0|10|").getBytes("UTF-8"));
request.addHeader("X-GWT-Permutation", "54044FB0C988344F1715C8B91330B0A2");
request.addHeader("X-GWT-Module-Base", "http://test/module/");
MockHttpServletResponse response = new MockHttpServletResponse();
defaultController.setServletConfig(config);
defaultController.doPost(request, response);
// expect the message of the out-dated 1.3 policy of GWT
Assert.assertTrue(response.getContentAsString().contains(
"Type \\x27org.geomajas.gwt.client.command.GwtCommand\\x27 was not assignable"
+ " to \\x27com.google.gwt.user.client.rpc.IsSerializable\\x27"));
}
示例10: testSerializationPolicy
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
@Test
public void testSerializationPolicy() throws UnsupportedEncodingException, ServletException {
// create mock context that loads from the classpath
MockServletConfig config = new MockServletConfig();
MockHttpServletRequest request = new MockHttpServletRequest(config.getServletContext());
request.setContentType("text/x-gwt-rpc");
request.setCharacterEncoding("UTF-8");
request.setContent(("6|0|10|http://apps.geomajas.org/explorer/be.geosparc.Explorer/"
+ "|54044FB0C988344F1715C8B91330B0A2|org.geomajas.gwt.client.GeomajasService|"
+ "execute|org.geomajas.gwt.client.command.GwtCommand/4093389776|command.configuration.GetMap|"
+ "org.geomajas.command.dto.GetMapConfigurationRequest/104733661|explorer|mainMap|"
+ "ss.TqRPfHFh24NVxB|1|2|3|4|1|5|5|6|7|8|9|0|10|").getBytes("UTF-8"));
request.addHeader("X-GWT-Permutation", "54044FB0C988344F1715C8B91330B0A2");
request.addHeader("X-GWT-Module-Base", "http://test/module/");
MockHttpServletResponse response = new MockHttpServletResponse();
customController.setServletConfig(config);
customController.doPost(request, response);
// expect the message that the type is missing from our policy file
Assert.assertTrue(response.getContentAsString().contains(
"Type \\x27org.geomajas.gwt.client.command.GwtCommand\\x27 was not included in the set of types"));
}
示例11: init
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
@Before
public void init() {
this.dispatcher = new DispatcherServlet() {
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.setParent(applicationContext);
wac.refresh();
return wac;
}
};
try {
this.dispatcher.init(new MockServletConfig());
} catch (ServletException e) {
e.printStackTrace();
}
log.debug("###### EgovExcelServiceControllerTest ######");
}
示例12: setUp
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
this.safeServlet = new SafeDispatcherServlet();
this.mockContext = new MockServletContext();
this.mockConfig = new MockServletConfig(this.mockContext);
}
示例13: before
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
@Before
public void before() throws Exception {
servlet = new CrnkServlet();
servletContext = new MockServletContext();
((MockServletContext) servletContext).setContextPath("");
servletConfig = new MockServletConfig(servletContext);
((MockServletConfig) servletConfig)
.addInitParameter(CrnkProperties.RESOURCE_SEARCH_PACKAGE, RESOURCE_SEARCH_PACKAGE);
((MockServletConfig) servletConfig)
.addInitParameter(CrnkProperties.RESOURCE_DEFAULT_DOMAIN, RESOURCE_DEFAULT_DOMAIN);
servlet.init(servletConfig);
nodeRepository = new NodeRepository();
}
示例14: MockJerseyServlet
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
/**
* this zero-arg constructor will be invoked if you use the 'configure
* httpClientClass' option refer to the MockJerseyServletFactory for how you
* can construct this manually and have full control over
* dependency-injection specific to your environment
*
* @throws Exception
*/
public MockJerseyServlet() throws Exception {
logger.info("auto construction of mock http servlet");
ServletConfig servletConfig = new MockServletConfig();
servletContext = new MockServletContext();
ResourceConfig resourceConfig = new ResourceConfig(HelloResource.class);
servlet = new ServletContainer(resourceConfig);
servlet.init(servletConfig);
}
示例15: initServlet
import org.springframework.mock.web.MockServletConfig; //导入依赖的package包/类
private static Servlet initServlet() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(MockDemoConfig.class);
context.setServletContext(SERVLET_CONTEXT);
DispatcherServlet servlet = new DispatcherServlet(context);
ServletConfig servletConfig = new MockServletConfig();
try {
servlet.init(servletConfig);
} catch (Exception e) {
throw new RuntimeException(e);
}
return servlet;
}