Add test case for HttpRequest with relative URIs

Test case for #19890
This commit is contained in:
Arjen Poutsma
2019-01-28 16:42:25 +01:00
parent b8f7c37cc4
commit d3b5ba7a36

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -25,6 +25,7 @@ import java.util.Map;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.mock.web.test.MockHttpServletRequest;
@@ -518,6 +519,29 @@ public class UriComponentsBuilderTests {
assertEquals("/foo/", after.getPath());
}
@Test // gh-19890
public void fromHttpRequestWithEmptyScheme() {
HttpRequest request = new HttpRequest() {
@Override
public String getMethodValue() {
return "GET";
}
@Override
public URI getURI() {
return UriComponentsBuilder.fromUriString("/").build().toUri();
}
@Override
public HttpHeaders getHeaders() {
return new HttpHeaders();
}
};
UriComponents result = UriComponentsBuilder.fromHttpRequest(request).build();
assertEquals("/", result.toString());
}
@Test
public void path() {
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");