• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java MockHttpServletRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.wicket.protocol.http.mock.MockHttpServletRequest的典型用法代码示例。如果您正苦于以下问题:Java MockHttpServletRequest类的具体用法?Java MockHttpServletRequest怎么用?Java MockHttpServletRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MockHttpServletRequest类属于org.apache.wicket.protocol.http.mock包,在下文中一共展示了MockHttpServletRequest类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: configureFilterConfig

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
@Before
public void configureFilterConfig() {
    MockApplication application = new MockApplication();

    MockServletContext context = new MockServletContext(application, "");
    context.setAttribute("nada", ServerContext.WORKLIST);

    filterConfig = new MockFilterConfig(context);
    filterConfig.addInitParameter(SSOFilter.URL_EXCLUDE_PATTERN_PARAM, "/rest");
    filterConfig.addInitParameter(SSOFilter.CLIENT_LOGOUT_URL, "/logout");
    filterConfig.addInitParameter(SSOConfigurableFilter.SINGULAR_CONTEXT_ATTRIBUTE, "nada");

    request = new MockHttpServletRequest(application, new MockHttpSession(context), context){
        @Override
        public String getContextPath() {
            return ServerContext.WORKLIST.getUrlPath();
        }
    };

    response = new MockHttpServletResponse(request);

}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:23,代码来源:SSOFilterTest.java


示例2: testGetVariable

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testGetVariable() {
    final WicketTester tester = getTester();

    TestAjaxBehavior behavior = new TestAjaxBehavior("testA");
    Map map = new Map("map");
    map.add(behavior);

    tester.startComponentInPage(map);

    MockHttpServletRequest request = this.prepareRequest(tester, behavior, "testA", "testValue");
    tester.processRequest(request);

    StringValue actual = behavior.actualVariableValue;
    assertThat(actual.isEmpty()).isFalse();
    assertThat(actual.toString()).isEqualTo("testValue");
}
 
开发者ID:DrunkenPandaFans,项目名称:wicket-leaflet,代码行数:18,代码来源:LeafletAjaxBehaviorTest.java


示例3: testGetMissingVariable

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testGetMissingVariable() {
    final WicketTester tester = getTester();

    TestAjaxBehavior behavior = new TestAjaxBehavior("testB");
    Map map = new Map("map");
    map.add(behavior);

    tester.startComponentInPage(map);

    MockHttpServletRequest request = prepareRequest(tester, behavior, "testA", "testA");
    tester.processRequest(request);

    StringValue missingValue = behavior.actualVariableValue;
    assertThat(missingValue.isEmpty()).isTrue();
}
 
开发者ID:DrunkenPandaFans,项目名称:wicket-leaflet,代码行数:17,代码来源:LeafletAjaxBehaviorTest.java


示例4: testRespondToLocationEvent

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testRespondToLocationEvent() {
    WicketTester tester = this.getTester();

    final Map map = new Map("map");
    final TestLocationEventBehavior behavior = new TestLocationEventBehavior();
    map.add(behavior);

    tester.startComponentInPage(map);

    MockHttpServletRequest request = this.prepareRequest(tester, behavior, MapEventType.LOCATION_FOUND, this.locationEvent);
    tester.processRequest(request);

    assertThat(behavior.actualLocationEvent)
            .isNotNull()
            .isEqualToComparingFieldByField(this.locationEvent);
    assertThat(behavior.actualError).isNull();
}
 
开发者ID:DrunkenPandaFans,项目名称:wicket-leaflet,代码行数:19,代码来源:LocationEventBehaviorTest.java


示例5: testRespondToLocationError

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testRespondToLocationError() {
    WicketTester tester = this.getTester();

    final Map map = new Map("map");
    final TestLocationEventBehavior behavior = new TestLocationEventBehavior();
    map.add(behavior);

    tester.startComponentInPage(map);

    MockHttpServletRequest request = this.prepareRequest(tester, behavior, MapEventType.LOCATION_ERROR, this.errorEvent);
    tester.processRequest(request);

    assertThat(behavior.actualError)
            .isNotNull()
            .isEqualToComparingFieldByField(this.errorEvent);
    assertThat(behavior.actualLocationEvent).isNull();
}
 
开发者ID:DrunkenPandaFans,项目名称:wicket-leaflet,代码行数:19,代码来源:LocationEventBehaviorTest.java


