From 0e2f127dacf9122b76d0fdad8bf2caf84102c72a Mon Sep 17 00:00:00 2001 From: bfindlay Date: Mon, 13 Nov 2023 23:00:47 +1100 Subject: [PATCH 1/6] fix PutTemplateRequest deserialization Signed-off-by: bfindlay --- .../indices/PutTemplateRequest.java | 2 + .../core/PutTemplateRequestTest.java | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java index 9ba6e65283..295d840473 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java @@ -586,8 +586,10 @@ public PutTemplateRequest build() { protected static void setupPutTemplateRequestDeserializer(ObjectDeserializer op) { op.add(Builder::aliases, JsonpDeserializer.stringMapDeserializer(Alias._DESERIALIZER), "aliases"); + op.add(Builder::create, JsonpDeserializer.booleanDeserializer(), "create"); op.add(Builder::indexPatterns, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "index_patterns"); op.add(Builder::mappings, TypeMapping._DESERIALIZER, "mappings"); + op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name"); op.add(Builder::order, JsonpDeserializer.integerDeserializer(), "order"); op.add(Builder::settings, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "settings"); op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version"); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java new file mode 100644 index 0000000000..2787ac5bba --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java @@ -0,0 +1,47 @@ +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 { + private static String INDEX_NAME_FIELD = "name"; + private static String INDEX_PATTERNS_FIELD = "index_patterns"; + private static String CREATE_FIELD = "create"; + private static String ORDER_FIELD = "order"; + + @Test + public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException { + // Arrange + final JsonpMapper mapper = new JsonbJsonpMapper(); + final Map indexTemplateMap = Map.of( + INDEX_NAME_FIELD, + "test", + INDEX_PATTERNS_FIELD, + "*", + CREATE_FIELD, + true, + ORDER_FIELD, + 1 + + ); + final String indexTemplate = new ObjectMapper().writeValueAsString(indexTemplateMap); + final var parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate)); + + // Act + final PutTemplateRequest putTemplateRequest = PutTemplateRequest._DESERIALIZER.deserialize(parser, mapper); + + // Assert + assertEquals(putTemplateRequest.name(), "test"); + assertEquals(putTemplateRequest.indexPatterns(), List.of("*")); + assertEquals((long) putTemplateRequest.order(), 1L); + assertEquals(putTemplateRequest.create(), true); + } +} From e7bd82ef7ffd75f3f12ba372ddd81f4a136d38f6 Mon Sep 17 00:00:00 2001 From: bfindlay Date: Mon, 13 Nov 2023 23:21:06 +1100 Subject: [PATCH 2/6] update changelog Signed-off-by: bfindlay --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e91c2d05c..069a05b0cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Fixed - Fix version and build ([#254](https://github.com/opensearch-project/opensearch-java/pull/254)) +- Fix PutTemplateRequest field deserialization ([#417](https://github.com/opensearch-project/opensearch-java/pull/723)) ### Security From cfa11578b14e82a2c1fab019f6abe14c7fb6f5f8 Mon Sep 17 00:00:00 2001 From: bfindlay Date: Mon, 13 Nov 2023 23:26:56 +1100 Subject: [PATCH 3/6] fix changelog PR number Signed-off-by: bfindlay --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 069a05b0cf..62aaf86987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Fixed - Fix version and build ([#254](https://github.com/opensearch-project/opensearch-java/pull/254)) -- Fix PutTemplateRequest field deserialization ([#417](https://github.com/opensearch-project/opensearch-java/pull/723)) +- Fix PutTemplateRequest field deserialization ([#723](https://github.com/opensearch-project/opensearch-java/pull/723)) ### Security From 7744f3a55522cd9564727873848a72a8d2e3c3b5 Mon Sep 17 00:00:00 2001 From: bfindlay Date: Tue, 14 Nov 2023 08:40:14 +1100 Subject: [PATCH 4/6] update for pr review Signed-off-by: bfindlay --- .../opensearch/core/PutTemplateRequestTest.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java index 2787ac5bba..d981bef97d 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java @@ -12,33 +12,26 @@ import org.opensearch.client.opensearch.indices.PutTemplateRequest; public class PutTemplateRequestTest extends Assert { - private static String INDEX_NAME_FIELD = "name"; - private static String INDEX_PATTERNS_FIELD = "index_patterns"; - private static String CREATE_FIELD = "create"; - private static String ORDER_FIELD = "order"; @Test public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException { - // Arrange final JsonpMapper mapper = new JsonbJsonpMapper(); final Map indexTemplateMap = Map.of( - INDEX_NAME_FIELD, + "name", "test", - INDEX_PATTERNS_FIELD, + "index_patterns", "*", - CREATE_FIELD, + "create", true, - ORDER_FIELD, + "order", 1 ); final String indexTemplate = new ObjectMapper().writeValueAsString(indexTemplateMap); final var parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate)); - // Act final PutTemplateRequest putTemplateRequest = PutTemplateRequest._DESERIALIZER.deserialize(parser, mapper); - // Assert assertEquals(putTemplateRequest.name(), "test"); assertEquals(putTemplateRequest.indexPatterns(), List.of("*")); assertEquals((long) putTemplateRequest.order(), 1L); From 895340c1059b8c96185b7bf7096ac988ba6e0e13 Mon Sep 17 00:00:00 2001 From: bfindlay Date: Tue, 14 Nov 2023 12:30:31 +1100 Subject: [PATCH 5/6] update unit test for pr Signed-off-by: bfindlay --- .../client/opensearch/core/PutTemplateRequestTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java index d981bef97d..43446a4f32 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java @@ -34,7 +34,7 @@ public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessi assertEquals(putTemplateRequest.name(), "test"); assertEquals(putTemplateRequest.indexPatterns(), List.of("*")); - assertEquals((long) putTemplateRequest.order(), 1L); + assertEquals((int) putTemplateRequest.order(), 1); assertEquals(putTemplateRequest.create(), true); } } From 4f5f8ec101b30624ceacaaed808fec73bbb0d77e Mon Sep 17 00:00:00 2001 From: bfindlay Date: Tue, 14 Nov 2023 18:38:08 +1100 Subject: [PATCH 6/6] apply spotless check Signed-off-by: bfindlay --- .../opensearch/core/PutTemplateRequestTest.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java index 43446a4f32..449b41e496 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java @@ -16,17 +16,8 @@ public class PutTemplateRequestTest extends Assert { @Test public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException { final JsonpMapper mapper = new JsonbJsonpMapper(); - final Map indexTemplateMap = Map.of( - "name", - "test", - "index_patterns", - "*", - "create", - true, - "order", - 1 + final Map 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));