/**
* Copyright 2010 JBoss Inc
*
* 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.drools.guvnor.server.files;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.Principal;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class MockHTTPRequest implements HttpServletRequest {
final private URI uri;
private Map<String, String> headers;
ServletInputStream stream;
String queryString;
Map<String, String> parameters;
public String method;
public StringBuffer url = new StringBuffer("http://foo.com");
public MockHTTPRequest(String uri, Map<String, String> headers) {
try {
this.uri = new URI (uri);
this.headers = headers;
} catch (URISyntaxException e) {
throw new RuntimeException (e);
}
}
public MockHTTPRequest(String uri, Map<String, String> headers, Map<String, String> parameters) {
try {
this.uri = new URI (uri);
this.headers = headers;
this.parameters = parameters;
} catch (URISyntaxException e) {
throw new RuntimeException (e);
}
}
public MockHTTPRequest(String uri, Map<String, String> headers, InputStream in) {
try {
this.uri = new URI (uri);
this.headers = headers;
this.stream = new MockInput(in);
} catch (URISyntaxException e) {
throw new RuntimeException (e);
}
}
public MockHTTPRequest(String uri, Map<String, String> headers,
Map<String,String> parameters, InputStream in)
{
try {
this.uri = new URI (uri);
this.headers = headers;
this.parameters = parameters;
this.stream = new MockInput(in);
} catch (URISyntaxException e) {
throw new RuntimeException (e);
}
}
public String getAuthType() {
// TODO Auto-generated method stub
return null;
}
public String getContextPath() {
return uri.getPath();
}
public Cookie[] getCookies() {
// TODO Auto-generated method stub
return null;
}
public long getDateHeader(String arg0) {
// TODO Auto-generated method stub
return 0;
}
public String getHeader(String n) {
return headers.get(n);
}
public Enumeration getHeaderNames() {
// TODO Auto-generated method stub
return null;
}
public Enumeration getHeaders(String arg0) {
// TODO Auto-generated method stub
return null;
}
public int getIntHeader(String arg0) {
// TODO Auto-generated method stub
return 0;
}
public String getMethod() {
return method;
}
public String getPathInfo() {
// TODO Auto-generated method stub
return null;
}
public String getPathTranslated() {
return uri.getPath();
}
public String getQueryString() {
return queryString;
}
public String getRemoteUser() {
// TODO Auto-generated method stub
return null;
}
public String getRequestURI() {
return uri.toString();
}
public StringBuffer getRequestURL() {
return url;
}
public String getRequestedSessionId() {
// TODO Auto-generated method stub
return null;
}
public String getServletPath() {
// TODO Auto-generated method stub
return null;
}
public HttpSession getSession() {
// TODO Auto-generated method stub
return null;
}
public HttpSession getSession(boolean arg0) {
// TODO Auto-generated method stub
return null;
}
public Principal getUserPrincipal() {
// TODO Auto-generated method stub
return null;
}
public boolean isRequestedSessionIdFromCookie() {
// TODO Auto-generated method stub
return false;
}
public boolean isRequestedSessionIdFromURL() {
// TODO Auto-generated method stub
return false;
}
public boolean isRequestedSessionIdFromUrl() {
// TODO Auto-generated method stub
return false;
}
public boolean isRequestedSessionIdValid() {
// TODO Auto-generated method stub
return false;
}
public boolean isUserInRole(String arg0) {
// TODO Auto-generated method stub
return false;
}
public Object getAttribute(String arg0) {
// TODO Auto-generated method stub
return null;
}
public Enumeration getAttributeNames() {
// TODO Auto-generated method stub
return null;
}
public String getCharacterEncoding() {
// TODO Auto-generated method stub
return null;
}
public int getContentLength() {
// TODO Auto-generated method stub
return 0;
}
public String getContentType() {
// TODO Auto-generated method stub
return null;
}
public ServletInputStream getInputStream() throws IOException {
return stream ;
}
public Locale getLocale() {
// TODO Auto-generated method stub
return null;
}
public Enumeration getLocales() {
// TODO Auto-generated method stub
return null;
}
public String getParameter(String arg0) {
return parameters.get(arg0);
}
public Map getParameterMap() {
return parameters;
}
public Enumeration getParameterNames() {
// TODO Auto-generated method stub
return null;
}
public String[] getParameterValues(String arg0) {
// TODO Auto-generated method stub
return null;
}
public String getProtocol() {
// TODO Auto-generated method stub
return null;
}
public BufferedReader getReader() throws IOException {
// TODO Auto-generated method stub
return null;
}
public String getRealPath(String arg0) {
// TODO Auto-generated method stub
return null;
}
public int getRemotePort() {
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
public String getLocalName() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public String getLocalAddr() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public int getLocalPort() {
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
public String getRemoteAddr() {
// TODO Auto-generated method stub
return null;
}
public String getRemoteHost() {
// TODO Auto-generated method stub
return null;
}
public RequestDispatcher getRequestDispatcher(String arg0) {
// TODO Auto-generated method stub
return null;
}
public String getScheme() {
// TODO Auto-generated method stub
return null;
}
public String getServerName() {
// TODO Auto-generated method stub
return null;
}
public int getServerPort() {
// TODO Auto-generated method stub
return 0;
}
public boolean isSecure() {
// TODO Auto-generated method stub
return false;
}
public void removeAttribute(String arg0) {
// TODO Auto-generated method stub
}
public void setAttribute(String arg0, Object arg1) {
// TODO Auto-generated method stub
}
public void setCharacterEncoding(String arg0)
throws UnsupportedEncodingException {
// TODO Auto-generated method stub
}
static class MockInput extends ServletInputStream {
private InputStream stream;
MockInput(InputStream in) {
this.stream = in;
}
public int read() throws IOException {
// TODO Auto-generated method stub
return stream.read();
}
}
}