forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegisterRestActionsTests.java
62 lines (50 loc) · 2.58 KB
/
RegisterRestActionsTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.extensions.rest;
import java.util.List;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.io.stream.BytesStreamInput;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.test.OpenSearchTestCase;
public class RegisterRestActionsTests extends OpenSearchTestCase {
public void testRegisterRestActionsRequest() throws Exception {
String uniqueIdStr = "uniqueid1";
List<String> expected = List.of("GET /foo", "PUT /bar", "POST /baz");
RegisterRestActionsRequest registerRestActionsRequest = new RegisterRestActionsRequest(uniqueIdStr, expected);
assertEquals(uniqueIdStr, registerRestActionsRequest.getUniqueId());
List<String> restActions = registerRestActionsRequest.getRestActions();
assertEquals(expected.size(), restActions.size());
assertTrue(restActions.containsAll(expected));
assertTrue(expected.containsAll(restActions));
try (BytesStreamOutput out = new BytesStreamOutput()) {
registerRestActionsRequest.writeTo(out);
out.flush();
try (BytesStreamInput in = new BytesStreamInput(BytesReference.toBytes(out.bytes()))) {
registerRestActionsRequest = new RegisterRestActionsRequest(in);
assertEquals(uniqueIdStr, registerRestActionsRequest.getUniqueId());
restActions = registerRestActionsRequest.getRestActions();
assertEquals(expected.size(), restActions.size());
assertTrue(restActions.containsAll(expected));
assertTrue(expected.containsAll(restActions));
}
}
}
public void testRegisterRestActionsResponse() throws Exception {
String response = "This is a response";
RegisterRestActionsResponse registerRestActionsResponse = new RegisterRestActionsResponse(response);
assertEquals(response, registerRestActionsResponse.getResponse());
try (BytesStreamOutput out = new BytesStreamOutput()) {
registerRestActionsResponse.writeTo(out);
out.flush();
try (BytesStreamInput in = new BytesStreamInput(BytesReference.toBytes(out.bytes()))) {
registerRestActionsResponse = new RegisterRestActionsResponse(in);
assertEquals(response, registerRestActionsResponse.getResponse());
}
}
}
}