Support response cookies in HtmlUnit integration
Issue: SPR-14051
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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
|
||||
@@ -19,6 +19,8 @@ package org.springframework.test.web.servlet.htmlunit;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
@@ -27,7 +29,9 @@ import com.gargoylesoftware.htmlunit.WebRequest;
|
||||
import com.gargoylesoftware.htmlunit.WebResponse;
|
||||
import com.gargoylesoftware.htmlunit.util.NameValuePair;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.endsWith;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
@@ -94,16 +98,27 @@ public class MockWebResponseBuilderTests {
|
||||
public void buildResponseHeaders() throws Exception {
|
||||
this.response.addHeader("Content-Type", "text/html");
|
||||
this.response.addHeader("X-Test", "value");
|
||||
Cookie cookie = new Cookie("cookieA", "valueA");
|
||||
cookie.setDomain("domain");
|
||||
cookie.setPath("/path");
|
||||
cookie.setMaxAge(1800);
|
||||
cookie.setSecure(true);
|
||||
cookie.setHttpOnly(true);
|
||||
this.response.addCookie(cookie);
|
||||
WebResponse webResponse = this.responseBuilder.build();
|
||||
|
||||
List<NameValuePair> responseHeaders = webResponse.getResponseHeaders();
|
||||
assertThat(responseHeaders.size(), equalTo(2));
|
||||
assertThat(responseHeaders.size(), equalTo(3));
|
||||
NameValuePair header = responseHeaders.get(0);
|
||||
assertThat(header.getName(), equalTo("Content-Type"));
|
||||
assertThat(header.getValue(), equalTo("text/html"));
|
||||
header = responseHeaders.get(1);
|
||||
assertThat(header.getName(), equalTo("X-Test"));
|
||||
assertThat(header.getValue(), equalTo("value"));
|
||||
header = responseHeaders.get(2);
|
||||
assertThat(header.getName(), equalTo("Set-Cookie"));
|
||||
assertThat(header.getValue(), startsWith("cookieA=valueA;domain=domain;path=/path;expires="));
|
||||
assertThat(header.getValue(), endsWith(";secure;httpOnly"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user