Skip to content

Commit 3f580db

Browse files
committed
Switch remaining tests to new style Requests
In elastic#29623 we added `Request` object flavored requests to the low level REST client and in elastic#30315 we deprecated the old `performRequest`s. This changes all calls in the `client` and `distribution` projects to use the new versions.
1 parent 8f16696 commit 3f580db

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/StoredScriptsIT.java

+6-16
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
21-
import org.apache.http.entity.ContentType;
22-
import org.apache.http.entity.StringEntity;
2320
import org.apache.http.util.EntityUtils;
2421
import org.elasticsearch.ElasticsearchStatusException;
2522
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
@@ -35,7 +32,6 @@
3532

3633
import java.util.Collections;
3734

38-
import static java.util.Collections.emptyMap;
3935
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
4036
import static org.hamcrest.Matchers.equalTo;
4137

@@ -52,12 +48,9 @@ public void testGetStoredScript() throws Exception {
5248
final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
5349
// TODO: change to HighLevel PutStoredScriptRequest when it will be ready
5450
// so far - using low-level REST API
55-
Response putResponse =
56-
adminClient()
57-
.performRequest("PUT", "/_scripts/calculate-score", emptyMap(),
58-
new StringEntity("{\"script\":" + script + "}",
59-
ContentType.APPLICATION_JSON));
60-
assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode());
51+
Request putRequest = new Request("PUT", "/_scripts/calculate-score");
52+
putRequest.setJsonEntity("{\"script\":" + script + "}");
53+
Response putResponse = adminClient().performRequest(putRequest);
6154
assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity()));
6255

6356
GetStoredScriptRequest getRequest = new GetStoredScriptRequest("calculate-score");
@@ -78,12 +71,9 @@ public void testDeleteStoredScript() throws Exception {
7871
final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
7972
// TODO: change to HighLevel PutStoredScriptRequest when it will be ready
8073
// so far - using low-level REST API
81-
Response putResponse =
82-
adminClient()
83-
.performRequest("PUT", "/_scripts/" + id, emptyMap(),
84-
new StringEntity("{\"script\":" + script + "}",
85-
ContentType.APPLICATION_JSON));
86-
assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode());
74+
Request putRequest = new Request("PUT", "/_scripts/" + id);
75+
putRequest.setJsonEntity("{\"script\":" + script + "}");
76+
Response putResponse = adminClient().performRequest(putRequest);
8777
assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity()));
8878

8979
DeleteStoredScriptRequest deleteRequest = new DeleteStoredScriptRequest(id);

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/StoredScriptsDocumentationIT.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import org.apache.http.entity.ContentType;
21-
import org.apache.http.entity.StringEntity;
2220
import org.apache.http.util.EntityUtils;
2321
import org.elasticsearch.action.ActionListener;
2422
import org.elasticsearch.action.LatchedActionListener;
@@ -27,6 +25,7 @@
2725
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
2826
import org.elasticsearch.action.support.master.AcknowledgedResponse;
2927
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
28+
import org.elasticsearch.client.Request;
3029
import org.elasticsearch.client.RequestOptions;
3130
import org.elasticsearch.client.Response;
3231
import org.elasticsearch.client.RestHighLevelClient;
@@ -43,7 +42,6 @@
4342
import java.util.concurrent.CountDownLatch;
4443
import java.util.concurrent.TimeUnit;
4544

46-
import static java.util.Collections.emptyMap;
4745
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
4846
import static org.hamcrest.Matchers.equalTo;
4947

@@ -193,11 +191,9 @@ private void putStoredScript(String id, StoredScriptSource scriptSource) throws
193191
final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
194192
// TODO: change to HighLevel PutStoredScriptRequest when it will be ready
195193
// so far - using low-level REST API
196-
Response putResponse =
197-
adminClient()
198-
.performRequest("PUT", "/_scripts/" + id, emptyMap(),
199-
new StringEntity("{\"script\":" + script + "}",
200-
ContentType.APPLICATION_JSON));
194+
Request request = new Request("PUT", "/_scripts/" + id);
195+
request.setJsonEntity("{\"script\":" + script + "}");
196+
Response putResponse = adminClient().performRequest(request);
201197
assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode());
202198
assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity()));
203199
}

distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/WaitForRefreshAndCloseTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void setupIndex() throws IOException {
5353

5454
@After
5555
public void cleanupIndex() throws IOException {
56-
client().performRequest("DELETE", indexName());
56+
client().performRequest(new Request("DELETE", indexName()));
5757
}
5858

5959
private String indexName() {

0 commit comments

Comments
 (0)