Skip to content

Commit 8e0e074

Browse files
author
Tianli Feng
committed
Add unit test for the temporary method ValidateParamValuesAreEqual()
Signed-off-by: Tianli Feng <ftianli@amazon.com>
1 parent aa50d4f commit 8e0e074

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

server/src/test/java/org/opensearch/rest/RestRequestTests.java

+29
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
import java.io.IOException;
4949
import java.util.ArrayList;
50+
import java.util.Arrays;
5051
import java.util.Collections;
5152
import java.util.HashMap;
5253
import java.util.List;
@@ -280,6 +281,34 @@ public void testRequiredContent() {
280281
assertEquals("unknown content type", e.getMessage());
281282
}
282283

284+
/*
285+
* The test is added in 2.0 when the request parameter "cluster_manager_timeout" is introduced.
286+
* Remove the test along with the removal of the non-inclusive terminology "master_timeout".
287+
*/
288+
public void testValidateParamValuesAreEqual() {
289+
FakeRestRequest request = new FakeRestRequest();
290+
List<String> valueList = new ArrayList<>(Arrays.asList(null, "value1", "value2"));
291+
String valueForKey1 = randomFrom(valueList);
292+
String valueForKey2 = randomFrom(valueList);
293+
request.params().put("key1", valueForKey1);
294+
request.params().put("key2", valueForKey2);
295+
try {
296+
request.validateParamValuesAreEqual("key1", "key2");
297+
} catch (OpenSearchParseException e) {
298+
assertEquals(
299+
"The values of the request parameters: [key1, key2] are required to be equal, otherwise please only assign value to one of the request parameters.",
300+
e.getMessage()
301+
);
302+
assertNotEquals(valueForKey1, valueForKey2);
303+
assertNotNull(valueForKey1);
304+
assertNotNull(valueForKey2);
305+
}
306+
assertTrue(
307+
"The 2 keys should be either equal, or having null value.",
308+
valueForKey1 == null || valueForKey2 == null || valueForKey1.equals(valueForKey2)
309+
);
310+
}
311+
283312
private static RestRequest contentRestRequest(String content, Map<String, String> params) {
284313
Map<String, List<String>> headers = new HashMap<>();
285314
headers.put("Content-Type", Collections.singletonList("application/json"));

0 commit comments

Comments
 (0)