示例6: testDontRespondToEmptyErrorEvent

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testDontRespondToEmptyErrorEvent() {
    WicketTester tester = this.getTester();

    final Map map = new Map("map");
    final TestLocationEventBehavior behavior = new TestLocationEventBehavior();
    map.add(behavior);

    tester.startComponentInPage(map);

    MockHttpServletRequest request = this.prepareRequest(tester, behavior, MapEventType.LOCATION_ERROR.getJavascriptName(), "");
    tester.processRequest(request);

    assertThat(behavior.actualError).isNull();
    assertThat(behavior.actualLocationEvent).isNull();
}
 
开发者ID:DrunkenPandaFans,项目名称:wicket-leaflet,代码行数:17,代码来源:LocationEventBehaviorTest.java


示例7: testDontTriggerEventOnMissingJson

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testDontTriggerEventOnMissingJson() {
    final WicketTester tester = this.getTester();

    final TestAjaxEventBehavior behavior = new TestAjaxEventBehavior(MapEventType.CLICK);
    final Map map = new Map("map");
    map.add(behavior);

    tester.startComponentInPage(map);

    final MockHttpServletRequest request = this.prepareRequest(tester, behavior,
            MapEventType.CLICK.getJavascriptName(), "");

    tester.processRequest(request);

    assertThat(behavior.wasTriggered).isFalse();
}
 
开发者ID:DrunkenPandaFans,项目名称:wicket-leaflet,代码行数:18,代码来源:LeafletAjaxEventBehaviorTest.java


示例8: testOnResponseTriggersEvent

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testOnResponseTriggersEvent() {
    final WicketTester tester = this.getTester();

    final TestAjaxEventBehavior behavior = new TestAjaxEventBehavior(MapEventType.CLICK);
    final Map map = new Map("map");
    map.add(behavior);

    tester.startComponentInPage(map);
    final PlainEvent jsonEvent = PlainEvent.of(MapEventType.CLICK);

    final MockHttpServletRequest request = this.prepareRequest(tester, behavior, MapEventType.CLICK, jsonEvent);
    tester.processRequest(request);

    assertThat(behavior.wasTriggered).isTrue();
    assertThat(behavior.lastEvent).isEqualToComparingFieldByField(jsonEvent);
}
 
开发者ID:DrunkenPandaFans,项目名称:wicket-leaflet,代码行数:18,代码来源:LeafletAjaxEventBehaviorTest.java


示例9: prepareRequest

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
/**
    * Prepares request that triggers AJAX behavior and contains parameter with given name and value.
    *
    * @param tester the wicket tester which triggers behavior
    * @param behavior the behavior that should be triggered
    * @param parameterName the name of parameter
    * @param parameterValue the value of parameter
    * @return mock HTTP request that triggers given behavior
    */
   protected MockHttpServletRequest prepareRequest(WicketTester tester, AbstractAjaxBehavior behavior,
           String parameterName, String parameterValue) {
       MockHttpServletRequest request = new MockHttpServletRequest(tester.getApplication(), tester.getHttpSession(), tester.getServletContext());

       Url url = Url.parse(behavior.getCallbackUrl().toString(), Charset.forName(request.getCharacterEncoding()));

       // make url suitable for wicket tester use. usually this involves stripping any leading ..
// segments to make the url absolute
       for (Iterator<String> segments = url.getSegments().iterator(); segments.hasNext();) {
           String segment = segments.next();
           if (segment.equals("..") || segment.equals(".")) {
               segments.remove();
           }
       }

       request.addHeader("Wicket-Ajax", "true");
       request.addHeader("Wicket-Ajax-BaseURL", url.toString());
       request.setUrl(url);

       request.setParameter(parameterName, parameterValue);

       return request;
   }
 
开发者ID:DrunkenPandaFans,项目名称:wicket-leaflet,代码行数:33,代码来源:AbstractLeafletTest.java


