Skip to content

Commit

Permalink
Add unit test for the temporary method ValidateParamValuesAreEqual()
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <[email protected]>
  • Loading branch information
Tianli Feng committed Mar 15, 2022
1 parent aa50d4f commit 8e0e074
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions server/src/test/java/org/opensearch/rest/RestRequestTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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<String, String> params) {
Map<String, List<String>> headers = new HashMap<>();
headers.put("Content-Type", Collections.singletonList("application/json"));
Expand Down

0 comments on commit 8e0e074

Please sign in to comment.