-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daulet <[email protected]>
- Loading branch information
1 parent
3ca9c0b
commit 3b5cac9
Showing
2 changed files
with
96 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* 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.sdk; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
import org.opensearch.common.bytes.BytesArray; | ||
import org.opensearch.common.bytes.BytesReference; | ||
import org.opensearch.common.xcontent.XContentType; | ||
import org.opensearch.extensions.rest.ExtensionRestRequest; | ||
import org.opensearch.http.HttpRequest; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.RestRequest.Method; | ||
import org.opensearch.sdk.rest.SDKHttpRequest; | ||
import org.opensearch.sdk.rest.SDKRestRequest; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import static java.util.Map.entry; | ||
|
||
public class TestSDKRestRequest extends OpenSearchTestCase { | ||
@Test | ||
public void TestSDKRestRequestMethods() { | ||
RestRequest.Method expectedMethod = Method.GET; | ||
String expectedUri = "foobar?foo=bar&baz=42"; | ||
String expectedPath = "foo"; | ||
Map<String, String> expectedParams = Map.ofEntries(entry("foo", "bar"), entry("baz", "42")); | ||
Map<String, List<String>> expectedHeaders = Map.ofEntries(entry("foo", Arrays.asList("hello", "world"))); | ||
XContentType exptectedXContentType = null; | ||
BytesReference expectedContent = new BytesArray("bar"); | ||
|
||
SDKRestRequest sdkRestRequest = createTestRestRequest( | ||
expectedMethod, | ||
expectedUri, | ||
expectedPath, | ||
expectedParams, | ||
expectedHeaders, | ||
exptectedXContentType, | ||
expectedContent, | ||
"", | ||
null | ||
); | ||
assertEquals(expectedMethod, sdkRestRequest.method()); | ||
assertEquals(expectedUri, sdkRestRequest.uri()); | ||
assertEquals(expectedPath, sdkRestRequest.path()); | ||
assertEquals(expectedParams, sdkRestRequest.params()); | ||
assertEquals(expectedHeaders, sdkRestRequest.getHeaders()); | ||
assertEquals(expectedContent, sdkRestRequest.content()); | ||
} | ||
|
||
public static RestRequest createTestRestRequest( | ||
final Method method, | ||
final String uri, | ||
final String path, | ||
final Map<String, String> params, | ||
final Map<String, String> headers, | ||
final XContentType xContentType, | ||
final BytesReference content, | ||
final String principalIdentifier, | ||
final HttpRequest.HttpVersion httpVersion | ||
) { | ||
ExtensionRestRequest request = new ExtensionRestRequest( | ||
method, | ||
uri, | ||
path, | ||
params, | ||
headers, | ||
xContentType, | ||
content, | ||
principalIdentifier, | ||
httpVersion | ||
); | ||
return new SDKRestRequest(null, request.params(), request.path(), request.headers(), new SDKHttpRequest(request), null); | ||
} | ||
} |