55 */
66package org .elasticsearch .smoketest ;
77
8- import org .apache .http .entity .ContentType ;
9- import org .apache .http .entity .StringEntity ;
108import org .apache .http .util .EntityUtils ;
9+ import org .elasticsearch .client .Request ;
1110import org .elasticsearch .client .Response ;
1211import org .elasticsearch .common .Strings ;
1312import org .elasticsearch .common .settings .SecureString ;
2120import org .junit .Before ;
2221
2322import java .io .IOException ;
24- import java .util .Collections ;
2523import java .util .Map ;
2624import java .util .concurrent .atomic .AtomicReference ;
2725
@@ -41,27 +39,28 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
4139
4240 @ Before
4341 public void startWatcher () throws Exception {
44- StringEntity entity = new StringEntity ("{ \" value\" : \" 15\" }" , ContentType .APPLICATION_JSON );
45- assertOK (adminClient ().performRequest ("PUT" , "my_test_index/doc/1" , Collections .singletonMap ("refresh" , "true" ), entity ));
42+ Request createAllowedDoc = new Request ("PUT" , "/my_test_index/doc/1" );
43+ createAllowedDoc .setJsonEntity ("{ \" value\" : \" 15\" }" );
44+ createAllowedDoc .addParameter ("refresh" , "true" );
45+ adminClient ().performRequest (createAllowedDoc );
4646
4747 // delete the watcher history to not clutter with entries from other test
48- adminClient ().performRequest ("DELETE" , ".watcher-history-*" , Collections . emptyMap ( ));
48+ adminClient ().performRequest (new Request ( "DELETE" , ".watcher-history-*" ));
4949
5050 // create one document in this index, so we can test in the YAML tests, that the index cannot be accessed
51- Response resp = adminClient (). performRequest ( "PUT" , "/index_not_allowed_to_read/doc/1" , Collections . emptyMap (),
52- new StringEntity ("{\" foo\" :\" bar\" }" , ContentType . APPLICATION_JSON ) );
53- assertThat ( resp . getStatusLine (). getStatusCode (), is ( 201 ) );
51+ Request createNotAllowedDoc = new Request ( "PUT" , "/index_not_allowed_to_read/doc/1" );
52+ createNotAllowedDoc . setJsonEntity ("{\" foo\" :\" bar\" }" );
53+ adminClient (). performRequest ( createNotAllowedDoc );
5454
5555 assertBusy (() -> {
5656 try {
57- Response statsResponse = adminClient ().performRequest ("GET" , "_xpack/watcher/stats" );
57+ Response statsResponse = adminClient ().performRequest (new Request ( "GET" , "/ _xpack/watcher/stats" ) );
5858 ObjectPath objectPath = ObjectPath .createFromResponse (statsResponse );
5959 String state = objectPath .evaluate ("stats.0.watcher_state" );
6060
6161 switch (state ) {
6262 case "stopped" :
63- Response startResponse = adminClient ().performRequest ("POST" , "_xpack/watcher/_start" );
64- assertOK (startResponse );
63+ Response startResponse = adminClient ().performRequest (new Request ("POST" , "/_xpack/watcher/_start" ));
6564 String body = EntityUtils .toString (startResponse .getEntity ());
6665 assertThat (body , containsString ("\" acknowledged\" :true" ));
6766 break ;
@@ -82,18 +81,18 @@ public void startWatcher() throws Exception {
8281
8382 assertBusy (() -> {
8483 for (String template : WatcherIndexTemplateRegistryField .TEMPLATE_NAMES ) {
85- assertOK (adminClient ().performRequest ("HEAD" , "_template/" + template ));
84+ assertOK (adminClient ().performRequest (new Request ( "HEAD" , "_template/" + template ) ));
8685 }
8786 });
8887 }
8988
9089 @ After
9190 public void stopWatcher () throws Exception {
92- assertOK ( adminClient ().performRequest ("DELETE" , "my_test_index" ));
91+ adminClient ().performRequest (new Request ( "DELETE" , "/ my_test_index" ));
9392
9493 assertBusy (() -> {
9594 try {
96- Response statsResponse = adminClient ().performRequest ("GET" , "_xpack/watcher/stats" );
95+ Response statsResponse = adminClient ().performRequest (new Request ( "GET" , "/ _xpack/watcher/stats" ) );
9796 ObjectPath objectPath = ObjectPath .createFromResponse (statsResponse );
9897 String state = objectPath .evaluate ("stats.0.watcher_state" );
9998
@@ -106,8 +105,7 @@ public void stopWatcher() throws Exception {
106105 case "starting" :
107106 throw new AssertionError ("waiting until starting state reached started state to stop" );
108107 case "started" :
109- Response stopResponse = adminClient ().performRequest ("POST" , "_xpack/watcher/_stop" , Collections .emptyMap ());
110- assertOK (stopResponse );
108+ Response stopResponse = adminClient ().performRequest (new Request ("POST" , "/_xpack/watcher/_stop" ));
111109 String body = EntityUtils .toString (stopResponse .getEntity ());
112110 assertThat (body , containsString ("\" acknowledged\" :true" ));
113111 break ;
@@ -210,7 +208,7 @@ public void testSearchTransformHasPermissions() throws Exception {
210208 boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
211209 assertThat (conditionMet , is (true ));
212210
213- ObjectPath getObjectPath = ObjectPath .createFromResponse (client ().performRequest ("GET" , "my_test_index/doc/my-id" ));
211+ ObjectPath getObjectPath = ObjectPath .createFromResponse (client ().performRequest (new Request ( "GET" , "/ my_test_index/doc/my-id" ) ));
214212 String value = getObjectPath .evaluate ("_source.hits.hits.0._source.value" );
215213 assertThat (value , is ("15" ));
216214 }
@@ -238,8 +236,7 @@ public void testSearchTransformInsufficientPermissions() throws Exception {
238236
239237 getWatchHistoryEntry (watchId );
240238
241- Response response = adminClient ().performRequest ("GET" , "my_test_index/doc/some-id" ,
242- Collections .singletonMap ("ignore" , "404" ));
239+ Response response = adminClient ().performRequest (new Request ("HEAD" , "/my_test_index/doc/some-id" ));
243240 assertThat (response .getStatusLine ().getStatusCode (), is (404 ));
244241 }
245242
@@ -262,7 +259,7 @@ public void testIndexActionHasPermissions() throws Exception {
262259 boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
263260 assertThat (conditionMet , is (true ));
264261
265- ObjectPath getObjectPath = ObjectPath .createFromResponse (client ().performRequest ("GET" , "my_test_index/doc/my-id" ));
262+ ObjectPath getObjectPath = ObjectPath .createFromResponse (client ().performRequest (new Request ( "GET" , "/ my_test_index/doc/my-id" ) ));
266263 String spam = getObjectPath .evaluate ("_source.spam" );
267264 assertThat (spam , is ("eggs" ));
268265 }
@@ -286,16 +283,14 @@ public void testIndexActionInsufficientPrivileges() throws Exception {
286283 boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
287284 assertThat (conditionMet , is (true ));
288285
289- Response response = adminClient ().performRequest ("GET" , "index_not_allowed_to_read/doc/my-id" ,
290- Collections .singletonMap ("ignore" , "404" ));
286+ Response response = adminClient ().performRequest (new Request ("HEAD" , "/index_not_allowed_to_read/doc/my-id" ));
291287 assertThat (response .getStatusLine ().getStatusCode (), is (404 ));
292288 }
293289
294290 private void indexWatch (String watchId , XContentBuilder builder ) throws Exception {
295- StringEntity entity = new StringEntity (Strings .toString (builder ), ContentType .APPLICATION_JSON );
296-
297- Response response = client ().performRequest ("PUT" , "_xpack/watcher/watch/" + watchId , Collections .emptyMap (), entity );
298- assertOK (response );
291+ Request request = new Request ("PUT" , "/_xpack/watcher/watch/" + watchId );
292+ request .setJsonEntity (Strings .toString (builder ));
293+ Response response = client ().performRequest (request );
299294 Map <String , Object > responseMap = entityAsMap (response );
300295 assertThat (responseMap , hasEntry ("_id" , watchId ));
301296 }
@@ -307,7 +302,7 @@ private ObjectPath getWatchHistoryEntry(String watchId) throws Exception {
307302 private ObjectPath getWatchHistoryEntry (String watchId , String state ) throws Exception {
308303 final AtomicReference <ObjectPath > objectPathReference = new AtomicReference <>();
309304 assertBusy (() -> {
310- client ().performRequest ("POST" , ".watcher-history-*/_refresh" );
305+ client ().performRequest (new Request ( "POST" , "/ .watcher-history-*/_refresh" ) );
311306
312307 try (XContentBuilder builder = jsonBuilder ()) {
313308 builder .startObject ();
@@ -323,8 +318,9 @@ private ObjectPath getWatchHistoryEntry(String watchId, String state) throws Exc
323318 .endObject ().endArray ();
324319 builder .endObject ();
325320
326- StringEntity entity = new StringEntity (Strings .toString (builder ), ContentType .APPLICATION_JSON );
327- Response response = client ().performRequest ("POST" , ".watcher-history-*/_search" , Collections .emptyMap (), entity );
321+ Request searchRequest = new Request ("POST" , "/.watcher-history-*/_search" );
322+ searchRequest .setJsonEntity (Strings .toString (builder ));
323+ Response response = client ().performRequest (searchRequest );
328324 ObjectPath objectPath = ObjectPath .createFromResponse (response );
329325 int totalHits = objectPath .evaluate ("hits.total" );
330326 assertThat (totalHits , is (greaterThanOrEqualTo (1 )));
0 commit comments