|
18 | 18 | */ |
19 | 19 | package org.elasticsearch.client.license; |
20 | 20 |
|
21 | | -import org.elasticsearch.client.AbstractHlrcWriteableXContentTestCase; |
22 | | -import org.elasticsearch.common.io.stream.Writeable; |
| 21 | +import org.elasticsearch.client.AbstractResponseTestCase; |
23 | 22 | import org.elasticsearch.common.xcontent.XContentParser; |
24 | | -import org.elasticsearch.protocol.xpack.license.LicensesStatus; |
| 23 | +import org.elasticsearch.common.xcontent.XContentType; |
25 | 24 |
|
26 | 25 | import java.io.IOException; |
| 26 | +import java.util.Arrays; |
27 | 27 | import java.util.Collections; |
28 | 28 | import java.util.HashMap; |
29 | 29 | import java.util.Map; |
30 | | -import java.util.function.Function; |
31 | | -import java.util.function.Predicate; |
32 | 30 |
|
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; |
53 | 32 |
|
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> { |
60 | 35 |
|
61 | 36 | @Override |
62 | | - protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createTestInstance() { |
| 37 | + protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createServerTestInstance(XContentType xContentType) { |
63 | 38 | boolean acknowledged = randomBoolean(); |
64 | 39 | org.elasticsearch.protocol.xpack.license.LicensesStatus status = |
65 | 40 | randomFrom(org.elasticsearch.protocol.xpack.license.LicensesStatus.VALID, |
@@ -97,45 +72,18 @@ private static Map<String, String[]> randomAckMessages() { |
97 | 72 | } |
98 | 73 |
|
99 | 74 | @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); |
102 | 77 | } |
103 | 78 |
|
104 | 79 | @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 | + } |
140 | 88 | } |
141 | 89 | } |
0 commit comments