示例10: ensureApplication

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
public static IApplication ensureApplication(Long langId) {
	IApplication a = _ensureApplication();
	if (ThreadContext.getRequestCycle() == null) {
		ServletWebRequest req = new ServletWebRequest(new MockHttpServletRequest((Application)a, new MockHttpSession(a.getServletContext()), a.getServletContext()), "");
		RequestCycleContext rctx = new RequestCycleContext(req, new MockWebResponse(), a.getRootRequestMapper(), a.getExceptionMapperProvider().get());
		ThreadContext.setRequestCycle(new RequestCycle(rctx));
	}
	if (ThreadContext.getSession() == null) {
		WebSession s = WebSession.get();
		if (langId > 0) {
			((IWebSession)s).setLanguage(langId);
		}
	}
	return a;
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:16,代码来源:ApplicationHelper.java


示例11: testTriggersSupportedEvents

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testTriggersSupportedEvents() {
    final WicketTester tester = this.getTester();
    Map map = new Map("map");

    ImmutableMap.Builder<MapEventType, TestMouseEventBehavior> behaviors = ImmutableMap.builder();
    for (MapEventType eventType : MouseEventBehavior.SUPPORTED_EVENTS) {
        final MouseEvent expectedEvent = this.prepareMouseEvent(eventType);
        final TestMouseEventBehavior behavior = new TestMouseEventBehavior(eventType, expectedEvent);
        map.add(behavior);

        behaviors.put(eventType, behavior);
    }

    tester.startComponentInPage(map);

    for (java.util.Map.Entry<MapEventType, TestMouseEventBehavior> entry : behaviors.build().entrySet()) {
        MouseEvent expected = this.prepareMouseEvent(entry.getKey());

        MockHttpServletRequest request = this.prepareRequest(tester, entry.getValue(), entry.getKey(), expected);
        tester.processRequest(request);

        assertThat(entry.getValue().actualEvent)
                .as("Event [%s] was not triggered.", entry.getKey())
                .isEqualToComparingFieldByField(expected);
    }
}
 
开发者ID:DrunkenPandaFans,项目名称:wicket-leaflet,代码行数:28,代码来源:MouseEventBehaviorTest.java


示例12: open

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
@Override
public ITearDownHandle open() {
	if (RequestCycle.get() != null) {
		return ExecutionContexts.noOp().open();
	}

	WebApplication application = WebApplication.get();

	final ServletContext context = application.getServletContext();

	final HttpSession newHttpSession = new MockHttpSession(context);
	final MockHttpServletRequest servletRequest = new ContextConfiguredMockHttpServletRequest(application,
			newHttpSession, context);
	final MockHttpServletResponse servletResponse = new MockHttpServletResponse(servletRequest);
	servletRequest.initialize();
	servletResponse.initialize();

	final ServletWebRequest webRequest = new ServletWebRequest(servletRequest, servletRequest.getFilterPrefix());
	final WebResponse webResponse = new BufferedWebResponse(new ServletWebResponse(webRequest, servletResponse));

	RequestCycle requestCycle = application.createRequestCycle(webRequest, webResponse);

	ITearDownHandle handle = new ITearDownHandle() {
		@Override
		public void close() {
			ThreadContext.setSession(null);
			ThreadContext.setRequestCycle(null);
		}
	};
	
	try {
		ThreadContext.setRequestCycle(requestCycle);
		// The session will be set automatically if required
		return handle;
	} catch (RuntimeException e) {
		try {
			handle.close();
		} catch (RuntimeException e2) {
			e.addSuppressed(e2);
		}
		throw e;
	}
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:44,代码来源:WicketContextProviderImpl.java


示例13: executeUrl

import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; //导入依赖的package包/类
public String executeUrl(String _url, final String method, final String content, String username, String password) throws Exception
{
	MockHttpServletRequest request = new MockHttpServletRequest(getApplication(), getHttpSession(), getServletContext())
	{
		{
			setMethod(method);
		}

		@Override
		public ServletInputStream getInputStream() throws IOException {
			if(content==null) return super.getInputStream();
			else
			{
				final StringReader sr = new StringReader(content);
				return new ServletInputStream() {
					@Override
					public int read() throws IOException {
						return sr.read();
					}
				};
			}
		}
	};
	
	Url url = Url.parse(_url, Charset.forName(request.getCharacterEncoding()));
	request.setUrl(url);
	request.setMethod(method);
	if(username!=null && password!=null)
	{
		request.setHeader(LazyAuthorizationRequestCycleListener.AUTHORIZATION_HEADER, "Basic "+Base64.encodeBase64String((username+":"+password).getBytes()));
	}
	if(!processRequest(request))
	{
		throw new IOException("Request was not sucessfully sent");
	}
	MockHttpServletResponse response = getLastResponse();
	int status = response.getStatus();
	if(status>=HttpServletResponse.SC_OK+100)
	{
		throw new IOException("Code: "+response.getStatus()+" Message: "+response.getErrorMessage()+" Content: "+response.getDocument());
	}
	else
	{
		return response.getDocument();
	}
}
 
开发者ID:OrienteerBAP,项目名称:wicket-orientdb,代码行数:47,代码来源:WicketOrientDbTester.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TranslatorFactory类代码示例发布时间:2022-05-22
下一篇:
Java WearableStatusCodes类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap