|
47 | 47 |
|
48 | 48 | import java.io.IOException;
|
49 | 49 | import java.util.ArrayList;
|
| 50 | +import java.util.Arrays; |
50 | 51 | import java.util.Collections;
|
51 | 52 | import java.util.HashMap;
|
52 | 53 | import java.util.List;
|
@@ -280,6 +281,34 @@ public void testRequiredContent() {
|
280 | 281 | assertEquals("unknown content type", e.getMessage());
|
281 | 282 | }
|
282 | 283 |
|
| 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 | + |
283 | 312 | private static RestRequest contentRestRequest(String content, Map<String, String> params) {
|
284 | 313 | Map<String, List<String>> headers = new HashMap<>();
|
285 | 314 | headers.put("Content-Type", Collections.singletonList("application/json"));
|
|
0 commit comments