当前位置: 首页>>代码示例>>Java>>正文


Java MockServletConfig类代码示例

本文整理汇总了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();
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:18,代码来源:CrnkServletRejectJsonTest.java

示例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 );

}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:25,代码来源:AbstractRepositoryServletTestCase.java

示例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 );
}
 
开发者ID:ruikom,项目名称:apache-archiva,代码行数:25,代码来源:RssFeedServletTest.java

示例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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:MockMvcBuilderSupport.java

示例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");
	}
}
 
开发者ID:tetherless-world,项目名称:s2s,代码行数:21,代码来源:SessionServletTest.java

示例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");
}
 
开发者ID:ggeorgovassilis,项目名称:gwt-sl,代码行数:18,代码来源:TestRPCExporter.java

示例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;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:MockMvcBuilderSupport.java

示例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);
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:25,代码来源:SpringWebMvc_5_x_IT.java

示例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"));
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:23,代码来源:GeomajasControllerTest.java

示例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"));
}
 
开发者ID:geomajas,项目名称:geomajas-project-client-gwt2,代码行数:22,代码来源:GeomajasControllerTest.java

示例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  ######");
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:19,代码来源:EgovExcelControllerTest.java

示例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);
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:9,代码来源:SafeDispatcherServletTests.java

示例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();
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:16,代码来源:CrnkServletTest.java

示例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);
}
 
开发者ID:intuit,项目名称:karate,代码行数:17,代码来源:MockJerseyServlet.java

示例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;
}
 
开发者ID:intuit,项目名称:karate,代码行数:14,代码来源:MockSpringMvcServlet.java


注:本文中的org.springframework.mock.web.MockServletConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。