From 60e7f2e04e12eaf2b5a25a728af8cc03e8ee9971 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 16 Sep 2021 14:53:00 +0200 Subject: [PATCH] #1608 - HAL FORMS templates now expose HTTP method in all caps. See the RFC for details: https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.1. --- .../hateoas/mediatype/hal/forms/HalFormsTemplate.java | 2 +- .../hal/forms/HalFormsTemplateBuilderUnitTest.java | 5 +++++ .../hal/forms/HalFormsWebFluxIntegrationTest.java | 6 +++--- .../hal/forms/HalFormsWebMvcIntegrationTest.java | 6 +++--- .../mvc/MultiMediaTypeWebMvcIntegrationTest.java | 10 +++++----- .../mediatype/hal/forms/employee-resource-support.json | 2 +- .../hateoas/mediatype/hal/forms/hal-forms-custom.json | 4 ++-- 7 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplate.java b/src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplate.java index 72eca88b..f2f4b7d4 100644 --- a/src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplate.java +++ b/src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplate.java @@ -130,7 +130,7 @@ final class HalFormsTemplate { @Nullable String getMethod() { - return this.httpMethod == null ? null : this.httpMethod.toString().toLowerCase(); + return this.httpMethod == null ? null : this.httpMethod.name(); } void setMethod(String method) { diff --git a/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplateBuilderUnitTest.java b/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplateBuilderUnitTest.java index 422e4e5b..48c78e08 100644 --- a/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplateBuilderUnitTest.java +++ b/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplateBuilderUnitTest.java @@ -225,6 +225,11 @@ class HalFormsTemplateBuilderUnitTest { }); } + @Test // #1608 + void exposesHttpMethodInAllCaps() { + assertThat(HalFormsTemplate.forMethod(HttpMethod.POST).getMethod()).isEqualTo("POST"); + } + @Getter static class PatternExample extends RepresentationModel { diff --git a/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebFluxIntegrationTest.java b/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebFluxIntegrationTest.java index e46d8c0c..8ffa9632 100644 --- a/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebFluxIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebFluxIntegrationTest.java @@ -80,13 +80,13 @@ class HalFormsWebFluxIntegrationTest { .value(jsonPath("$._links['employees'].href", is("http://localhost/employees"))) // .value(jsonPath("$._templates.*", hasSize(2))) // - .value(jsonPath("$._templates['default'].method", is("put"))) // + .value(jsonPath("$._templates['default'].method", is("PUT"))) // .value(jsonPath("$._templates['default'].properties[0].name", is("name"))) // .value(jsonPath("$._templates['default'].properties[0].required", is(true))) // .value(jsonPath("$._templates['default'].properties[1].name", is("role"))) // .value(jsonPath("$._templates['default'].properties[1].required").doesNotExist()) // - .value(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("patch"))) // + .value(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("PATCH"))) // .value(jsonPath("$._templates['partiallyUpdateEmployee'].properties[0].name", is("name"))) // .value(jsonPath("$._templates['partiallyUpdateEmployee'].properties[0].required").doesNotExist()) // .value(jsonPath("$._templates['partiallyUpdateEmployee'].properties[1].name", is("role"))) // @@ -111,7 +111,7 @@ class HalFormsWebFluxIntegrationTest { .value(jsonPath("$._links.*", hasSize(1))) .value(jsonPath("$._links['self'].href", is("http://localhost/employees"))) - .value(jsonPath("$._templates.*", hasSize(1))).value(jsonPath("$._templates['default'].method", is("post"))) + .value(jsonPath("$._templates.*", hasSize(1))).value(jsonPath("$._templates['default'].method", is("POST"))) .value(jsonPath("$._templates['default'].properties[0].name", is("name"))) .value(jsonPath("$._templates['default'].properties[0].required", is(true))) .value(jsonPath("$._templates['default'].properties[1].name", is("role"))) diff --git a/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebMvcIntegrationTest.java b/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebMvcIntegrationTest.java index a5814db3..7872a638 100644 --- a/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebMvcIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebMvcIntegrationTest.java @@ -76,13 +76,13 @@ class HalFormsWebMvcIntegrationTest { .andExpect(jsonPath("$._links['employees'].href", is("http://localhost/employees"))) .andExpect(jsonPath("$._templates.*", hasSize(2))) - .andExpect(jsonPath("$._templates['default'].method", is("put"))) + .andExpect(jsonPath("$._templates['default'].method", is("PUT"))) .andExpect(jsonPath("$._templates['default'].properties[0].name", is("name"))) .andExpect(jsonPath("$._templates['default'].properties[0].required").value(true)) .andExpect(jsonPath("$._templates['default'].properties[1].name", is("role"))) .andExpect(jsonPath("$._templates['default'].properties[1].required").doesNotExist()) - .andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("patch"))) + .andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("PATCH"))) .andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].properties[0].name", is("name"))) .andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].properties[0].required").doesNotExist()) .andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].properties[1].name", is("role"))) @@ -105,7 +105,7 @@ class HalFormsWebMvcIntegrationTest { .andExpect(jsonPath("$._links['self'].href", is("http://localhost/employees"))) .andExpect(jsonPath("$._templates.*", hasSize(1))) - .andExpect(jsonPath("$._templates['default'].method", is("post"))) + .andExpect(jsonPath("$._templates['default'].method", is("POST"))) .andExpect(jsonPath("$._templates['default'].properties[0].name", is("name"))) .andExpect(jsonPath("$._templates['default'].properties[0].required").value(true)) .andExpect(jsonPath("$._templates['default'].properties[1].name", is("role"))) diff --git a/src/test/java/org/springframework/hateoas/server/mvc/MultiMediaTypeWebMvcIntegrationTest.java b/src/test/java/org/springframework/hateoas/server/mvc/MultiMediaTypeWebMvcIntegrationTest.java index 139b99c2..facc0f36 100644 --- a/src/test/java/org/springframework/hateoas/server/mvc/MultiMediaTypeWebMvcIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/server/mvc/MultiMediaTypeWebMvcIntegrationTest.java @@ -208,8 +208,8 @@ class MultiMediaTypeWebMvcIntegrationTest { .andExpect(jsonPath("$._links['employees'].href", is("http://localhost/employees"))); expectEmployeeProperties(actions, "default", "partiallyUpdateEmployee") // - .andExpect(jsonPath("$._templates['default'].method", is("put"))) - .andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("patch"))); + .andExpect(jsonPath("$._templates['default'].method", is("PUT"))) + .andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("PATCH"))); } @Test @@ -227,7 +227,7 @@ class MultiMediaTypeWebMvcIntegrationTest { .andExpect(jsonPath("$._links.*", hasSize(1))) .andExpect(jsonPath("$._links['self'].href", is("http://localhost/employees"))) - .andExpect(jsonPath("$._templates['default'].method", is("post"))); + .andExpect(jsonPath("$._templates['default'].method", is("POST"))); expectEmployeeProperties(actions, "default"); } @@ -251,8 +251,8 @@ class MultiMediaTypeWebMvcIntegrationTest { expectEmployeeProperties(actions, "default", "partiallyUpdateEmployee") // - .andExpect(jsonPath("$._templates['default'].method", is("put"))) - .andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("patch"))); + .andExpect(jsonPath("$._templates['default'].method", is("PUT"))) + .andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("PATCH"))); } @Test diff --git a/src/test/resources/org/springframework/hateoas/mediatype/hal/forms/employee-resource-support.json b/src/test/resources/org/springframework/hateoas/mediatype/hal/forms/employee-resource-support.json index 70fb38cc..45b63b9d 100644 --- a/src/test/resources/org/springframework/hateoas/mediatype/hal/forms/employee-resource-support.json +++ b/src/test/resources/org/springframework/hateoas/mediatype/hal/forms/employee-resource-support.json @@ -7,7 +7,7 @@ }, "_templates" : { "default" : { - "method" : "post", + "method" : "POST", "properties" : [ { "name" : "name", "type" : "text" diff --git a/src/test/resources/org/springframework/hateoas/mediatype/hal/forms/hal-forms-custom.json b/src/test/resources/org/springframework/hateoas/mediatype/hal/forms/hal-forms-custom.json index 7e677c1a..3bc0e1ed 100644 --- a/src/test/resources/org/springframework/hateoas/mediatype/hal/forms/hal-forms-custom.json +++ b/src/test/resources/org/springframework/hateoas/mediatype/hal/forms/hal-forms-custom.json @@ -11,7 +11,7 @@ }, "_templates" : { "default" : { - "method" : "put", + "method" : "PUT", "properties" : [ { "name" : "name", "required" : true, @@ -22,7 +22,7 @@ } ] }, "partiallyUpdateEmployee" : { - "method" : "patch", + "method" : "PATCH", "properties" : [ { "name" : "name", "type" : "text"