diff --git a/server/src/test/java/org/opensearch/rest/RestRequestTests.java b/server/src/test/java/org/opensearch/rest/RestRequestTests.java index 7abc53e4ca610..99e6c7bf0ea70 100644 --- a/server/src/test/java/org/opensearch/rest/RestRequestTests.java +++ b/server/src/test/java/org/opensearch/rest/RestRequestTests.java @@ -47,6 +47,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -280,6 +281,34 @@ public void testRequiredContent() { assertEquals("unknown content type", e.getMessage()); } + /* + * The test is added in 2.0 when the request parameter "cluster_manager_timeout" is introduced. + * Remove the test along with the removal of the non-inclusive terminology "master_timeout". + */ + public void testValidateParamValuesAreEqual() { + FakeRestRequest request = new FakeRestRequest(); + List valueList = new ArrayList<>(Arrays.asList(null, "value1", "value2")); + String valueForKey1 = randomFrom(valueList); + String valueForKey2 = randomFrom(valueList); + request.params().put("key1", valueForKey1); + request.params().put("key2", valueForKey2); + try { + request.validateParamValuesAreEqual("key1", "key2"); + } catch (OpenSearchParseException e) { + assertEquals( + "The values of the request parameters: [key1, key2] are required to be equal, otherwise please only assign value to one of the request parameters.", + e.getMessage() + ); + assertNotEquals(valueForKey1, valueForKey2); + assertNotNull(valueForKey1); + assertNotNull(valueForKey2); + } + assertTrue( + "The 2 keys should be either equal, or having null value.", + valueForKey1 == null || valueForKey2 == null || valueForKey1.equals(valueForKey2) + ); + } + private static RestRequest contentRestRequest(String content, Map params) { Map> headers = new HashMap<>(); headers.put("Content-Type", Collections.singletonList("application/json"));