From 3126fcb856683f546342d09cfa3526dab212fdb1 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Fri, 1 Apr 2016 14:20:03 -0400 Subject: [PATCH] Improved tests with better error message Original commit: elastic/x-pack-elasticsearch@cb79988dc346a1e33d1d9b6255b9cb6e00d74720 --- .../plugin/core/AbstractLicenseeTestCase.java | 14 +++++++++++++- .../marvel/license/MarvelLicenseeTests.java | 7 +++++-- .../shield/license/ShieldLicenseeTests.java | 11 +++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java index 8e7a247c0fe..b1dc8a942ae 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java @@ -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 licensees = new ArrayList<>(); private OperationMode operationMode; diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java index 6462e003259..7e1eb108c72 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java @@ -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() { diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java index f8f3b2f4724..5f12556ef34 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java @@ -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() {