|
1 | 1 | /* |
2 | | - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
5 | 5 | * use this file except in compliance with the License. You may obtain a copy of |
|
19 | 19 | import java.net.URL; |
20 | 20 | import java.util.List; |
21 | 21 |
|
| 22 | +import javax.servlet.http.Cookie; |
| 23 | + |
22 | 24 | import org.junit.Before; |
23 | 25 | import org.junit.Test; |
24 | 26 | import org.springframework.mock.web.MockHttpServletResponse; |
|
27 | 29 | import com.gargoylesoftware.htmlunit.WebResponse; |
28 | 30 | import com.gargoylesoftware.htmlunit.util.NameValuePair; |
29 | 31 |
|
| 32 | +import static org.hamcrest.CoreMatchers.endsWith; |
30 | 33 | import static org.hamcrest.CoreMatchers.equalTo; |
| 34 | +import static org.hamcrest.CoreMatchers.startsWith; |
31 | 35 | import static org.junit.Assert.assertThat; |
32 | 36 |
|
33 | 37 | /** |
@@ -94,16 +98,27 @@ public void buildContentType() throws Exception { |
94 | 98 | public void buildResponseHeaders() throws Exception { |
95 | 99 | this.response.addHeader("Content-Type", "text/html"); |
96 | 100 | this.response.addHeader("X-Test", "value"); |
| 101 | + Cookie cookie = new Cookie("cookieA", "valueA"); |
| 102 | + cookie.setDomain("domain"); |
| 103 | + cookie.setPath("/path"); |
| 104 | + cookie.setMaxAge(1800); |
| 105 | + cookie.setSecure(true); |
| 106 | + cookie.setHttpOnly(true); |
| 107 | + this.response.addCookie(cookie); |
97 | 108 | WebResponse webResponse = this.responseBuilder.build(); |
98 | 109 |
|
99 | 110 | List<NameValuePair> responseHeaders = webResponse.getResponseHeaders(); |
100 | | - assertThat(responseHeaders.size(), equalTo(2)); |
| 111 | + assertThat(responseHeaders.size(), equalTo(3)); |
101 | 112 | NameValuePair header = responseHeaders.get(0); |
102 | 113 | assertThat(header.getName(), equalTo("Content-Type")); |
103 | 114 | assertThat(header.getValue(), equalTo("text/html")); |
104 | 115 | header = responseHeaders.get(1); |
105 | 116 | assertThat(header.getName(), equalTo("X-Test")); |
106 | 117 | assertThat(header.getValue(), equalTo("value")); |
| 118 | + header = responseHeaders.get(2); |
| 119 | + assertThat(header.getName(), equalTo("Set-Cookie")); |
| 120 | + assertThat(header.getValue(), startsWith("cookieA=valueA;domain=domain;path=/path;expires=")); |
| 121 | + assertThat(header.getValue(), endsWith(";secure;httpOnly")); |
107 | 122 | } |
108 | 123 |
|
109 | 124 | @Test |
|
0 commit comments