Skip to content

Commit 6068773

Browse files
authored
[TEST] test that low level REST client leaves path untouched (#25193)
Relates to #24987
1 parent 5a6fa62 commit 6068773

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

client/rest/src/main/java/org/elasticsearch/client/RestClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ private static HttpRequestBase addRequestBody(HttpRequestBase httpRequest, HttpE
553553
return httpRequest;
554554
}
555555

556-
private static URI buildUri(String pathPrefix, String path, Map<String, String> params) {
556+
static URI buildUri(String pathPrefix, String path, Map<String, String> params) {
557557
Objects.requireNonNull(path, "path must not be null");
558558
try {
559559
String fullPath;

client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import org.apache.http.HttpHost;
2424
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
2525

26+
import java.net.URI;
27+
import java.util.Collections;
28+
2629
import static org.junit.Assert.assertEquals;
2730
import static org.junit.Assert.fail;
2831
import static org.mockito.Mockito.mock;
@@ -77,6 +80,22 @@ public void testPerformAsyncWithWrongEndpoint() throws Exception {
7780
}
7881
}
7982

83+
public void testBuildUriLeavesPathUntouched() {
84+
{
85+
URI uri = RestClient.buildUri("/foo$bar", "/index/type/id", Collections.<String, String>emptyMap());
86+
assertEquals("/foo$bar/index/type/id", uri.getPath());
87+
}
88+
{
89+
URI uri = RestClient.buildUri(null, "/foo$bar/ty/pe/i/d", Collections.<String, String>emptyMap());
90+
assertEquals("/foo$bar/ty/pe/i/d", uri.getPath());
91+
}
92+
{
93+
URI uri = RestClient.buildUri(null, "/index/type/id", Collections.singletonMap("foo$bar", "x/y/z"));
94+
assertEquals("/index/type/id", uri.getPath());
95+
assertEquals("foo$bar=x/y/z", uri.getQuery());
96+
}
97+
}
98+
8099
private static RestClient createRestClient() {
81100
HttpHost[] hosts = new HttpHost[]{new HttpHost("localhost", 9200)};
82101
return new RestClient(mock(CloseableHttpAsyncClient.class), randomLongBetween(1_000, 30_000), new Header[]{}, hosts, null, null);

0 commit comments

Comments
 (0)