forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
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: Peng Huo <penghuo@gmail.com>
- Loading branch information
Showing
5 changed files
with
69 additions
and
7 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
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
52 changes: 52 additions & 0 deletions
52
spark/src/test/java/org/opensearch/sql/spark/rest/model/CreateAsyncQueryRequestTest.java
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,52 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.rest.model; | ||
|
||
import java.io.IOException; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.common.xcontent.LoggingDeprecationHandler; | ||
import org.opensearch.common.xcontent.XContentType; | ||
import org.opensearch.core.xcontent.NamedXContentRegistry; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
|
||
public class CreateAsyncQueryRequestTest { | ||
|
||
@Test | ||
public void fromXContent() throws IOException { | ||
String request = | ||
"{\n" | ||
+ " \"datasource\": \"my_glue\",\n" | ||
+ " \"lang\": \"sql\",\n" | ||
+ " \"query\": \"select 1\"\n" | ||
+ "}"; | ||
CreateAsyncQueryRequest queryRequest = | ||
CreateAsyncQueryRequest.fromXContentParser(xContentParser(request)); | ||
Assertions.assertEquals("my_glue", queryRequest.getDatasource()); | ||
Assertions.assertEquals(LangType.SQL, queryRequest.getLang()); | ||
Assertions.assertEquals("select 1", queryRequest.getQuery()); | ||
} | ||
|
||
@Test | ||
public void fromXContentWithSessionId() throws IOException { | ||
String request = | ||
"{\n" | ||
+ " \"datasource\": \"my_glue\",\n" | ||
+ " \"lang\": \"sql\",\n" | ||
+ " \"query\": \"select 1\",\n" | ||
+ " \"sessionId\": \"00fdjevgkf12s00q\"\n" | ||
+ "}"; | ||
CreateAsyncQueryRequest queryRequest = | ||
CreateAsyncQueryRequest.fromXContentParser(xContentParser(request)); | ||
Assertions.assertEquals("00fdjevgkf12s00q", queryRequest.getSessionId()); | ||
} | ||
|
||
private XContentParser xContentParser(String request) throws IOException { | ||
return XContentType.JSON | ||
.xContent() | ||
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, request); | ||
} | ||
} |
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