Improved tests with better error message
Original commit: elastic/x-pack-elasticsearch@cb79988dc3
This commit is contained in:
parent
05811c5167
commit
3126fcb856
|
@ -14,6 +14,7 @@ import org.elasticsearch.test.ESTestCase;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -50,7 +51,7 @@ public abstract class AbstractLicenseeTestCase extends ESTestCase {
|
|||
// test it
|
||||
String[] messages = licensee.acknowledgmentMessages(fromLicense, toLicense);
|
||||
|
||||
assertThat(messages.length, equalTo(0));
|
||||
assertThat(fromToMessage(fromMode, toMode), messages.length, equalTo(0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,6 +158,17 @@ public abstract class AbstractLicenseeTestCase extends ESTestCase {
|
|||
return randomFrom(Arrays.stream(values).filter(filter).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message to show with assertions for license transition.
|
||||
*
|
||||
* @param fromMode Coming "from" mode
|
||||
* @param toMode Going "to" mode
|
||||
* @return Never {@code null}.
|
||||
*/
|
||||
public static String fromToMessage(OperationMode fromMode, OperationMode toMode) {
|
||||
return String.format(Locale.ROOT, "From [%s] to [%s]", fromMode, toMode);
|
||||
}
|
||||
|
||||
public static class SimpleLicenseeRegistry extends AbstractComponent implements LicenseeRegistry {
|
||||
private final List<Licensee> licensees = new ArrayList<>();
|
||||
private OperationMode operationMode;
|
||||
|
|
|
@ -38,10 +38,13 @@ public class MarvelLicenseeTests extends AbstractLicenseeTestCase {
|
|||
}
|
||||
|
||||
public void testAcknowledgementMessagesToBasicFromNotBasicNotesLimits() {
|
||||
String[] messages = ackLicenseChange(randomModeExcept(OperationMode.BASIC), OperationMode.BASIC, licensee);
|
||||
OperationMode from = randomModeExcept(OperationMode.BASIC);
|
||||
OperationMode to = OperationMode.BASIC;
|
||||
|
||||
String[] messages = ackLicenseChange(from, to, licensee);
|
||||
|
||||
// leaving messages up to inspection
|
||||
assertThat(messages.length, equalTo(2));
|
||||
assertThat(fromToMessage(from, to), messages.length, equalTo(2));
|
||||
}
|
||||
|
||||
public void testCollectionEnabledIsTrueForActiveState() {
|
||||
|
|
|
@ -58,8 +58,8 @@ public class ShieldLicenseeTests extends AbstractLicenseeTestCase {
|
|||
verifyNoMoreInteractions(registry, shieldState);
|
||||
}
|
||||
|
||||
public void testAcknowledgementMessagesFromBasicToAnyIsNoOp() {
|
||||
assertEmptyAck(OperationMode.BASIC, randomMode(), this::buildLicensee);
|
||||
public void testAcknowledgementMessagesFromBasicToAnyNotGoldIsNoOp() {
|
||||
assertEmptyAck(OperationMode.BASIC, randomModeExcept(OperationMode.GOLD), this::buildLicensee);
|
||||
}
|
||||
|
||||
public void testAcknowledgementMessagesFromAnyToTrialOrPlatinumIsNoOp() {
|
||||
|
@ -67,10 +67,13 @@ public class ShieldLicenseeTests extends AbstractLicenseeTestCase {
|
|||
}
|
||||
|
||||
public void testAcknowledgementMessagesFromTrialStandardGoldOrPlatinumToBasicNotesLimits() {
|
||||
String[] messages = ackLicenseChange(randomTrialStandardGoldOrPlatinumMode(), OperationMode.BASIC, this::buildLicensee);
|
||||
OperationMode from = randomTrialStandardGoldOrPlatinumMode();
|
||||
OperationMode to = OperationMode.BASIC;
|
||||
|
||||
String[] messages = ackLicenseChange(from, to, this::buildLicensee);
|
||||
|
||||
// leaving messages up to inspection
|
||||
assertThat(messages.length, equalTo(3));
|
||||
assertThat(fromToMessage(from, to), messages.length, equalTo(3));
|
||||
}
|
||||
|
||||
public void testAcknowledgementMessagesFromBasicStandardTrialOrPlatinumToGoldNotesLimits() {
|
||||
|
|
Loading…
Reference in New Issue