|
|
@@ -58,6 +58,7 @@ import static org.hamcrest.Matchers.startsWith;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
+import static org.junit.Assert.fail;
|
|
|
|
|
|
/**
|
|
|
* Integration test to check interaction between {@link RestClient} and {@link org.apache.http.client.HttpClient}.
|
|
|
@@ -135,8 +136,7 @@ public class RestClientSingleHostIntegTests extends RestClientTestCase {
|
|
|
final RestClientBuilder restClientBuilder = RestClient.builder(
|
|
|
new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort())).setDefaultHeaders(defaultHeaders);
|
|
|
if (pathPrefix.length() > 0) {
|
|
|
- // sometimes cut off the leading slash
|
|
|
- restClientBuilder.setPathPrefix(randomBoolean() ? pathPrefix.substring(1) : pathPrefix);
|
|
|
+ restClientBuilder.setPathPrefix(pathPrefix);
|
|
|
}
|
|
|
|
|
|
if (useAuth) {
|
|
|
@@ -281,6 +281,33 @@ public class RestClientSingleHostIntegTests extends RestClientTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testUrlWithoutLeadingSlash() throws Exception {
|
|
|
+ if (pathPrefix.length() == 0) {
|
|
|
+ try {
|
|
|
+ restClient.performRequest("GET", "200");
|
|
|
+ fail("request should have failed");
|
|
|
+ } catch(ResponseException e) {
|
|
|
+ assertEquals(404, e.getResponse().getStatusLine().getStatusCode());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ {
|
|
|
+ Response response = restClient.performRequest("GET", "200");
|
|
|
+ //a trailing slash gets automatically added if a pathPrefix is configured
|
|
|
+ assertEquals(200, response.getStatusLine().getStatusCode());
|
|
|
+ }
|
|
|
+ {
|
|
|
+ //pathPrefix is not required to start with '/', will be added automatically
|
|
|
+ try (RestClient restClient = RestClient.builder(
|
|
|
+ new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort()))
|
|
|
+ .setPathPrefix(pathPrefix.substring(1)).build()) {
|
|
|
+ Response response = restClient.performRequest("GET", "200");
|
|
|
+ //a trailing slash gets automatically added if a pathPrefix is configured
|
|
|
+ assertEquals(200, response.getStatusLine().getStatusCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private Response bodyTest(final String method) throws IOException {
|
|
|
return bodyTest(restClient, method);
|
|
|
}
|