Skip to content

Commit 5dc9c4c

Browse files
committed
URL Cleanup - Fix broken tests
See gh-22680
1 parent 3db08c6 commit 5dc9c4c

File tree

21 files changed

+84
-80
lines changed

21 files changed

+84
-80
lines changed

spring-messaging/src/test/java/org/springframework/messaging/simp/SimpMessagingTemplateTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,7 +83,7 @@ public void convertAndSendToUserWithEncoding() {
8383
MessageHeaderAccessor.getAccessor(messages.get(0), SimpMessageHeaderAccessor.class);
8484

8585
assertNotNull(headerAccessor);
86-
assertEquals("/user/http:%2F%2Fjoe.openid.example.org%2F/queue/foo", headerAccessor.getDestination());
86+
assertEquals("/user/https:%2F%2Fjoe.openid.example.org%2F/queue/foo", headerAccessor.getDestination());
8787
}
8888

8989
@Test

spring-oxm/src/test/java/org/springframework/oxm/AbstractMarshallerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,7 +74,7 @@ public void marshalDOMResult() throws Exception {
7474
marshaller.marshal(flights, domResult);
7575
Document expected = builder.newDocument();
7676
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
77-
Attr namespace = expected.createAttributeNS("https://www.w3.org/2000/xmlns/", "xmlns:tns");
77+
Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
7878
namespace.setNodeValue("http://samples.springframework.org/flight");
7979
flightsElement.setAttributeNode(namespace);
8080
expected.appendChild(flightsElement);
@@ -98,7 +98,7 @@ public void marshalEmptyDOMResult() throws Exception {
9898
Document result = (Document) domResult.getNode();
9999
Document expected = builder.newDocument();
100100
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
101-
Attr namespace = expected.createAttributeNS("https://www.w3.org/2000/xmlns/", "xmlns:tns");
101+
Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
102102
namespace.setNodeValue("http://samples.springframework.org/flight");
103103
flightsElement.setAttributeNode(namespace);
104104
expected.appendChild(flightsElement);

spring-oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
7676
*/
7777
private static final String XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
7878
"<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
79-
" xmlns:java=\"https://java.sun.com\"" +
79+
" xmlns:java=\"http://java.sun.com\"" +
8080
" xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
8181
"<name>test</name><value>8</value></castor-object></objects>";
8282

@@ -91,7 +91,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
9191
*/
9292
private static final String ROOT_WITH_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
9393
"<objects xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
94-
" xmlns:java=\"https://java.sun.com\"" +
94+
" xmlns:java=\"http://java.sun.com\"" +
9595
" xsi:type=\"java:java.util.Arrays$ArrayList\">" +
9696
"<castor-object xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
9797
"<name>test</name><value>8</value></castor-object></objects>";
@@ -101,7 +101,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
101101
*/
102102
private static final String ROOT_WITHOUT_XSI_EXPECTED_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
103103
"<objects><castor-object xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
104-
" xmlns:java=\"https://java.sun.com\"" +
104+
" xmlns:java=\"http://java.sun.com\"" +
105105
" xsi:type=\"java:org.springframework.oxm.castor.CastorObject\">" +
106106
"<name>test</name><value>8</value></castor-object></objects>";
107107

spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,9 +91,9 @@ public void marshalAttachments() throws Exception {
9191
given(mimeContainer.getAttachment("<99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws>")).willReturn(dataHandler);
9292
given(mimeContainer.getAttachment("[email protected]")).willReturn(dataHandler);
9393
String content = "<binaryObject xmlns='http://springframework.org/spring-ws'>" + "<bytes>" +
94-
"<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='https://www.w3.org/2004/08/xop/include'/>" +
94+
"<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
9595
"</bytes>" + "<dataHandler>" +
96-
"<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='https://www.w3.org/2004/08/xop/include'/>" +
96+
"<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" +
9797
"</dataHandler>" +
9898
"<swaDataHandler>[email protected]</swaDataHandler>" +
9999
"</binaryObject>";

spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ public void buildRequestRemotePort8080() throws Exception {
618618

619619
@Test
620620
public void buildRequestRemotePort80WithDefault() throws Exception {
621-
webRequest.setUrl(new URL("https://example.com/"));
621+
webRequest.setUrl(new URL("http://example.com/"));
622622

623623
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
624624

@@ -650,7 +650,7 @@ public void buildRequestUri() {
650650
@Test
651651
public void buildRequestUrl() {
652652
String uri = requestBuilder.buildRequest(servletContext).getRequestURL().toString();
653-
assertThat(uri, equalTo("https://example.com/test/this/here"));
653+
assertThat(uri, equalTo("http://example.com/test/this/here"));
654654
}
655655

656656
@Test

spring-web/src/test/java/org/springframework/http/RequestEntityTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void uriVariablesExpansion() throws URISyntaxException {
6161
URI uri = new UriTemplate("https://example.com/{foo}").expand("bar");
6262
RequestEntity.get(uri).accept(MediaType.TEXT_PLAIN).build();
6363

64-
String url = "http://www.{host}.com/{path}";
64+
String url = "https://www.{host}.com/{path}";
6565
String host = "example";
6666
String path = "foo/bar";
6767
URI expected = new URI("https://www.example.com/foo/bar");

spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,6 +60,7 @@ public void getMethod() {
6060
@Test
6161
public void getUriForSimplePath() throws URISyntaxException {
6262
URI uri = new URI("https://example.com/path");
63+
mockRequest.setScheme(uri.getScheme());
6364
mockRequest.setServerName(uri.getHost());
6465
mockRequest.setServerPort(uri.getPort());
6566
mockRequest.setRequestURI(uri.getPath());
@@ -70,6 +71,7 @@ public void getUriForSimplePath() throws URISyntaxException {
7071
@Test
7172
public void getUriWithQueryString() throws URISyntaxException {
7273
URI uri = new URI("https://example.com/path?query");
74+
mockRequest.setScheme(uri.getScheme());
7375
mockRequest.setServerName(uri.getHost());
7476
mockRequest.setServerPort(uri.getPort());
7577
mockRequest.setRequestURI(uri.getPath());
@@ -82,15 +84,15 @@ public void getUriWithQueryParam() throws URISyntaxException {
8284
mockRequest.setServerName("example.com");
8385
mockRequest.setRequestURI("/path");
8486
mockRequest.setQueryString("query=foo");
85-
assertEquals(new URI("https://example.com/path?query=foo"), request.getURI());
87+
assertEquals(new URI("http://example.com/path?query=foo"), request.getURI());
8688
}
8789

8890
@Test // SPR-16414
8991
public void getUriWithMalformedQueryParam() throws URISyntaxException {
9092
mockRequest.setServerName("example.com");
9193
mockRequest.setRequestURI("/path");
9294
mockRequest.setQueryString("query=foo%%x");
93-
assertEquals(new URI("https://example.com/path"), request.getURI());
95+
assertEquals(new URI("http://example.com/path"), request.getURI());
9496
}
9597

9698
@Test // SPR-13876

spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -96,16 +96,16 @@ public void mutateRequest() throws Exception {
9696
request = createHttpRequest("/").mutate().method(HttpMethod.DELETE).build();
9797
assertEquals(HttpMethod.DELETE, request.getMethod());
9898

99-
String baseUri = "https://www.aaa.org/articles/";
99+
String baseUri = "http://www.aaa.org/articles/";
100100

101-
request = createHttpRequest(baseUri).mutate().uri(URI.create("https://bbb.org:9090/b")).build();
102-
assertEquals("https://bbb.org:9090/b", request.getURI().toString());
101+
request = createHttpRequest(baseUri).mutate().uri(URI.create("http://bbb.org:9090/b")).build();
102+
assertEquals("http://bbb.org:9090/b", request.getURI().toString());
103103

104104
request = createHttpRequest(baseUri).mutate().path("/b/c/d").build();
105-
assertEquals("https://www.aaa.org/b/c/d", request.getURI().toString());
105+
assertEquals("http://www.aaa.org/b/c/d", request.getURI().toString());
106106

107107
request = createHttpRequest(baseUri).mutate().path("/app/b/c/d").contextPath("/app").build();
108-
assertEquals("https://www.aaa.org/app/b/c/d", request.getURI().toString());
108+
assertEquals("http://www.aaa.org/app/b/c/d", request.getURI().toString());
109109
assertEquals("/app", request.getPath().contextPath().value());
110110
}
111111

spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ public void ioException() throws Exception {
562562
public void ioExceptionWithEmptyQueryString() throws Exception {
563563

564564
// https://example.com/resource?
565-
URI uri = new URI("http", "example.com", "/resource", "", null);
565+
URI uri = new URI("https", "example.com", "/resource", "", null);
566566

567567
given(converter.canRead(String.class, null)).willReturn(true);
568568
given(converter.getSupportedMediaTypes()).willReturn(Collections.singletonList(parseMediaType("foo/bar")));

spring-web/src/test/java/org/springframework/web/cors/reactive/CorsUtilsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -95,7 +95,7 @@ public void isSameOriginWithForwardedHeader() {
9595
@Test // SPR-16362
9696
public void isSameOriginWithDifferentSchemes() {
9797
MockServerHttpRequest request = MockServerHttpRequest
98-
.get("https://mydomain1.com")
98+
.get("http://mydomain1.com")
9999
.header(HttpHeaders.ORIGIN, "https://mydomain1.com")
100100
.build();
101101
assertFalse(CorsUtils.isSameOrigin(request));

spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,6 +57,7 @@ public void getURI() throws Exception {
5757
ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");
5858

5959
URI uri = new URI("https://example.com/path?query");
60+
this.mockRequest.setScheme("https");
6061
this.mockRequest.setServerName(uri.getHost());
6162
this.mockRequest.setServerPort(uri.getPort());
6263
this.mockRequest.setRequestURI(uri.getPath());

spring-web/src/test/java/org/springframework/web/util/DefaultUriBuilderFactoryTests.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.web.util;
1718

1819
import java.net.URI;
@@ -48,48 +49,48 @@ public void defaultSettingsWithBuilder() {
4849

4950
@Test
5051
public void baseUri() {
51-
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://www.foo.com/v1?id=123");
52+
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://example.com/v1?id=123");
5253
URI uri = factory.uriString("/bar").port(8080).build();
53-
assertEquals("https://foo.com:8080/v1/bar?id=123", uri.toString());
54+
assertEquals("http://example.com:8080/v1/bar?id=123", uri.toString());
5455
}
5556

5657
@Test
5758
public void baseUriWithFullOverride() {
58-
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://www.foo.com/v1?id=123");
59+
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://example.com/v1?id=123");
5960
URI uri = factory.uriString("https://example.com/1/2").build();
6061
assertEquals("Use of host should case baseUri to be completely ignored",
6162
"https://example.com/1/2", uri.toString());
6263
}
6364

6465
@Test
6566
public void baseUriWithPathOverride() {
66-
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://www.foo.com/v1");
67+
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://example.com/v1");
6768
URI uri = factory.builder().replacePath("/baz").build();
68-
assertEquals("http://www.foo.com/baz", uri.toString());
69+
assertEquals("http://example.com/baz", uri.toString());
6970
}
7071

7172
@Test
7273
public void defaultUriVars() {
7374
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://{host}/v1");
74-
factory.setDefaultUriVariables(singletonMap("host", "foo.com"));
75+
factory.setDefaultUriVariables(singletonMap("host", "example.com"));
7576
URI uri = factory.uriString("/{id}").build(singletonMap("id", "123"));
76-
assertEquals("http://www.foo.com/v1/123", uri.toString());
77+
assertEquals("http://example.com/v1/123", uri.toString());
7778
}
7879

7980
@Test
8081
public void defaultUriVarsWithOverride() {
8182
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://{host}/v1");
8283
factory.setDefaultUriVariables(singletonMap("host", "spring.io"));
8384
URI uri = factory.uriString("/bar").build(singletonMap("host", "docs.spring.io"));
84-
assertEquals("https://docs.spring.io/v1/bar", uri.toString());
85+
assertEquals("http://docs.spring.io/v1/bar", uri.toString());
8586
}
8687

8788
@Test
8889
public void defaultUriVarsWithEmptyVarArg() {
8990
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory("http://{host}/v1");
90-
factory.setDefaultUriVariables(singletonMap("host", "foo.com"));
91+
factory.setDefaultUriVariables(singletonMap("host", "example.com"));
9192
URI uri = factory.uriString("/bar").build();
92-
assertEquals("Expected delegation to build(Map) method", "http://www.foo.com/v1/bar", uri.toString());
93+
assertEquals("Expected delegation to build(Map) method", "http://example.com/v1/bar", uri.toString());
9394
}
9495

9596
@Test
@@ -137,10 +138,10 @@ public void encodingValuesOnly() {
137138
public void encodingValuesOnlySpr14147() {
138139
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
139140
factory.setEncodingMode(EncodingMode.VALUES_ONLY);
140-
factory.setDefaultUriVariables(singletonMap("host", "www.example.com"));
141+
factory.setDefaultUriVariables(singletonMap("host", "example.com"));
141142
UriBuilder uriBuilder = factory.uriString("http://{host}/user/{userId}/dashboard");
142143

143-
assertEquals("https://www.example.com/user/john%3Bdoe/dashboard",
144+
assertEquals("http://example.com/user/john%3Bdoe/dashboard",
144145
uriBuilder.build(singletonMap("userId", "john;doe")).toString());
145146
}
146147

spring-web/src/test/java/org/springframework/web/util/DefaultUriTemplateHandlerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -142,7 +142,7 @@ public void strictEncodingAndDefaultUriVariables() throws Exception {
142142
Map<String, Object> vars = new HashMap<>(1);
143143
vars.put("userId", "john;doe");
144144

145-
String template = "http://{host}/user/{userId}/dashboard";
145+
String template = "https://{host}/user/{userId}/dashboard";
146146
URI actual = this.handler.expand(template, vars);
147147

148148
assertEquals("https://www.example.com/user/john%3Bdoe/dashboard", actual.toString());

0 commit comments

Comments
 (0)