Skip to content

Commit f3f4a58

Browse files
authored
[8.19] Migrate watcher REST tests to new test framework. (#136690) (#137087)
* Migrate watcher REST tests to new test framework. (#136690) Relates to ES-11813 (cherry picked from commit 79791c8) # Conflicts: # x-pack/plugin/watcher/qa/rest/build.gradle * fix rest compat test * fix
1 parent e29f10e commit f3f4a58

File tree

71 files changed

+282
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+282
-203
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ private static ListMultimap<Class<?>, String> createLegacyRestTestBasePluginUsag
9292
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:transform:qa:multi-cluster-tests-with-security");
9393
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:transform:qa:multi-node-tests");
9494
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:transform:qa:single-node-tests");
95-
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:watcher:qa:rest");
96-
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:watcher:qa:with-security");
9795
return map;
9896
}
9997

x-pack/plugin/watcher/build.gradle

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
apply plugin: 'elasticsearch.internal-es-plugin'
22
apply plugin: 'elasticsearch.internal-cluster-test'
3+
apply plugin: 'elasticsearch.internal-java-rest-test'
4+
apply plugin: 'elasticsearch.internal-yaml-rest-test'
5+
apply plugin: 'elasticsearch.internal-test-artifact'
6+
apply plugin: 'elasticsearch.yaml-rest-compat-test'
7+
38
esplugin {
49
name = 'x-pack-watcher'
510
description = 'Elasticsearch Expanded Pack Plugin - Watcher'
6-
classname ='org.elasticsearch.xpack.watcher.Watcher'
7-
hasNativeController =false
8-
requiresKeystore =false
11+
classname = 'org.elasticsearch.xpack.watcher.Watcher'
12+
hasNativeController = false
13+
requiresKeystore = false
914
extendedPlugins = ['x-pack-core', 'lang-painless']
1015
}
1116

@@ -15,6 +20,16 @@ base {
1520

1621
ext.compactProfile = 'full'
1722

23+
restResources {
24+
restApi {
25+
include '_common', 'cluster', 'index', 'indices', 'get', 'nodes', 'search', 'watcher', 'security', 'xpack',
26+
'put_script', 'ingest', 'count', 'xpack'
27+
}
28+
restTests {
29+
includeXpack 'watcher'
30+
}
31+
}
32+
1833
tasks.named("dependencyLicenses").configure {
1934
mapping from: /owasp-java-html-sanitizer.*/, to: 'owasp-java-html-sanitizer'
2035
}
@@ -44,6 +59,41 @@ dependencies {
4459
testImplementation 'com.google.code.findbugs:jsr305:3.0.2'
4560

4661
internalClusterTestImplementation project(":modules:analysis-common")
62+
63+
javaRestTestImplementation project(':x-pack:qa')
64+
yamlRestTestImplementation project(':x-pack:qa')
65+
66+
clusterModules project(':modules:analysis-common')
67+
clusterModules project(':modules:ingest-common')
68+
clusterModules project(':modules:lang-mustache')
69+
clusterModules project(':modules:lang-painless')
70+
clusterModules project(xpackModule('ilm'))
71+
}
72+
73+
artifacts {
74+
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
75+
}
76+
77+
tasks.named("yamlRestTestV7CompatTransform").configure{ task ->
78+
task.skipTest("mustache/30_search_input/Test search input mustache integration (using request body and rest_total_hits_as_int)", "remove JodaCompatibleDateTime -- ZonedDateTime doesn't output millis/nanos if they're 0 (#78417)")
79+
task.skipTest("mustache/30_search_input/Test search input mustache integration (using request body)", "remove JodaCompatibleDateTime -- ZonedDateTime doesn't output millis/nanos if they're 0 (#78417)")
80+
task.skipTest("mustache/40_search_transform/Test search transform mustache integration (using request body)", "remove JodaCompatibleDateTime -- ZonedDateTime doesn't output millis/nanos if they're 0 (#78417)")
81+
task.skipTest("painless/40_exception/Test painless exceptions are returned when logging a broken response", "Exceptions are no longer thrown from Mustache, but from the transform action itself")
82+
task.replaceKeyInDo("watcher.ack_watch", "xpack-watcher.ack_watch")
83+
task.replaceKeyInDo("watcher.activate_watch", "xpack-watcher.activate_watch")
84+
task.replaceKeyInDo("watcher.deactivate_watch", "xpack-watcher.deactivate_watch")
85+
task.replaceKeyInDo("watcher.delete_watch", "xpack-watcher.delete_watch")
86+
task.replaceKeyInDo("watcher.execute_watch", "xpack-watcher.execute_watch")
87+
task.replaceKeyInDo("watcher.get_watch", "xpack-watcher.get_watch")
88+
task.replaceKeyInDo("watcher.put_watch", "xpack-watcher.put_watch")
89+
task.replaceKeyInDo("watcher.start", "xpack-watcher.start")
90+
task.replaceKeyInDo("watcher.stats", "xpack-watcher.stats")
91+
task.replaceKeyInDo("watcher.stop", "xpack-watcher.stop")
92+
93+
task.addAllowedWarningRegex(".*_xpack/watcher/.* is deprecated.*")
94+
task.addAllowedWarningRegex("\\[types removal\\].*")
95+
task.replaceValueTextByKeyValue("path", "/my_index/my_type/{{ctx.watch_id}}", "/my_index/_doc/{{ctx.watch_id}}",
96+
"Test webhook action with mustache integration")
4797
}
4898

4999
// classes are missing, e.g. com.ibm.icu.lang.UCharacter

x-pack/plugin/watcher/qa/build.gradle

Whitespace-only changes.

x-pack/plugin/watcher/qa/common/build.gradle

Lines changed: 0 additions & 6 deletions
This file was deleted.

x-pack/plugin/watcher/qa/rest/build.gradle

Lines changed: 0 additions & 59 deletions
This file was deleted.

x-pack/plugin/watcher/qa/with-security/build.gradle

Lines changed: 0 additions & 39 deletions
This file was deleted.

x-pack/plugin/watcher/qa/with-security/src/yamlRestTest/java/org/elasticsearch/smoketest/SmokeTestWatcherWithSecurityClientYamlTestSuiteIT.java

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
import org.elasticsearch.client.Response;
1111
import org.elasticsearch.client.ResponseException;
1212
import org.elasticsearch.common.Strings;
13-
import org.elasticsearch.common.settings.SecureString;
14-
import org.elasticsearch.common.settings.Settings;
15-
import org.elasticsearch.common.util.concurrent.ThreadContext;
13+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1614
import org.elasticsearch.test.rest.ObjectPath;
1715
import org.elasticsearch.xcontent.XContentBuilder;
1816
import org.elasticsearch.xcontent.XContentType;
19-
import org.elasticsearch.xpack.watcher.WatcherRestTestCase;
17+
import org.junit.ClassRule;
2018

2119
import java.io.IOException;
2220
import java.util.Map;
@@ -31,19 +29,12 @@
3129

3230
public class SmokeTestWatcherTestSuiteIT extends WatcherRestTestCase {
3331

34-
private static final String TEST_ADMIN_USERNAME = "test_admin";
35-
private static final String TEST_ADMIN_PASSWORD = "x-pack-test-password";
32+
@ClassRule
33+
public static ElasticsearchCluster cluster = watcherClusterSpec().build();
3634

3735
@Override
38-
protected Settings restClientSettings() {
39-
String token = basicAuthHeaderValue("watcher_manager", new SecureString("x-pack-test-password".toCharArray()));
40-
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
41-
}
42-
43-
@Override
44-
protected Settings restAdminSettings() {
45-
String token = basicAuthHeaderValue(TEST_ADMIN_USERNAME, new SecureString(TEST_ADMIN_PASSWORD.toCharArray()));
46-
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
36+
protected String getTestRestCluster() {
37+
return cluster.getHttpAddresses();
4738
}
4839

4940
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/52453")
@@ -79,8 +70,8 @@ public void testMonitorClusterHealth() throws Exception {
7970
.field("scheme", "http")
8071
.startObject("auth")
8172
.startObject("basic")
82-
.field("username", TEST_ADMIN_USERNAME)
83-
.field("password", TEST_ADMIN_PASSWORD)
73+
.field("username", ADMIN_USER)
74+
.field("password", TEST_PASSWORD)
8475
.endObject()
8576
.endObject()
8677
.endObject()
Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
import org.elasticsearch.client.Response;
1212
import org.elasticsearch.client.ResponseException;
1313
import org.elasticsearch.common.Strings;
14-
import org.elasticsearch.common.settings.SecureString;
15-
import org.elasticsearch.common.settings.Settings;
16-
import org.elasticsearch.common.util.concurrent.ThreadContext;
14+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
15+
import org.elasticsearch.test.cluster.util.resource.Resource;
1716
import org.elasticsearch.test.rest.ObjectPath;
1817
import org.elasticsearch.xcontent.XContentBuilder;
19-
import org.elasticsearch.xpack.watcher.WatcherRestTestCase;
2018
import org.junit.Before;
19+
import org.junit.ClassRule;
2120

2221
import java.io.IOException;
2322
import java.util.Map;
@@ -31,11 +30,19 @@
3130

3231
public class SmokeTestWatcherWithSecurityIT extends WatcherRestTestCase {
3332

34-
private static final String TEST_ADMIN_USERNAME = "test_admin";
35-
private static final String TEST_ADMIN_PASSWORD = "x-pack-test-password";
36-
3733
private String watchId = randomAlphaOfLength(20);
3834

35+
@ClassRule
36+
public static ElasticsearchCluster cluster = watcherClusterSpec().setting("xpack.security.enabled", "true")
37+
.rolesFile(Resource.fromClasspath("roles.yml"))
38+
.user(WATCHER_USER, TEST_PASSWORD, "watcher_manager", false)
39+
.build();
40+
41+
@Override
42+
protected String getTestRestCluster() {
43+
return cluster.getHttpAddresses();
44+
}
45+
3946
@Before
4047
public void beforeTest() throws Exception {
4148
Request deleteRequest = new Request("DELETE", "/my_test_index");
@@ -53,18 +60,6 @@ public void beforeTest() throws Exception {
5360
adminClient().performRequest(createNotAllowedDoc);
5461
}
5562

56-
@Override
57-
protected Settings restClientSettings() {
58-
String token = basicAuthHeaderValue("watcher_manager", new SecureString("x-pack-test-password".toCharArray()));
59-
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
60-
}
61-
62-
@Override
63-
protected Settings restAdminSettings() {
64-
String token = basicAuthHeaderValue(TEST_ADMIN_USERNAME, new SecureString(TEST_ADMIN_PASSWORD.toCharArray()));
65-
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
66-
}
67-
6863
public void testSearchInputHasPermissions() throws Exception {
6964
try (XContentBuilder builder = jsonBuilder()) {
7065
builder.startObject();

0 commit comments

Comments
 (0)