Skip to content

Commit f0dda05

Browse files
Fix create_index/create_index_with_IOException issue caused by OpenSearch PR change (#1899)
* Added setDefaultMediaType for create_index and create_index_with_IOException Signed-off-by: Mitchell Gale <[email protected]> (cherry picked from commit 7b932a7) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 031183d commit f0dda05

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

opensearch/src/test/java/org/opensearch/sql/opensearch/client/OpenSearchRestClientTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.mockito.Mockito.never;
2020
import static org.mockito.Mockito.verify;
2121
import static org.mockito.Mockito.when;
22+
import static org.opensearch.core.xcontent.MediaTypeParserRegistry.setDefaultMediaType;
2223
import static org.opensearch.sql.opensearch.client.OpenSearchClient.META_CLUSTER_NAME;
2324
import static org.opensearch.sql.opensearch.data.type.OpenSearchDataType.MappingType;
2425

@@ -34,6 +35,7 @@
3435
import lombok.SneakyThrows;
3536
import org.apache.commons.lang3.reflect.FieldUtils;
3637
import org.apache.lucene.search.TotalHits;
38+
import org.junit.jupiter.api.BeforeAll;
3739
import org.junit.jupiter.api.BeforeEach;
3840
import org.junit.jupiter.api.DisplayNameGeneration;
3941
import org.junit.jupiter.api.DisplayNameGenerator;
@@ -101,6 +103,11 @@ void setUp() {
101103
client = new OpenSearchRestClient(restClient);
102104
}
103105

106+
@BeforeAll
107+
static void setUpJSON() {
108+
setDefaultMediaType(XContentType.JSON);
109+
}
110+
104111
@Test
105112
void is_index_exist() throws IOException {
106113
when(restClient.indices()
@@ -142,7 +149,6 @@ void create_index() throws IOException {
142149
@Test
143150
void create_index_with_IOException() throws IOException {
144151
when(restClient.indices().create(any(), any())).thenThrow(IOException.class);
145-
146152
assertThrows(IllegalStateException.class,
147153
() -> client.createIndex("test", ImmutableMap.of()));
148154
}

0 commit comments

Comments
 (0)