Skip to content

Commit 60e7f2e

Browse files
committed
#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.
1 parent f9274a6 commit 60e7f2e

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

src/main/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void setContentType(MediaType mediaType) {
130130

131131
@Nullable
132132
String getMethod() {
133-
return this.httpMethod == null ? null : this.httpMethod.toString().toLowerCase();
133+
return this.httpMethod == null ? null : this.httpMethod.name();
134134
}
135135

136136
void setMethod(String method) {

src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsTemplateBuilderUnitTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ void propagatesSelectedValueToProperty() {
225225
});
226226
}
227227

228+
@Test // #1608
229+
void exposesHttpMethodInAllCaps() {
230+
assertThat(HalFormsTemplate.forMethod(HttpMethod.POST).getMethod()).isEqualTo("POST");
231+
}
232+
228233
@Getter
229234
static class PatternExample extends RepresentationModel<PatternExample> {
230235

src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebFluxIntegrationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ void singleEmployee() {
8080
.value(jsonPath("$._links['employees'].href", is("http://localhost/employees"))) //
8181

8282
.value(jsonPath("$._templates.*", hasSize(2))) //
83-
.value(jsonPath("$._templates['default'].method", is("put"))) //
83+
.value(jsonPath("$._templates['default'].method", is("PUT"))) //
8484
.value(jsonPath("$._templates['default'].properties[0].name", is("name"))) //
8585
.value(jsonPath("$._templates['default'].properties[0].required", is(true))) //
8686
.value(jsonPath("$._templates['default'].properties[1].name", is("role"))) //
8787
.value(jsonPath("$._templates['default'].properties[1].required").doesNotExist()) //
8888

89-
.value(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("patch"))) //
89+
.value(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("PATCH"))) //
9090
.value(jsonPath("$._templates['partiallyUpdateEmployee'].properties[0].name", is("name"))) //
9191
.value(jsonPath("$._templates['partiallyUpdateEmployee'].properties[0].required").doesNotExist()) //
9292
.value(jsonPath("$._templates['partiallyUpdateEmployee'].properties[1].name", is("role"))) //
@@ -111,7 +111,7 @@ void collectionOfEmployees() {
111111
.value(jsonPath("$._links.*", hasSize(1)))
112112
.value(jsonPath("$._links['self'].href", is("http://localhost/employees")))
113113

114-
.value(jsonPath("$._templates.*", hasSize(1))).value(jsonPath("$._templates['default'].method", is("post")))
114+
.value(jsonPath("$._templates.*", hasSize(1))).value(jsonPath("$._templates['default'].method", is("POST")))
115115
.value(jsonPath("$._templates['default'].properties[0].name", is("name")))
116116
.value(jsonPath("$._templates['default'].properties[0].required", is(true)))
117117
.value(jsonPath("$._templates['default'].properties[1].name", is("role")))

src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebMvcIntegrationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ void singleEmployee() throws Exception {
7676
.andExpect(jsonPath("$._links['employees'].href", is("http://localhost/employees")))
7777

7878
.andExpect(jsonPath("$._templates.*", hasSize(2)))
79-
.andExpect(jsonPath("$._templates['default'].method", is("put")))
79+
.andExpect(jsonPath("$._templates['default'].method", is("PUT")))
8080
.andExpect(jsonPath("$._templates['default'].properties[0].name", is("name")))
8181
.andExpect(jsonPath("$._templates['default'].properties[0].required").value(true))
8282
.andExpect(jsonPath("$._templates['default'].properties[1].name", is("role")))
8383
.andExpect(jsonPath("$._templates['default'].properties[1].required").doesNotExist())
8484

85-
.andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("patch")))
85+
.andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("PATCH")))
8686
.andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].properties[0].name", is("name")))
8787
.andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].properties[0].required").doesNotExist())
8888
.andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].properties[1].name", is("role")))
@@ -105,7 +105,7 @@ void collectionOfEmployees() throws Exception {
105105
.andExpect(jsonPath("$._links['self'].href", is("http://localhost/employees")))
106106

107107
.andExpect(jsonPath("$._templates.*", hasSize(1)))
108-
.andExpect(jsonPath("$._templates['default'].method", is("post")))
108+
.andExpect(jsonPath("$._templates['default'].method", is("POST")))
109109
.andExpect(jsonPath("$._templates['default'].properties[0].name", is("name")))
110110
.andExpect(jsonPath("$._templates['default'].properties[0].required").value(true))
111111
.andExpect(jsonPath("$._templates['default'].properties[1].name", is("role")))

src/test/java/org/springframework/hateoas/server/mvc/MultiMediaTypeWebMvcIntegrationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ void singleEmployeeHalForms() throws Exception {
208208
.andExpect(jsonPath("$._links['employees'].href", is("http://localhost/employees")));
209209

210210
expectEmployeeProperties(actions, "default", "partiallyUpdateEmployee") //
211-
.andExpect(jsonPath("$._templates['default'].method", is("put")))
212-
.andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("patch")));
211+
.andExpect(jsonPath("$._templates['default'].method", is("PUT")))
212+
.andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("PATCH")));
213213
}
214214

215215
@Test
@@ -227,7 +227,7 @@ void collectionOfEmployeesHalForms() throws Exception {
227227
.andExpect(jsonPath("$._links.*", hasSize(1)))
228228
.andExpect(jsonPath("$._links['self'].href", is("http://localhost/employees")))
229229

230-
.andExpect(jsonPath("$._templates['default'].method", is("post")));
230+
.andExpect(jsonPath("$._templates['default'].method", is("POST")));
231231

232232
expectEmployeeProperties(actions, "default");
233233
}
@@ -251,8 +251,8 @@ void createNewEmployeeHalForms() throws Exception {
251251

252252
expectEmployeeProperties(actions, "default", "partiallyUpdateEmployee") //
253253

254-
.andExpect(jsonPath("$._templates['default'].method", is("put")))
255-
.andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("patch")));
254+
.andExpect(jsonPath("$._templates['default'].method", is("PUT")))
255+
.andExpect(jsonPath("$._templates['partiallyUpdateEmployee'].method", is("PATCH")));
256256
}
257257

258258
@Test

src/test/resources/org/springframework/hateoas/mediatype/hal/forms/employee-resource-support.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"_templates" : {
99
"default" : {
10-
"method" : "post",
10+
"method" : "POST",
1111
"properties" : [ {
1212
"name" : "name",
1313
"type" : "text"

src/test/resources/org/springframework/hateoas/mediatype/hal/forms/hal-forms-custom.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"_templates" : {
1313
"default" : {
14-
"method" : "put",
14+
"method" : "PUT",
1515
"properties" : [ {
1616
"name" : "name",
1717
"required" : true,
@@ -22,7 +22,7 @@
2222
} ]
2323
},
2424
"partiallyUpdateEmployee" : {
25-
"method" : "patch",
25+
"method" : "PATCH",
2626
"properties" : [ {
2727
"name" : "name",
2828
"type" : "text"

0 commit comments

Comments
 (0)