diff --git a/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java b/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java index 37a3c556804e0..aee9f0859005a 100644 --- a/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java +++ b/server/src/test/java/org/opensearch/action/support/IndicesOptionsTests.java @@ -142,6 +142,35 @@ public void testFromOptions() { } } + public void testIllegalArgumentExceptionForClosedIndices() { + final boolean ignoreUnavailable = randomBoolean(); + final boolean allowNoIndices = randomBoolean(); + final boolean expandToOpenIndices = randomBoolean(); + final boolean expandToClosedIndices = true; + final boolean expandToHiddenIndices = randomBoolean(); + final boolean allowAliasesToMultipleIndices = randomBoolean(); + final boolean forbidClosedIndices = true; + final boolean ignoreAliases = randomBoolean(); + final boolean ignoreThrottled = randomBoolean(); + + IllegalArgumentException iae = expectThrows( + IllegalArgumentException.class, + () -> IndicesOptions.fromOptions( + ignoreUnavailable, + allowNoIndices, + expandToOpenIndices, + expandToClosedIndices, + expandToHiddenIndices, + allowAliasesToMultipleIndices, + forbidClosedIndices, + ignoreAliases, + ignoreThrottled + ) + ); + String expectedMessage = "To expand [" + WildcardStates.CLOSED + "] wildcard, please set forbid_closed_indices to `false` "; + assertEquals(expectedMessage, iae.getMessage()); + } + public void testFromOptionsWithDefaultOptions() { boolean ignoreUnavailable = randomBoolean(); boolean allowNoIndices = randomBoolean();