From 4e1bb79e8de2ddfc0130bac76f7fb609244b9834 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Wed, 18 Dec 2024 16:16:41 +1300 Subject: [PATCH] Test that deserialization fails Signed-off-by: Thomas Farr --- .../core/PutIndexTemplateRequestTest.java | 15 +++++---------- .../opensearch/core/PutTemplateRequestTest.java | 12 +++++------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java index fa58b8474..b2fa0fa0b 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java @@ -12,22 +12,20 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.stream.JsonParser; import java.io.StringReader; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import org.opensearch.client.json.JsonpMapper; import org.opensearch.client.json.jsonb.JsonbJsonpMapper; import org.opensearch.client.opensearch.indices.PutIndexTemplateRequest; +import org.opensearch.client.util.MissingRequiredPropertyException; public class PutIndexTemplateRequestTest extends Assert { // TODO: Allow constructing requests from JSON with required path params - @Ignore @Test - public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException { + public void doesNotDeserializePathParamsFromJsonBlob() throws JsonProcessingException { final JsonpMapper mapper = new JsonbJsonpMapper(); final Map indexTemplateMap = new HashMap<>(); indexTemplateMap.put("name", "test"); @@ -38,11 +36,8 @@ public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessi final String indexTemplate = new ObjectMapper().writeValueAsString(indexTemplateMap); final JsonParser parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate)); - final PutIndexTemplateRequest putIndexTemplateRequest = PutIndexTemplateRequest._DESERIALIZER.deserialize(parser, mapper); - - assertEquals(putIndexTemplateRequest.name(), "test"); - assertEquals(putIndexTemplateRequest.indexPatterns(), Collections.singletonList("*")); - assertEquals((int) putIndexTemplateRequest.priority(), 1); + assertThrows("Missing required property 'PutTemplateRequest.name'", MissingRequiredPropertyException.class, () -> { + PutIndexTemplateRequest._DESERIALIZER.deserialize(parser, mapper); + }); } - } 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 b9f1425db..9a544b6aa 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 @@ -21,13 +21,13 @@ import org.opensearch.client.json.JsonpMapper; import org.opensearch.client.json.jsonb.JsonbJsonpMapper; import org.opensearch.client.opensearch.indices.PutTemplateRequest; +import org.opensearch.client.util.MissingRequiredPropertyException; public class PutTemplateRequestTest extends Assert { // TODO: Allow constructing requests from JSON with required path params - @Ignore @Test - public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException { + public void doesNotDeserializePathParamsFromJsonBlob() throws JsonProcessingException { final JsonpMapper mapper = new JsonbJsonpMapper(); final Map indexTemplateMap = new HashMap<>(); indexTemplateMap.put("name", "test"); @@ -37,10 +37,8 @@ public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessi final String indexTemplate = new ObjectMapper().writeValueAsString(indexTemplateMap); final JsonParser parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate)); - final PutTemplateRequest putTemplateRequest = PutTemplateRequest._DESERIALIZER.deserialize(parser, mapper); - - assertEquals("test", putTemplateRequest.name()); - assertEquals(Collections.singletonList("*"), putTemplateRequest.indexPatterns()); - assertEquals((Integer) 1, putTemplateRequest.order()); + assertThrows("Missing required property 'PutTemplateRequest.name'", MissingRequiredPropertyException.class, () -> { + PutTemplateRequest._DESERIALIZER.deserialize(parser, mapper); + }); } }