Skip to content

Commit

Permalink
Remove deprecated test from the HLRC tests
Browse files Browse the repository at this point in the history
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 elastic#39745
  • Loading branch information
hub-cap committed Oct 23, 2019
1 parent df83eb9 commit 6910863
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 176 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,23 @@
*/
package org.elasticsearch.client.license;

import org.elasticsearch.client.AbstractHlrcWriteableXContentTestCase;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.client.AbstractResponseTestCase;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.xpack.license.LicensesStatus;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;

public class PutLicenseResponseTests extends AbstractHlrcWriteableXContentTestCase<
org.elasticsearch.protocol.xpack.license.PutLicenseResponse, PutLicenseResponse> {

@Override
public org.elasticsearch.client.license.PutLicenseResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.license.PutLicenseResponse.fromXContent(parser);
}

@Override
public org.elasticsearch.protocol.xpack.license.PutLicenseResponse convertHlrcToInternal(
org.elasticsearch.client.license.PutLicenseResponse instance) {
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(instance.isAcknowledged(),
org.elasticsearch.protocol.xpack.license.LicensesStatus.valueOf(instance.status().name()),
instance.acknowledgeHeader(), instance.acknowledgeMessages());
}

@Override
protected boolean supportsUnknownFields() {
return true;
}
import static org.hamcrest.Matchers.equalTo;

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

