HttpServletRequestMock request = new HttpServletRequestMock(
"test-request", expectationContainer);
String pathInfo = "/" + rule + "/" + fileName;
request.expects.getPathInfo().returns(pathInfo).any();
final MockFactory mf = MockFactory.getDefaultInstance();
// use a vector as we need to return an enumeration for calls to
// getHeaderNames()
final Map params = new HashMap();
request.fuzzy.getParameter(mf.expectsAny()).does(new MethodAction(){
public Object perform(MethodActionEvent event) throws Throwable {
return params.get(event.getArguments()[0]);
}
}).any();
StringBuffer url = new StringBuffer(pathInfo);
char c = '?';
if (parameters != null) {
url.append('/');
for (int i = 0; i < parameters.length; i++) {
if (parameters[i].length != 2) {
throw new IllegalArgumentException(
"Supplied parameter " +
i +
" has incorrect " +
"length: expected 2 got " +
parameters[i].length);
}
url.append(c).append(parameters[i][0]).append("=").append(parameters[i][1]);
c = '&';
params.put(parameters[i][0], parameters[i][1]);
}
}
// Hack to enable gif support without having a config file.
if (enableGif) {
params.put("v.gifEnabled", "true");
url.append(c).append("v.gifEnabled=true");
}
request.expects.getParameterNames().does(new MethodAction() {
public Object perform(MethodActionEvent event) throws Throwable {
return Collections.enumeration(params.keySet());
}
}).any();
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ServletOutputStream os = new ServletOutputStream() {
public void write(int b) {
outputStream.write(b);
}
};
HttpServletResponseMock response = new HttpServletResponseMock(
"test-response", expectationContainer);
response.expects.getOutputStream().returns(os).any();
// content type should only be set once
response.fuzzy.setContentType(mf.expectsAny()).returns().any();
response.fuzzy.setDateHeader(mf.expectsAny(), mf.expectsAny()).returns().any();
response.fuzzy.addDateHeader(mf.expectsAny(), mf.expectsAny()).returns().any();
response.fuzzy.addHeader(mf.expectsAny(), mf.expectsAny()).returns().any();
response.fuzzy.addIntHeader(mf.expectsAny(), mf.expectsAny()).returns().any();
response.fuzzy.setContentLength(mf.expectsAny()).returns().any();
ICSParamBuilder builder = new ICSParamBuilder();
builder.build(new URI(url.toString()),
descriptor.getInputParameters());