WebDriverAccessor accessor = createWebDriverAccessor(request, response);
container.setProperty(WebDriverAccessor.class, accessor, false);
String cookieName = "Set-Cookie";
String cookieValue = "name1=value1";
final Cookie cookie1 = new CookieImpl(cookieName, "localhost", "/");
cookie1.setValue(cookieValue);
String headerName = "Other-Header";
String headerValue = "o-h-value";
final Header otherHeader = new HeaderImpl(headerName);
otherHeader.setValue(headerValue);
HTTPMessageEntities additionalCookies = new SimpleHTTPMessageEntities();
Cookie additionalCookie = new CookieImpl("additionalName",
"localhost",
"/");
additionalCookie.setValue("additionalValue");
additionalCookies.add(additionalCookie);
String method = "populateWebDriverResponse";
Class paramTypes [] = {
WebDriverResponse.class,
HTTPResponseAccessor.class,
HTTPMessageEntities.class};
Object[] args = {
response,
new HTTPResponseAccessor() {
public HTTPMessageEntities getCookies() {
HTTPMessageEntities cookies =
new SimpleHTTPMessageEntities();
cookies.add(cookie1);
return cookies;
}
public HTTPMessageEntities getHeaders() {
HTTPMessageEntities headers =
new SimpleHTTPMessageEntities();
headers.add(otherHeader);
return headers;
}
public InputStream getResponseStream() {
return null;
}
public int getStatusCode() {
return 200;
}
/**
* Get the HTTP version returned by the server.
* @return The HTTP version returned by the server.
*/
public HTTPVersion getHTTPVersion() {
return HTTPVersion.HTTP_1_1;
}
},
additionalCookies
};
PrivateAccessor.invoke(manager, method, paramTypes, args);
HTTPMessageEntities responseHeaders = response.getHeaders();
HTTPMessageEntities responseCookies = response.getCookies();
final int expectedCookies = 2;
assertEquals("Expected one header.", 1, responseHeaders.size());
assertEquals("Expected number of cookies to match", expectedCookies,
responseCookies.size());
Iterator headers = responseHeaders.iterator();
while (headers.hasNext()) {
HeaderImpl header = (HeaderImpl) headers.next();
assertEquals("Unexpected header name.",
headerName, header.getName());
assertEquals("Unexpected header value.",
headerValue, header.getValue());
}
CookieImpl[] cookies = new CookieImpl[expectedCookies];
int count = 0;
Iterator cookiesIterator = responseCookies.iterator();
while (cookiesIterator.hasNext()) {
CookieImpl cookie = (CookieImpl) cookiesIterator.next();
cookies[count] = cookie;
count++;
}
assertEquals("Checking cookie 1 name",