@Override
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createTestInstance() {
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createServerTestInstance(XContentType xContentType) {
boolean acknowledged = randomBoolean();
org.elasticsearch.protocol.xpack.license.LicensesStatus status =
randomFrom(org.elasticsearch.protocol.xpack.license.LicensesStatus.VALID,
Expand Down Expand Up @@ -97,45 +72,18 @@ private static Map<String, String[]> randomAckMessages() {
}

@Override
protected Writeable.Reader<org.elasticsearch.protocol.xpack.license.PutLicenseResponse> instanceReader() {
return org.elasticsearch.protocol.xpack.license.PutLicenseResponse::new;
protected PutLicenseResponse doParseToClientInstance(XContentParser parser) throws IOException {
return PutLicenseResponse.fromXContent(parser);
}

@Override
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse mutateInstance(
org.elasticsearch.protocol.xpack.license.PutLicenseResponse response) {
@SuppressWarnings("unchecked")
Function<org.elasticsearch.protocol.xpack.license.PutLicenseResponse,
org.elasticsearch.protocol.xpack.license.PutLicenseResponse> mutator = randomFrom(
r -> new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
r.isAcknowledged() == false,
r.status(),
r.acknowledgeHeader(),
r.acknowledgeMessages()),
r -> new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
r.isAcknowledged(),
mutateStatus(r.status()),
r.acknowledgeHeader(),
r.acknowledgeMessages()),
r -> {
if (r.acknowledgeMessages().isEmpty()) {
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
r.isAcknowledged(),
r.status(),
randomAlphaOfLength(10),
randomAckMessages()
);
} else {
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(r.isAcknowledged(), r.status());
}
}

);
return mutator.apply(response);
}

private org.elasticsearch.protocol.xpack.license.LicensesStatus mutateStatus(
org.elasticsearch.protocol.xpack.license.LicensesStatus status) {
return randomValueOtherThan(status, () -> randomFrom(LicensesStatus.values()));
protected void assertInstances(org.elasticsearch.protocol.xpack.license.PutLicenseResponse serverTestInstance,
PutLicenseResponse clientInstance) {
assertThat(serverTestInstance.status().name(), equalTo(clientInstance.status().name()));
assertThat(serverTestInstance.acknowledgeHeader(), equalTo(clientInstance.acknowledgeHeader()));
assertThat(serverTestInstance.acknowledgeMessages().keySet(), equalTo(clientInstance.acknowledgeMessages().keySet()));
for(Map.Entry<String, String[]> entry: serverTestInstance.acknowledgeMessages().entrySet()) {
assertTrue(Arrays.equals(entry.getValue(), clientInstance.acknowledgeMessages().get(entry.getKey())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,24 @@
*/
package org.elasticsearch.client.license;

import org.elasticsearch.client.AbstractHlrcWriteableXContentTestCase;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.client.AbstractResponseTestCase;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.license.PostStartBasicResponse;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;

public class StartBasicResponseTests extends AbstractHlrcWriteableXContentTestCase<
PostStartBasicResponse, StartBasicResponse> {

@Override
public org.elasticsearch.client.license.StartBasicResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.license.StartBasicResponse.fromXContent(parser);
}

@Override
public PostStartBasicResponse convertHlrcToInternal(org.elasticsearch.client.license.StartBasicResponse instance) {
return new PostStartBasicResponse(PostStartBasicResponse.Status.valueOf(instance.getStatus().name()),
instance.getAcknowledgeMessages(), instance.getAcknowledgeMessage());
}

@Override
protected Writeable.Reader<PostStartBasicResponse> instanceReader() {
return PostStartBasicResponse::new;
}
import static org.hamcrest.Matchers.equalTo;

@Override
protected boolean supportsUnknownFields() {
return true;
}

@Override
protected Predicate<String> getRandomFieldsExcludeFilter() {
// The structure of the response is such that unknown fields inside acknowledge cannot be supported since they
// are treated as messages from new services
return p -> p.startsWith("acknowledge");
}
public class StartBasicResponseTests extends AbstractResponseTestCase<
PostStartBasicResponse, StartBasicResponse> {

@Override
protected PostStartBasicResponse createTestInstance() {
protected PostStartBasicResponse createServerTestInstance(XContentType xContentType) {
PostStartBasicResponse.Status status = randomFrom(PostStartBasicResponse.Status.values());
String acknowledgeMessage = null;
Map<String, String[]> ackMessages = Collections.emptyMap();
Expand All @@ -71,7 +44,6 @@ protected PostStartBasicResponse createTestInstance() {
ackMessages = randomAckMessages();
}
final PostStartBasicResponse postStartBasicResponse = new PostStartBasicResponse(status, ackMessages, acknowledgeMessage);
logger.info("{}", Strings.toString(postStartBasicResponse));
return postStartBasicResponse;
}

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

return ackMessages;
}

@Override
protected StartBasicResponse doParseToClientInstance(XContentParser parser) throws IOException {
return StartBasicResponse.fromXContent(parser);
}

@Override
protected void assertInstances(PostStartBasicResponse serverTestInstance, StartBasicResponse clientInstance) {
assertThat(serverTestInstance.getStatus().name(), equalTo(clientInstance.getStatus().name()));
assertThat(serverTestInstance.getStatus().isBasicStarted(), equalTo(clientInstance.isBasicStarted()));
assertThat(serverTestInstance.isAcknowledged(), equalTo(clientInstance.isAcknowledged()));
assertThat(serverTestInstance.getStatus().getErrorMessage(), equalTo(clientInstance.getErrorMessage()));
assertThat(serverTestInstance.getAcknowledgeMessage(), equalTo(clientInstance.getAcknowledgeMessage()));
assertThat(serverTestInstance.getAcknowledgeMessages().keySet(), equalTo(clientInstance.getAcknowledgeMessages().keySet()));
for(Map.Entry<String, String[]> entry: serverTestInstance.getAcknowledgeMessages().entrySet()) {
assertTrue(Arrays.equals(entry.getValue(), clientInstance.getAcknowledgeMessages().get(entry.getKey())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public enum Status {
this.restStatus = restStatus;
}

boolean isBasicStarted() {
public boolean isBasicStarted() {
return isBasicStarted;
}

String getErrorMessage() {
public String getErrorMessage() {
return errorMessage;
}

Expand Down Expand Up @@ -134,6 +134,14 @@ public RestStatus status() {
return status.restStatus;
}

public String getAcknowledgeMessage() {
return acknowledgeMessage;
}

public Map<String, String[]> getAcknowledgeMessages() {
return acknowledgeMessages;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down

0 comments on commit 6910863

Please sign in to comment.