forked from opensearch-project/opensearch-java
-
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.
Made InlineGet source field nullable (opensearch-project#1046)
Addresses bug in opensearch-project#1042 Signed-off-by: Brendon Faleiro <faleiro@amazon.com> Co-authored-by: Brendon Faleiro <faleiro@amazon.com> (cherry picked from commit 69aa51c)
- Loading branch information
1 parent
ef92971
commit b6e98fe
Showing
3 changed files
with
67 additions
and
6 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
55 changes: 55 additions & 0 deletions
55
java-client/src/test/java/org/opensearch/client/opensearch/_types/InlineGetTest.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,55 @@ | ||
/* | ||
* 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.client.opensearch._types; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import jakarta.json.stream.JsonParser; | ||
import java.io.StringReader; | ||
import org.junit.Test; | ||
import org.opensearch.client.json.JsonpDeserializer; | ||
import org.opensearch.client.json.jackson.JacksonJsonpMapper; | ||
|
||
public class InlineGetTest { | ||
@Test | ||
public void testInlineGet_withSource() { | ||
final InlineGet inlineGet = InlineGet.of( | ||
b -> b.found(true).seqNo(1L).primaryTerm(2L).routing("routing").source("{\"name\":\"John Doe\"}") | ||
); | ||
|
||
final String jsonString = "{\"found\":true,\"_seq_no\":1,\"_primary_term\":2,\"_routing\":\"routing\"," | ||
+ "\"_source\":\"{\\\"name\\\":\\\"John Doe\\\"}\"}"; | ||
|
||
final StringReader reader = new StringReader(jsonString); | ||
final JacksonJsonpMapper mapper = new JacksonJsonpMapper(); | ||
final JsonParser parser = mapper.jsonProvider().createParser(reader); | ||
final InlineGet actual = InlineGet.createInlineGetDeserializer(JsonpDeserializer.stringDeserializer()).deserialize(parser, mapper); | ||
assertEquals(inlineGet.found(), actual.found()); | ||
assertEquals(inlineGet.seqNo(), actual.seqNo()); | ||
assertEquals(inlineGet.primaryTerm(), actual.primaryTerm()); | ||
assertEquals(inlineGet.routing(), actual.routing()); | ||
assertEquals(inlineGet.source(), actual.source()); | ||
} | ||
|
||
@Test | ||
public void testInlineGet_withoutSource() { | ||
final InlineGet inlineGet = InlineGet.of(b -> b.found(true).seqNo(1L).primaryTerm(2L).routing("routing")); | ||
|
||
final String jsonString = "{\"found\":true,\"_seq_no\":1,\"_primary_term\":2,\"_routing\":\"routing\"}"; | ||
|
||
final StringReader reader = new StringReader(jsonString); | ||
final JacksonJsonpMapper mapper = new JacksonJsonpMapper(); | ||
final JsonParser parser = mapper.jsonProvider().createParser(reader); | ||
final InlineGet actual = InlineGet.createInlineGetDeserializer(JsonpDeserializer.stringDeserializer()).deserialize(parser, mapper); | ||
assertEquals(inlineGet.found(), actual.found()); | ||
assertEquals(inlineGet.seqNo(), actual.seqNo()); | ||
assertEquals(inlineGet.primaryTerm(), actual.primaryTerm()); | ||
assertEquals(inlineGet.routing(), actual.routing()); | ||
} | ||
} |