-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PutTemplateRequest deserialization (#723)
* fix PutTemplateRequest deserialization Signed-off-by: bfindlay <bfindlay@acm.org> * update changelog Signed-off-by: bfindlay <bfindlay@acm.org> * fix changelog PR number Signed-off-by: bfindlay <bfindlay@acm.org> * update for pr review Signed-off-by: bfindlay <bfindlay@acm.org> * update unit test for pr Signed-off-by: bfindlay <bfindlay@acm.org> * apply spotless check Signed-off-by: bfindlay <bfindlay@acm.org> --------- Signed-off-by: bfindlay <bfindlay@acm.org>
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 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
31 changes: 31 additions & 0 deletions
31
java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.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,31 @@ | ||
package org.opensearch.client.opensearch.core; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.StringReader; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.opensearch.client.json.JsonpMapper; | ||
import org.opensearch.client.json.jsonb.JsonbJsonpMapper; | ||
import org.opensearch.client.opensearch.indices.PutTemplateRequest; | ||
|
||
public class PutTemplateRequestTest extends Assert { | ||
|
||
@Test | ||
public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException { | ||
final JsonpMapper mapper = new JsonbJsonpMapper(); | ||
final Map<String, Object> indexTemplateMap = Map.of("name", "test", "index_patterns", "*", "create", true, "order", 1); | ||
|
||
final String indexTemplate = new ObjectMapper().writeValueAsString(indexTemplateMap); | ||
final var parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate)); | ||
|
||
final PutTemplateRequest putTemplateRequest = PutTemplateRequest._DESERIALIZER.deserialize(parser, mapper); | ||
|
||
assertEquals(putTemplateRequest.name(), "test"); | ||
assertEquals(putTemplateRequest.indexPatterns(), List.of("*")); | ||
assertEquals((int) putTemplateRequest.order(), 1); | ||
assertEquals(putTemplateRequest.create(), true); | ||
} | ||
} |