本文整理汇总了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);
}
示例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");
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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();
}
}