Skip to content

Commit b7d109c

Browse files
authored
Migrate discovery-ec2 YAML tests to Java REST tests (#118427)
Really just to create a starting point for a more comprehensive Java REST test suite, the test itself is not very interesting.
1 parent 3590be7 commit b7d109c

File tree

5 files changed

+65
-54
lines changed

5 files changed

+65
-54
lines changed

plugins/discovery-ec2/build.gradle

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* your election, the "Elastic License 2.0", the "GNU Affero General Public
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
9-
apply plugin: 'elasticsearch.legacy-yaml-rest-test'
109
apply plugin: 'elasticsearch.internal-cluster-test'
10+
apply plugin: 'elasticsearch.internal-java-rest-test'
1111

1212
esplugin {
1313
description 'The EC2 discovery plugin allows to use AWS API for the unicast discovery mechanism.'
@@ -29,12 +29,6 @@ dependencies {
2929
api "joda-time:joda-time:2.10.10"
3030
}
3131

32-
restResources {
33-
restApi {
34-
include '_common', 'cluster', 'nodes'
35-
}
36-
}
37-
3832
tasks.named("dependencyLicenses").configure {
3933
mapping from: /aws-java-sdk-.*/, to: 'aws-java-sdk'
4034
mapping from: /jackson-.*/, to: 'jackson'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.discovery.ec2;
11+
12+
import org.elasticsearch.client.Request;
13+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
14+
import org.elasticsearch.test.rest.ESRestTestCase;
15+
import org.junit.ClassRule;
16+
17+
import java.io.IOException;
18+
import java.util.HashSet;
19+
import java.util.List;
20+
import java.util.Objects;
21+
22+
import static org.hamcrest.Matchers.hasItem;
23+
24+
public class DiscoveryEc2PluginLoadedIT extends ESRestTestCase {
25+
26+
@ClassRule
27+
public static ElasticsearchCluster cluster = ElasticsearchCluster.local().plugin("discovery-ec2").build();
28+
29+
@Override
30+
protected String getTestRestCluster() {
31+
return cluster.getHttpAddresses();
32+
}
33+
34+
public void testPluginLoaded() throws IOException {
35+
final var nodesInfoResponse = assertOKAndCreateObjectPath(client().performRequest(new Request("GET", "/_nodes/plugins")));
36+
for (final var nodeId : nodesInfoResponse.evaluateMapKeys("nodes")) {
37+
final var pluginCount = asInstanceOf(List.class, nodesInfoResponse.evaluateExact("nodes", nodeId, "plugins")).size();
38+
final var pluginNames = new HashSet<String>();
39+
for (int i = 0; i < pluginCount; i++) {
40+
pluginNames.add(
41+
Objects.requireNonNull(nodesInfoResponse.evaluateExact("nodes", nodeId, "plugins", Integer.toString(i), "name"))
42+
);
43+
}
44+
assertThat(pluginNames, hasItem("discovery-ec2"));
45+
}
46+
}
47+
48+
}

plugins/discovery-ec2/src/yamlRestTest/java/org/elasticsearch/discovery/ec2/CloudAwsClientYamlTestSuiteIT.java

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

plugins/discovery-ec2/src/yamlRestTest/resources/rest-api-spec/test/discovery_ec2/10_basic.yml

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

test/framework/src/main/java/org/elasticsearch/test/rest/ObjectPath.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,24 @@ public <T> T evaluate(String path) throws IOException {
7070
/**
7171
* Returns the object corresponding to the provided path if present, null otherwise
7272
*/
73-
@SuppressWarnings("unchecked")
7473
public <T> T evaluate(String path, Stash stash) throws IOException {
75-
String[] parts = parsePath(path);
74+
return evaluateExact(stash, parsePath(path));
75+
}
76+
77+
/**
78+
* Returns the object corresponding to the provided path if present, null otherwise
79+
*/
80+
public <T> T evaluateExact(String... path) throws IOException {
81+
return evaluateExact(Stash.EMPTY, path);
82+
}
83+
84+
/**
85+
* Returns the object corresponding to the provided path if present, null otherwise
86+
*/
87+
@SuppressWarnings("unchecked")
88+
public <T> T evaluateExact(Stash stash, String... path) throws IOException {
7689
Object result = this.object;
77-
for (String part : parts) {
90+
for (String part : path) {
7891
result = evaluate(part, result, stash);
7992
if (result == null) {
8093
return null;

0 commit comments

Comments
 (0)