@@ -37,6 +37,8 @@ public class SmokeTestWatcherWithSecurityIT extends ESRestTestCase {
3737 private static final String TEST_ADMIN_USERNAME = "test_admin" ;
3838 private static final String TEST_ADMIN_PASSWORD = "x-pack-test-password" ;
3939
40+ private String watchId = randomAlphaOfLength (20 );
41+
4042 @ Before
4143 public void startWatcher () throws Exception {
4244 StringEntity entity = new StringEntity ("{ \" value\" : \" 15\" }" , ContentType .APPLICATION_JSON );
@@ -87,7 +89,6 @@ public void startWatcher() throws Exception {
8789
8890 @ After
8991 public void stopWatcher () throws Exception {
90- adminClient ().performRequest ("DELETE" , "_xpack/watcher/watch/my_watch" );
9192 assertOK (adminClient ().performRequest ("DELETE" , "my_test_index" ));
9293
9394 assertBusy (() -> {
@@ -147,14 +148,14 @@ public void testSearchInputHasPermissions() throws Exception {
147148 builder .startObject ("condition" ).startObject ("compare" ).startObject ("ctx.payload.hits.total" ).field ("gte" , 1 )
148149 .endObject ().endObject ().endObject ();
149150 builder .startObject ("actions" ).startObject ("logging" ).startObject ("logging" )
150- .field ("text" , "successfully ran my_watch to test for search inpput" ).endObject ().endObject ().endObject ();
151+ .field ("text" , "successfully ran " + watchId + " to test for search inpput" ).endObject ().endObject ().endObject ();
151152 builder .endObject ();
152153
153- indexWatch ("my_watch" , builder );
154+ indexWatch (watchId , builder );
154155 }
155156
156157 // check history, after watch has fired
157- ObjectPath objectPath = getWatchHistoryEntry ("my_watch" , "executed" );
158+ ObjectPath objectPath = getWatchHistoryEntry (watchId , "executed" );
158159 boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
159160 assertThat (conditionMet , is (true ));
160161 }
@@ -174,11 +175,11 @@ public void testSearchInputWithInsufficientPrivileges() throws Exception {
174175 .field ("text" , "this should never be logged" ).endObject ().endObject ().endObject ();
175176 builder .endObject ();
176177
177- indexWatch ("my_watch" , builder );
178+ indexWatch (watchId , builder );
178179 }
179180
180181 // check history, after watch has fired
181- ObjectPath objectPath = getWatchHistoryEntry ("my_watch" );
182+ ObjectPath objectPath = getWatchHistoryEntry (watchId );
182183 String state = objectPath .evaluate ("hits.hits.0._source.state" );
183184 assertThat (state , is ("execution_not_needed" ));
184185 boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
@@ -201,11 +202,11 @@ public void testSearchTransformHasPermissions() throws Exception {
201202 .endObject ().endObject ().endObject ();
202203 builder .endObject ();
203204
204- indexWatch ("my_watch" , builder );
205+ indexWatch (watchId , builder );
205206 }
206207
207208 // check history, after watch has fired
208- ObjectPath objectPath = getWatchHistoryEntry ("my_watch" , "executed" );
209+ ObjectPath objectPath = getWatchHistoryEntry (watchId , "executed" );
209210 boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
210211 assertThat (conditionMet , is (true ));
211212
@@ -232,10 +233,10 @@ public void testSearchTransformInsufficientPermissions() throws Exception {
232233 .endObject ().endObject ().endObject ();
233234 builder .endObject ();
234235
235- indexWatch ("my_watch" , builder );
236+ indexWatch (watchId , builder );
236237 }
237238
238- getWatchHistoryEntry ("my_watch" );
239+ getWatchHistoryEntry (watchId );
239240
240241 Response response = adminClient ().performRequest ("GET" , "my_test_index/doc/some-id" ,
241242 Collections .singletonMap ("ignore" , "404" ));
@@ -254,10 +255,10 @@ public void testIndexActionHasPermissions() throws Exception {
254255 .endObject ().endObject ().endObject ();
255256 builder .endObject ();
256257
257- indexWatch ("my_watch" , builder );
258+ indexWatch (watchId , builder );
258259 }
259260
260- ObjectPath objectPath = getWatchHistoryEntry ("my_watch" , "executed" );
261+ ObjectPath objectPath = getWatchHistoryEntry (watchId , "executed" );
261262 boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
262263 assertThat (conditionMet , is (true ));
263264
@@ -278,10 +279,10 @@ public void testIndexActionInsufficientPrivileges() throws Exception {
278279 .endObject ().endObject ().endObject ();
279280 builder .endObject ();
280281
281- indexWatch ("my_watch" , builder );
282+ indexWatch (watchId , builder );
282283 }
283284
284- ObjectPath objectPath = getWatchHistoryEntry ("my_watch" , "executed" );
285+ ObjectPath objectPath = getWatchHistoryEntry (watchId , "executed" );
285286 boolean conditionMet = objectPath .evaluate ("hits.hits.0._source.result.condition.met" );
286287 assertThat (conditionMet , is (true ));
287288
@@ -293,7 +294,7 @@ public void testIndexActionInsufficientPrivileges() throws Exception {
293294 private void indexWatch (String watchId , XContentBuilder builder ) throws Exception {
294295 StringEntity entity = new StringEntity (Strings .toString (builder ), ContentType .APPLICATION_JSON );
295296
296- Response response = client ().performRequest ("PUT" , "_xpack/watcher/watch/my_watch" , Collections .emptyMap (), entity );
297+ Response response = client ().performRequest ("PUT" , "_xpack/watcher/watch/" + watchId , Collections .emptyMap (), entity );
297298 assertOK (response );
298299 Map <String , Object > responseMap = entityAsMap (response );
299300 assertThat (responseMap , hasEntry ("_id" , watchId ));
0 commit comments