16 changed files with 799 additions and 274 deletions
@ -0,0 +1,130 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2002-2013 the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package org.springframework.mock.web; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
import javax.servlet.AsyncContext; |
||||||
|
import javax.servlet.AsyncEvent; |
||||||
|
import javax.servlet.AsyncListener; |
||||||
|
import javax.servlet.ServletContext; |
||||||
|
import javax.servlet.ServletException; |
||||||
|
import javax.servlet.ServletRequest; |
||||||
|
import javax.servlet.ServletResponse; |
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
|
||||||
|
import org.springframework.beans.BeanUtils; |
||||||
|
import org.springframework.web.util.WebUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mock implementation of the {@link AsyncContext} interface. |
||||||
|
* |
||||||
|
* @author Rossen Stoyanchev |
||||||
|
* @since 3.2 |
||||||
|
*/ |
||||||
|
public class MockAsyncContext implements AsyncContext { |
||||||
|
|
||||||
|
private final HttpServletRequest request; |
||||||
|
|
||||||
|
private final HttpServletResponse response; |
||||||
|
|
||||||
|
private final List<AsyncListener> listeners = new ArrayList<AsyncListener>(); |
||||||
|
|
||||||
|
private String dispatchedPath; |
||||||
|
|
||||||
|
private long timeout = 10 * 1000L; // 10 seconds is Tomcat's default
|
||||||
|
|
||||||
|
|
||||||
|
public MockAsyncContext(ServletRequest request, ServletResponse response) { |
||||||
|
this.request = (HttpServletRequest) request; |
||||||
|
this.response = (HttpServletResponse) response; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public ServletRequest getRequest() { |
||||||
|
return this.request; |
||||||
|
} |
||||||
|
|
||||||
|
public ServletResponse getResponse() { |
||||||
|
return this.response; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasOriginalRequestAndResponse() { |
||||||
|
return (this.request instanceof MockHttpServletRequest) && (this.response instanceof MockHttpServletResponse); |
||||||
|
} |
||||||
|
|
||||||
|
public void dispatch() { |
||||||
|
dispatch(this.request.getRequestURI()); |
||||||
|
} |
||||||
|
|
||||||
|
public void dispatch(String path) { |
||||||
|
dispatch(null, path); |
||||||
|
} |
||||||
|
|
||||||
|
public void dispatch(ServletContext context, String path) { |
||||||
|
this.dispatchedPath = path; |
||||||
|
} |
||||||
|
|
||||||
|
public String getDispatchedPath() { |
||||||
|
return this.dispatchedPath; |
||||||
|
} |
||||||
|
|
||||||
|
public void complete() { |
||||||
|
MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(request, MockHttpServletRequest.class); |
||||||
|
if (mockRequest != null) { |
||||||
|
mockRequest.setAsyncStarted(false); |
||||||
|
} |
||||||
|
for (AsyncListener listener : this.listeners) { |
||||||
|
try { |
||||||
|
listener.onComplete(new AsyncEvent(this, this.request, this.response)); |
||||||
|
} |
||||||
|
catch (IOException e) { |
||||||
|
throw new IllegalStateException("AsyncListener failure", e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void start(Runnable runnable) { |
||||||
|
runnable.run(); |
||||||
|
} |
||||||
|
|
||||||
|
public void addListener(AsyncListener listener) { |
||||||
|
this.listeners.add(listener); |
||||||
|
} |
||||||
|
|
||||||
|
public void addListener(AsyncListener listener, ServletRequest request, ServletResponse response) { |
||||||
|
this.listeners.add(listener); |
||||||
|
} |
||||||
|
|
||||||
|
public List<AsyncListener> getListeners() { |
||||||
|
return this.listeners; |
||||||
|
} |
||||||
|
|
||||||
|
public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException { |
||||||
|
return BeanUtils.instantiateClass(clazz); |
||||||
|
} |
||||||
|
|
||||||
|
public void setTimeout(long timeout) { |
||||||
|
this.timeout = timeout; |
||||||
|
} |
||||||
|
|
||||||
|
public long getTimeout() { |
||||||
|
return this.timeout; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,101 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2002-2013 the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.mock.web; |
||||||
|
|
||||||
|
import javax.servlet.SessionCookieConfig; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mock implementation of the {@link javax.servlet.SessionCookieConfig} interface. |
||||||
|
* |
||||||
|
* @author Juergen Hoeller |
||||||
|
* @since 4.0 |
||||||
|
* @see javax.servlet.ServletContext#getSessionCookieConfig() |
||||||
|
*/ |
||||||
|
public class MockSessionCookieConfig implements SessionCookieConfig { |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
private String domain; |
||||||
|
|
||||||
|
private String path; |
||||||
|
|
||||||
|
private String comment; |
||||||
|
|
||||||
|
private boolean httpOnly; |
||||||
|
|
||||||
|
private boolean secure; |
||||||
|
|
||||||
|
private int maxAge; |
||||||
|
|
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return this.name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDomain(String domain) { |
||||||
|
this.domain = domain; |
||||||
|
} |
||||||
|
|
||||||
|
public String getDomain() { |
||||||
|
return this.domain; |
||||||
|
} |
||||||
|
|
||||||
|
public void setPath(String path) { |
||||||
|
this.path = path; |
||||||
|
} |
||||||
|
|
||||||
|
public String getPath() { |
||||||
|
return this.path; |
||||||
|
} |
||||||
|
|
||||||
|
public void setComment(String comment) { |
||||||
|
this.comment = comment; |
||||||
|
} |
||||||
|
|
||||||
|
public String getComment() { |
||||||
|
return this.comment; |
||||||
|
} |
||||||
|
|
||||||
|
public void setHttpOnly(boolean httpOnly) { |
||||||
|
this.httpOnly = httpOnly; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isHttpOnly() { |
||||||
|
return this.httpOnly; |
||||||
|
} |
||||||
|
|
||||||
|
public void setSecure(boolean secure) { |
||||||
|
this.secure = secure; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isSecure() { |
||||||
|
return this.secure; |
||||||
|
} |
||||||
|
|
||||||
|
public void setMaxAge(int maxAge) { |
||||||
|
this.maxAge = maxAge; |
||||||
|
} |
||||||
|
|
||||||
|
public int getMaxAge() { |
||||||
|
return this.maxAge; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,101 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2002-2013 the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.mock.web.test; |
||||||
|
|
||||||
|
import javax.servlet.SessionCookieConfig; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mock implementation of the {@link javax.servlet.SessionCookieConfig} interface. |
||||||
|
* |
||||||
|
* @author Juergen Hoeller |
||||||
|
* @since 4.0 |
||||||
|
* @see javax.servlet.ServletContext#getSessionCookieConfig() |
||||||
|
*/ |
||||||
|
public class MockSessionCookieConfig implements SessionCookieConfig { |
||||||
|
|
||||||
|
private String name; |
||||||
|
|
||||||
|
private String domain; |
||||||
|
|
||||||
|
private String path; |
||||||
|
|
||||||
|
private String comment; |
||||||
|
|
||||||
|
private boolean httpOnly; |
||||||
|
|
||||||
|
private boolean secure; |
||||||
|
|
||||||
|
private int maxAge; |
||||||
|
|
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return this.name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDomain(String domain) { |
||||||
|
this.domain = domain; |
||||||
|
} |
||||||
|
|
||||||
|
public String getDomain() { |
||||||
|
return this.domain; |
||||||
|
} |
||||||
|
|
||||||
|
public void setPath(String path) { |
||||||
|
this.path = path; |
||||||
|
} |
||||||
|
|
||||||
|
public String getPath() { |
||||||
|
return this.path; |
||||||
|
} |
||||||
|
|
||||||
|
public void setComment(String comment) { |
||||||
|
this.comment = comment; |
||||||
|
} |
||||||
|
|
||||||
|
public String getComment() { |
||||||
|
return this.comment; |
||||||
|
} |
||||||
|
|
||||||
|
public void setHttpOnly(boolean httpOnly) { |
||||||
|
this.httpOnly = httpOnly; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isHttpOnly() { |
||||||
|
return this.httpOnly; |
||||||
|
} |
||||||
|
|
||||||
|
public void setSecure(boolean secure) { |
||||||
|
this.secure = secure; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isSecure() { |
||||||
|
return this.secure; |
||||||
|
} |
||||||
|
|
||||||
|
public void setMaxAge(int maxAge) { |
||||||
|
this.maxAge = maxAge; |
||||||
|
} |
||||||
|
|
||||||
|
public int getMaxAge() { |
||||||
|
return this.maxAge; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue