Skip to content

Commit da93344

Browse files
authored
Remove deprecated test from the HLRC tests (#48424)
The AbstractHlrcWriteableXContentTestCase was replaced by a better test case a while ago, and this is the last two instances using it. They have been converted and the test is now deleted. Ref #39745
1 parent 0600e65 commit da93344

File tree

4 files changed

+52
-176
lines changed

4 files changed

+52
-176
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcWriteableXContentTestCase.java

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

client/rest-high-level/src/test/java/org/elasticsearch/client/license/PutLicenseResponseTests.java

Lines changed: 17 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,23 @@
1818
*/
1919
package org.elasticsearch.client.license;
2020

21-
import org.elasticsearch.client.AbstractHlrcWriteableXContentTestCase;
22-
import org.elasticsearch.common.io.stream.Writeable;
21+
import org.elasticsearch.client.AbstractResponseTestCase;
2322
import org.elasticsearch.common.xcontent.XContentParser;
24-
import org.elasticsearch.protocol.xpack.license.LicensesStatus;
23+
import org.elasticsearch.common.xcontent.XContentType;
2524

2625
import java.io.IOException;
26+
import java.util.Arrays;
2727
import java.util.Collections;
2828
import java.util.HashMap;
2929
import java.util.Map;
30-
import java.util.function.Function;
31-
import java.util.function.Predicate;
3230

33-
public class PutLicenseResponseTests extends AbstractHlrcWriteableXContentTestCase<
34-
org.elasticsearch.protocol.xpack.license.PutLicenseResponse, PutLicenseResponse> {
35-
36-
@Override
37-
public org.elasticsearch.client.license.PutLicenseResponse doHlrcParseInstance(XContentParser parser) throws IOException {
38-
return org.elasticsearch.client.license.PutLicenseResponse.fromXContent(parser);
39-
}
40-
41-
@Override
42-
public org.elasticsearch.protocol.xpack.license.PutLicenseResponse convertHlrcToInternal(
43-
org.elasticsearch.client.license.PutLicenseResponse instance) {
44-
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(instance.isAcknowledged(),
45-
org.elasticsearch.protocol.xpack.license.LicensesStatus.valueOf(instance.status().name()),
46-
instance.acknowledgeHeader(), instance.acknowledgeMessages());
47-
}
48-
49-
@Override
50-
protected boolean supportsUnknownFields() {
51-
return true;
52-
}
31+
import static org.hamcrest.Matchers.equalTo;
5332

54-
@Override
55-
protected Predicate<String> getRandomFieldsExcludeFilter() {
56-
// The structure of the response is such that unknown fields inside acknowledge cannot be supported since they
57-
// are treated as messages from new services
58-
return p -> p.startsWith("acknowledge");
59-
}
33+
public class PutLicenseResponseTests extends AbstractResponseTestCase<
34+
org.elasticsearch.protocol.xpack.license.PutLicenseResponse, PutLicenseResponse> {
6035

6136
@Override
62-
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createTestInstance() {
37+
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createServerTestInstance(XContentType xContentType) {
6338
boolean acknowledged = randomBoolean();
6439
org.elasticsearch.protocol.xpack.license.LicensesStatus status =
6540
randomFrom(org.elasticsearch.protocol.xpack.license.LicensesStatus.VALID,
@@ -97,45 +72,18 @@ private static Map<String, String[]> randomAckMessages() {
9772
}
9873

9974
@Override
100-
protected Writeable.Reader<org.elasticsearch.protocol.xpack.license.PutLicenseResponse> instanceReader() {
101-
return org.elasticsearch.protocol.xpack.license.PutLicenseResponse::new;
75+
protected PutLicenseResponse doParseToClientInstance(XContentParser parser) throws IOException {
76+
return PutLicenseResponse.fromXContent(parser);
10277
}
10378

10479
@Override
105-
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse mutateInstance(
106-
org.elasticsearch.protocol.xpack.license.PutLicenseResponse response) {
107-
@SuppressWarnings("unchecked")
108-
Function<org.elasticsearch.protocol.xpack.license.PutLicenseResponse,
109-
org.elasticsearch.protocol.xpack.license.PutLicenseResponse> mutator = randomFrom(
110-
r -> new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
111-
r.isAcknowledged() == false,
112-
r.status(),
113-
r.acknowledgeHeader(),
114-
r.acknowledgeMessages()),
115-
r -> new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
116-
r.isAcknowledged(),
117-
mutateStatus(r.status()),
118-
r.acknowledgeHeader(),
119-
r.acknowledgeMessages()),
120-
r -> {
121-
if (r.acknowledgeMessages().isEmpty()) {
122-
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
123-
r.isAcknowledged(),
124-
r.status(),
125-
randomAlphaOfLength(10),
126-
randomAckMessages()
127-
);
128-
} else {
129-
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(r.isAcknowledged(), r.status());
130-
}
131-
}
132-
133-
);
134-
return mutator.apply(response);
135-
}
136-
137-
private org.elasticsearch.protocol.xpack.license.LicensesStatus mutateStatus(
138-
org.elasticsearch.protocol.xpack.license.LicensesStatus status) {
139-
return randomValueOtherThan(status, () -> randomFrom(LicensesStatus.values()));
80+
protected void assertInstances(org.elasticsearch.protocol.xpack.license.PutLicenseResponse serverTestInstance,
81+
PutLicenseResponse clientInstance) {
82+
assertThat(serverTestInstance.status().name(), equalTo(clientInstance.status().name()));
83+
assertThat(serverTestInstance.acknowledgeHeader(), equalTo(clientInstance.acknowledgeHeader()));
84+
assertThat(serverTestInstance.acknowledgeMessages().keySet(), equalTo(clientInstance.acknowledgeMessages().keySet()));
85+
for(Map.Entry<String, String[]> entry: serverTestInstance.acknowledgeMessages().entrySet()) {
86+
assertTrue(Arrays.equals(entry.getValue(), clientInstance.acknowledgeMessages().get(entry.getKey())));
87+
}
14088
}
14189
}

client/rest-high-level/src/test/java/org/elasticsearch/client/license/StartBasicResponseTests.java

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,24 @@
1818
*/
1919
package org.elasticsearch.client.license;
2020

21-
import org.elasticsearch.client.AbstractHlrcWriteableXContentTestCase;
22-
import org.elasticsearch.common.Strings;
23-
import org.elasticsearch.common.io.stream.Writeable;
21+
import org.elasticsearch.client.AbstractResponseTestCase;
2422
import org.elasticsearch.common.xcontent.XContentParser;
23+
import org.elasticsearch.common.xcontent.XContentType;
2524
import org.elasticsearch.license.PostStartBasicResponse;
2625

2726
import java.io.IOException;
27+
import java.util.Arrays;
2828
import java.util.Collections;
2929
import java.util.HashMap;
3030
import java.util.Map;
31-
import java.util.function.Predicate;
3231

33-
public class StartBasicResponseTests extends AbstractHlrcWriteableXContentTestCase<
34-
PostStartBasicResponse, StartBasicResponse> {
35-
36-
@Override
37-
public org.elasticsearch.client.license.StartBasicResponse doHlrcParseInstance(XContentParser parser) throws IOException {
38-
return org.elasticsearch.client.license.StartBasicResponse.fromXContent(parser);
39-
}
40-
41-
@Override
42-
public PostStartBasicResponse convertHlrcToInternal(org.elasticsearch.client.license.StartBasicResponse instance) {
43-
return new PostStartBasicResponse(PostStartBasicResponse.Status.valueOf(instance.getStatus().name()),
44-
instance.getAcknowledgeMessages(), instance.getAcknowledgeMessage());
45-
}
46-
47-
@Override
48-
protected Writeable.Reader<PostStartBasicResponse> instanceReader() {
49-
return PostStartBasicResponse::new;
50-
}
32+
import static org.hamcrest.Matchers.equalTo;
5133

52-
@Override
53-
protected boolean supportsUnknownFields() {
54-
return true;
55-
}
56-
57-
@Override
58-
protected Predicate<String> getRandomFieldsExcludeFilter() {
59-
// The structure of the response is such that unknown fields inside acknowledge cannot be supported since they
60-
// are treated as messages from new services
61-
return p -> p.startsWith("acknowledge");
62-
}
34+
public class StartBasicResponseTests extends AbstractResponseTestCase<
35+
PostStartBasicResponse, StartBasicResponse> {
6336

6437
@Override
65-
protected PostStartBasicResponse createTestInstance() {
38+
protected PostStartBasicResponse createServerTestInstance(XContentType xContentType) {
6639
PostStartBasicResponse.Status status = randomFrom(PostStartBasicResponse.Status.values());
6740
String acknowledgeMessage = null;
6841
Map<String, String[]> ackMessages = Collections.emptyMap();
@@ -71,7 +44,6 @@ protected PostStartBasicResponse createTestInstance() {
7144
ackMessages = randomAckMessages();
7245
}
7346
final PostStartBasicResponse postStartBasicResponse = new PostStartBasicResponse(status, ackMessages, acknowledgeMessage);
74-
logger.info("{}", Strings.toString(postStartBasicResponse));
7547
return postStartBasicResponse;
7648
}
7749

@@ -92,4 +64,22 @@ private static Map<String, String[]> randomAckMessages() {
9264

9365
return ackMessages;
9466
}
67+
68+
@Override
69+
protected StartBasicResponse doParseToClientInstance(XContentParser parser) throws IOException {
70+
return StartBasicResponse.fromXContent(parser);
71+
}
72+
73+
@Override
74+
protected void assertInstances(PostStartBasicResponse serverTestInstance, StartBasicResponse clientInstance) {
75+
assertThat(serverTestInstance.getStatus().name(), equalTo(clientInstance.getStatus().name()));
76+
assertThat(serverTestInstance.getStatus().isBasicStarted(), equalTo(clientInstance.isBasicStarted()));
77+
assertThat(serverTestInstance.isAcknowledged(), equalTo(clientInstance.isAcknowledged()));
78+
assertThat(serverTestInstance.getStatus().getErrorMessage(), equalTo(clientInstance.getErrorMessage()));
79+
assertThat(serverTestInstance.getAcknowledgeMessage(), equalTo(clientInstance.getAcknowledgeMessage()));
80+
assertThat(serverTestInstance.getAcknowledgeMessages().keySet(), equalTo(clientInstance.getAcknowledgeMessages().keySet()));
81+
for(Map.Entry<String, String[]> entry: serverTestInstance.getAcknowledgeMessages().entrySet()) {
82+
assertTrue(Arrays.equals(entry.getValue(), clientInstance.getAcknowledgeMessages().get(entry.getKey())));
83+
}
84+
}
9585
}

x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartBasicResponse.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public enum Status {
4444
this.restStatus = restStatus;
4545
}
4646

47-
boolean isBasicStarted() {
47+
public boolean isBasicStarted() {
4848
return isBasicStarted;
4949
}
5050

51-
String getErrorMessage() {
51+
public String getErrorMessage() {
5252
return errorMessage;
5353
}
5454

@@ -134,6 +134,14 @@ public RestStatus status() {
134134
return status.restStatus;
135135
}
136136

137+
public String getAcknowledgeMessage() {
138+
return acknowledgeMessage;
139+
}
140+
141+
public Map<String, String[]> getAcknowledgeMessages() {
142+
return acknowledgeMessages;
143+
}
144+
137145
@Override
138146
public boolean equals(Object o) {
139147
if (this == o) return true;

0 commit comments

Comments
 (0)