use of com.gargoylesoftware.htmlunit.WebResponse in project spring-framework by spring-projects.
the class DelegatingWebConnectionTests method getResponseSecondMatches.
@Test
public void getResponseSecondMatches() throws Exception {
when(matcher2.matches(request)).thenReturn(true);
when(connection2.getResponse(request)).thenReturn(expectedResponse);
WebResponse response = webConnection.getResponse(request);
assertThat(response, sameInstance(expectedResponse));
verify(matcher1).matches(request);
verify(matcher2).matches(request);
verifyNoMoreInteractions(connection1, defaultConnection);
verify(connection2).getResponse(request);
}
use of com.gargoylesoftware.htmlunit.WebResponse in project spring-framework by spring-projects.
the class MockWebResponseBuilderTests method buildResponseHeadersNullDomainDefaulted.
// SPR-14169
@Test
public void buildResponseHeadersNullDomainDefaulted() throws Exception {
Cookie cookie = new Cookie("cookieA", "valueA");
this.response.addCookie(cookie);
WebResponse webResponse = this.responseBuilder.build();
List<NameValuePair> responseHeaders = webResponse.getResponseHeaders();
assertThat(responseHeaders.size(), equalTo(1));
NameValuePair header = responseHeaders.get(0);
assertThat(header.getName(), equalTo("Set-Cookie"));
assertThat(header.getValue(), equalTo("cookieA=valueA"));
}
use of com.gargoylesoftware.htmlunit.WebResponse in project spring-framework by spring-projects.
the class MockWebResponseBuilderTests method buildStatusNotOk.
@Test
public void buildStatusNotOk() throws Exception {
this.response.setStatus(401);
WebResponse webResponse = this.responseBuilder.build();
assertThat(webResponse.getStatusCode(), equalTo(401));
assertThat(webResponse.getStatusMessage(), equalTo("Unauthorized"));
}
use of com.gargoylesoftware.htmlunit.WebResponse in project spring-framework by spring-projects.
the class MockWebResponseBuilderTests method buildResponseHeaders.
@Test
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(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"));
}
use of com.gargoylesoftware.htmlunit.WebResponse in project javaee7-samples by javaee-samples.
the class LoginServletTest method testAuthenticatedRequest.
@Test
public void testAuthenticatedRequest() throws IOException, SAXException {
WebClient webClient = new WebClient();
WebRequest request = new WebRequest(new URL(base + "/LoginServlet?user=u1&password=p1"), HttpMethod.GET);
WebResponse response = webClient.getWebConnection().getResponse(request);
String responseText = response.getContentAsString();
System.out.println(responseText);
assert (responseText.contains("isUserInRole?true"));
assert (responseText.contains("getRemoteUser?u1"));
assert (responseText.contains("getUserPrincipal?u1"));
assert (responseText.contains("getAuthType?BASIC"));
}
Aggregations