Polishing
This commit is contained in:
parent
e58b17a3a1
commit
98dbc17591
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -56,6 +56,13 @@ import static org.mockito.Mockito.*;
|
|||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DelegatingWebConnectionTests {
|
||||
|
||||
private DelegatingWebConnection webConnection;
|
||||
|
||||
private WebRequest request;
|
||||
|
||||
private WebResponse expectedResponse;
|
||||
|
||||
|
||||
@Mock
|
||||
private WebRequestMatcher matcher1;
|
||||
|
||||
|
|
@ -72,15 +79,8 @@ public class DelegatingWebConnectionTests {
|
|||
private WebConnection connection2;
|
||||
|
||||
|
||||
private DelegatingWebConnection webConnection;
|
||||
|
||||
private WebRequest request;
|
||||
|
||||
private WebResponse expectedResponse;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setup() throws Exception {
|
||||
request = new WebRequest(new URL("http://localhost/"));
|
||||
WebResponseData data = new WebResponseData("".getBytes("UTF-8"), 200, "", Collections.<NameValuePair> emptyList());
|
||||
expectedResponse = new WebResponse(data, request, 100L);
|
||||
|
|
@ -88,6 +88,7 @@ public class DelegatingWebConnectionTests {
|
|||
new DelegateWebConnection(matcher1, connection1), new DelegateWebConnection(matcher2, connection2));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getResponseDefault() throws Exception {
|
||||
when(defaultConnection.getResponse(request)).thenReturn(expectedResponse);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -28,9 +28,12 @@ import javax.servlet.http.Cookie;
|
|||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.FormEncodingType;
|
||||
import com.gargoylesoftware.htmlunit.HttpMethod;
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.WebRequest;
|
||||
import com.gargoylesoftware.htmlunit.util.NameValuePair;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -41,15 +44,10 @@ import org.springframework.test.util.ReflectionTestUtils;
|
|||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.HttpMethod;
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.WebRequest;
|
||||
import com.gargoylesoftware.htmlunit.util.NameValuePair;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Arrays.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link HtmlUnitRequestBuilder}.
|
||||
|
|
@ -72,12 +70,13 @@ public class HtmlUnitRequestBuilderTests {
|
|||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setup() throws Exception {
|
||||
webRequest = new WebRequest(new URL("http://example.com:80/test/this/here"));
|
||||
webRequest.setHttpMethod(HttpMethod.GET);
|
||||
requestBuilder = new HtmlUnitRequestBuilder(sessions, webClient, webRequest);
|
||||
}
|
||||
|
||||
|
||||
// --- constructor
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
|
@ -95,6 +94,7 @@ public class HtmlUnitRequestBuilderTests {
|
|||
new HtmlUnitRequestBuilder(sessions, webClient, null);
|
||||
}
|
||||
|
||||
|
||||
// --- buildRequest
|
||||
|
||||
@Test
|
||||
|
|
@ -151,7 +151,7 @@ public class HtmlUnitRequestBuilderTests {
|
|||
assertThat(actualRequest.getHeader("Content-Type"), equalTo(contentType));
|
||||
}
|
||||
|
||||
@Test // SPR-14916
|
||||
@Test // SPR-14916
|
||||
public void buildRequestContentTypeWithFormSubmission() {
|
||||
webRequest.setEncodingType(FormEncodingType.URL_ENCODED);
|
||||
|
||||
|
|
@ -251,6 +251,7 @@ public class HtmlUnitRequestBuilderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void buildRequestInputStream() throws Exception {
|
||||
String content = "some content that has length";
|
||||
webRequest.setHttpMethod(HttpMethod.POST);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -47,7 +47,7 @@ public class MockWebResponseBuilderTests {
|
|||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setup() throws Exception {
|
||||
this.webRequest = new WebRequest(new URL("http://example.com:80/test/this/here"));
|
||||
this.responseBuilder = new MockWebResponseBuilder(System.currentTimeMillis(), this.webRequest, this.response);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -35,6 +35,8 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
|
@ -67,10 +69,10 @@ public class RestTemplateIntegrationTests extends AbstractMockWebServerTestCase
|
|||
|
||||
private RestTemplate template;
|
||||
|
||||
@Parameterized.Parameter
|
||||
@Parameter
|
||||
public ClientHttpRequestFactory clientHttpRequestFactory;
|
||||
|
||||
@Parameterized.Parameters
|
||||
@Parameters
|
||||
public static Iterable<? extends ClientHttpRequestFactory> data() {
|
||||
return Arrays.asList(
|
||||
new SimpleClientHttpRequestFactory(),
|
||||
|
|
@ -81,11 +83,13 @@ public class RestTemplateIntegrationTests extends AbstractMockWebServerTestCase
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setUpClient() {
|
||||
public void setupClient() {
|
||||
this.template = new RestTemplate(this.clientHttpRequestFactory);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getString() {
|
||||
String s = template.getForObject(baseUrl + "/{method}", String.class, "get");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -69,7 +69,7 @@ public class RestTemplateTests {
|
|||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
public void setup() {
|
||||
requestFactory = mock(ClientHttpRequestFactory.class);
|
||||
request = mock(ClientHttpRequest.class);
|
||||
response = mock(ClientHttpResponse.class);
|
||||
|
|
@ -146,6 +146,21 @@ public class RestTemplateTests {
|
|||
verify(response).close();
|
||||
}
|
||||
|
||||
@Test // SPR-15201
|
||||
public void uriTemplateWithTrailingSlash() throws Exception {
|
||||
String url = "http://example.com/spring/";
|
||||
given(requestFactory.createRequest(new URI(url), HttpMethod.GET)).willReturn(request);
|
||||
given(request.execute()).willReturn(response);
|
||||
given(errorHandler.hasError(response)).willReturn(false);
|
||||
HttpStatus status = HttpStatus.OK;
|
||||
given(response.getStatusCode()).willReturn(status);
|
||||
given(response.getStatusText()).willReturn(status.getReasonPhrase());
|
||||
|
||||
template.execute(url, HttpMethod.GET, null, null);
|
||||
|
||||
verify(response).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorHandling() throws Exception {
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.GET)).willReturn(request);
|
||||
|
|
@ -265,7 +280,6 @@ public class RestTemplateTests {
|
|||
|
||||
@Test
|
||||
public void getForObjectWithCustomUriTemplateHandler() throws Exception {
|
||||
|
||||
DefaultUriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler();
|
||||
uriTemplateHandler.setParsePath(true);
|
||||
template.setUriTemplateHandler(uriTemplateHandler);
|
||||
|
|
@ -292,7 +306,6 @@ public class RestTemplateTests {
|
|||
verify(response).close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void headForHeaders() throws Exception {
|
||||
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.HEAD)).willReturn(request);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -213,19 +213,19 @@ public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
|
|||
this.id = ObjectUtils.getIdentityHexString(getNativeSession());
|
||||
this.uri = session.getUpgradeRequest().getRequestURI();
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
this.headers.putAll(session.getUpgradeRequest().getHeaders());
|
||||
this.headers = HttpHeaders.readOnlyHttpHeaders(this.headers);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.putAll(session.getUpgradeRequest().getHeaders());
|
||||
this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
|
||||
|
||||
this.acceptedProtocol = session.getUpgradeResponse().getAcceptedSubProtocol();
|
||||
|
||||
List<ExtensionConfig> jettyExtensions = session.getUpgradeResponse().getExtensions();
|
||||
if (!CollectionUtils.isEmpty(jettyExtensions)) {
|
||||
this.extensions = new ArrayList<WebSocketExtension>(jettyExtensions.size());
|
||||
List<WebSocketExtension> extensions = new ArrayList<WebSocketExtension>(jettyExtensions.size());
|
||||
for (ExtensionConfig jettyExtension : jettyExtensions) {
|
||||
this.extensions.add(new WebSocketExtension(jettyExtension.getName(), jettyExtension.getParameters()));
|
||||
extensions.add(new WebSocketExtension(jettyExtension.getName(), jettyExtension.getParameters()));
|
||||
}
|
||||
this.extensions = Collections.unmodifiableList(this.extensions);
|
||||
this.extensions = Collections.unmodifiableList(extensions);
|
||||
}
|
||||
else {
|
||||
this.extensions = Collections.emptyList();
|
||||
|
|
@ -244,19 +244,19 @@ public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
|
|||
this.id = ObjectUtils.getIdentityHexString(getNativeSession());
|
||||
this.uri = (URI) ReflectionUtils.invokeMethod(getRequestURI, request);
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
this.headers.putAll((Map<String, List<String>>) ReflectionUtils.invokeMethod(getHeaders, request));
|
||||
this.headers = HttpHeaders.readOnlyHttpHeaders(this.headers);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.putAll((Map<String, List<String>>) ReflectionUtils.invokeMethod(getHeaders, request));
|
||||
this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
|
||||
|
||||
this.acceptedProtocol = (String) ReflectionUtils.invokeMethod(getAcceptedSubProtocol, response);
|
||||
|
||||
List<ExtensionConfig> extensions = (List<ExtensionConfig>) ReflectionUtils.invokeMethod(getExtensions, response);
|
||||
if (!CollectionUtils.isEmpty(extensions)) {
|
||||
this.extensions = new ArrayList<WebSocketExtension>(extensions.size());
|
||||
for (ExtensionConfig extension : extensions) {
|
||||
this.extensions.add(new WebSocketExtension(extension.getName(), extension.getParameters()));
|
||||
List<ExtensionConfig> jettyExtensions = (List<ExtensionConfig>) ReflectionUtils.invokeMethod(getExtensions, response);
|
||||
if (!CollectionUtils.isEmpty(jettyExtensions)) {
|
||||
List<WebSocketExtension> extensions = new ArrayList<WebSocketExtension>(jettyExtensions.size());
|
||||
for (ExtensionConfig jettyExtension : jettyExtensions) {
|
||||
extensions.add(new WebSocketExtension(jettyExtension.getName(), jettyExtension.getParameters()));
|
||||
}
|
||||
this.extensions = Collections.unmodifiableList(this.extensions);
|
||||
this.extensions = Collections.unmodifiableList(extensions);
|
||||
}
|
||||
else {
|
||||
this.extensions = Collections.emptyList();
|
||||
|
|
|
|||
Loading…
Reference in New Issue