Skip to content

Commit

Permalink
Test that deserialization fails
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Dec 18, 2024
1 parent a1c5c09 commit 4e1bb79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> indexTemplateMap = new HashMap<>();
indexTemplateMap.put("name", "test");
Expand All @@ -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);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> indexTemplateMap = new HashMap<>();
indexTemplateMap.put("name", "test");
Expand All @@ -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);
});
}
}

0 comments on commit 4e1bb79

Please sign in to comment.