Skip to content

Commit 45d4ae8

Browse files
authored
Migrate watcher REST tests to new test framework. (#136690) (#137045)
Relates to ES-11813
1 parent 4fca9fa commit 45d4ae8

File tree

71 files changed

+259
-186
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

+259
-186
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: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
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+
37
esplugin {
48
name = 'x-pack-watcher'
59
description = 'Elasticsearch Expanded Pack Plugin - Watcher'
6-
classname ='org.elasticsearch.xpack.watcher.Watcher'
7-
hasNativeController =false
8-
requiresKeystore =false
10+
classname = 'org.elasticsearch.xpack.watcher.Watcher'
11+
hasNativeController = false
12+
requiresKeystore = false
913
extendedPlugins = ['x-pack-core', 'lang-painless']
1014
}
1115

@@ -15,6 +19,16 @@ base {
1519

1620
ext.compactProfile = 'full'
1721

22+
restResources {
23+
restApi {
24+
include '_common', 'cluster', 'index', 'indices', 'get', 'nodes', 'search', 'watcher', 'security', 'xpack',
25+
'put_script', 'ingest', 'count', 'xpack'
26+
}
27+
restTests {
28+
includeXpack 'watcher'
29+
}
30+
}
31+
1832
tasks.named("dependencyLicenses").configure {
1933
mapping from: /owasp-java-html-sanitizer.*/, to: 'owasp-java-html-sanitizer'
2034
}
@@ -44,6 +58,19 @@ dependencies {
4458
testImplementation 'com.google.code.findbugs:jsr305:3.0.2'
4559

4660
internalClusterTestImplementation project(":modules:analysis-common")
61+
62+
javaRestTestImplementation project(':x-pack:qa')
63+
yamlRestTestImplementation project(':x-pack:qa')
64+
65+
clusterModules project(':modules:analysis-common')
66+
clusterModules project(':modules:ingest-common')
67+
clusterModules project(':modules:lang-mustache')
68+
clusterModules project(':modules:lang-painless')
69+
clusterModules project(xpackModule('ilm'))
70+
}
71+
72+
artifacts {
73+
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
4774
}
4875

4976
// 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 & 42 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
public void testMonitorClusterHealth() throws Exception {
@@ -78,8 +69,8 @@ public void testMonitorClusterHealth() throws Exception {
7869
.field("scheme", "http")
7970
.startObject("auth")
8071
.startObject("basic")
81-
.field("username", TEST_ADMIN_USERNAME)
82-
.field("password", TEST_ADMIN_PASSWORD)
72+
.field("username", ADMIN_USER)
73+
.field("password", TEST_PASSWORD)
8374
.endObject()
8475
.endObject()
8576
.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();
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
package org.elasticsearch.xpack.watcher;
7+
package org.elasticsearch.smoketest;
88

99
import org.elasticsearch.client.Request;
1010
import org.elasticsearch.client.Response;
11+
import org.elasticsearch.common.settings.SecureString;
12+
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.common.util.concurrent.ThreadContext;
1114
import org.elasticsearch.test.ESTestCase;
15+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
16+
import org.elasticsearch.test.cluster.local.LocalClusterSpecBuilder;
1217
import org.elasticsearch.test.rest.ESRestTestCase;
1318
import org.elasticsearch.test.rest.ObjectPath;
1419
import org.junit.After;
@@ -26,6 +31,36 @@
2631
*/
2732
public abstract class WatcherRestTestCase extends ESRestTestCase {
2833

34+
static final String ADMIN_USER = "test_admin";
35+
static final String WATCHER_USER = "watcher_manager";
36+
static final String TEST_PASSWORD = "x-pack-test-password";
37+
38+
static LocalClusterSpecBuilder<ElasticsearchCluster> watcherClusterSpec() {
39+
return ElasticsearchCluster.local()
40+
.module("x-pack-watcher")
41+
.module("x-pack-ilm")
42+
.module("ingest-common")
43+
.module("analysis-common")
44+
.module("lang-mustache")
45+
.setting("xpack.ml.enabled", "false")
46+
.setting("xpack.license.self_generated.type", "trial")
47+
.setting("logger.org.elasticsearch.xpack.watcher", "debug")
48+
.setting("logger.org.elasticsearch.xpack.core.watcher", "debug")
49+
.user(ADMIN_USER, TEST_PASSWORD, "superuser", true);
50+
}
51+
52+
@Override
53+
protected Settings restClientSettings() {
54+
String token = basicAuthHeaderValue(WATCHER_USER, new SecureString(TEST_PASSWORD.toCharArray()));
55+
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
56+
}
57+
58+
@Override
59+
protected Settings restAdminSettings() {
60+
String token = basicAuthHeaderValue(ADMIN_USER, new SecureString(TEST_PASSWORD.toCharArray()));
61+
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
62+
}
63+
2964
@Before
3065
public final void startWatcher() throws Exception {
3166
ESTestCase.assertBusy(() -> {

0 commit comments

Comments
 (0)