Skip to content

Commit d6a1677

Browse files
committed
Updates for Spring Framework 7 jackson 3
1 parent 0c3d8b5 commit d6a1677

File tree

5 files changed

+36
-30
lines changed

5 files changed

+36
-30
lines changed

spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/test/java/org/springframework/cloud/function/serverless/web/RequestResponseTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
import java.util.List;
2020

21-
import com.fasterxml.jackson.core.type.TypeReference;
22-
import com.fasterxml.jackson.databind.ObjectMapper;
2321
import jakarta.servlet.http.HttpServletRequest;
2422
import org.junit.jupiter.api.AfterEach;
2523
import org.junit.jupiter.api.BeforeEach;
2624
import org.junit.jupiter.api.Test;
25+
import tools.jackson.core.type.TypeReference;
26+
import tools.jackson.databind.ObjectMapper;
2727

2828
import org.springframework.cloud.function.test.app.Pet;
2929
import org.springframework.cloud.function.test.app.PetStoreSpringAppConfig;

spring-cloud-function-kotlin/src/test/kotlin/org/springframework/cloud/function/kotlin/web/HeadersToMessageSuspendTests.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import org.springframework.cloud.function.web.RestApplication
2828
import org.springframework.context.annotation.Bean
2929
import org.springframework.http.MediaType
3030
import org.springframework.http.RequestEntity
31+
import org.springframework.http.ResponseEntity
3132
import org.springframework.messaging.Message
3233
import org.springframework.messaging.support.MessageBuilder
3334
import org.springframework.test.context.ContextConfiguration
@@ -52,25 +53,27 @@ open class HeadersToMessageSuspendTests {
5253
.exchange(
5354
RequestEntity.post(URI("/functions/employeeSuspend"))
5455
.contentType(MediaType.APPLICATION_JSON)
55-
.body("[{\"name\":\"Bob\",\"age\":25}]"), String::class.java
56-
)
56+
.body("[{\"name\":\"Bob\",\"age\":25}]"), List::class.java
57+
) as ResponseEntity<List<Map<String, Object>>>
5758

58-
Assertions.assertThat(postForEntity.body).isEqualTo("[{\"name\":\"Bob\",\"age\":25}]")
59+
val map = hashMapOf("name" to "Bob", "age" to 25) as Map<String, Object>
60+
Assertions.assertThat(postForEntity.body).hasSize(1)
61+
Assertions.assertThat(postForEntity.body?.get(0)).containsExactlyInAnyOrderEntriesOf(map)
5962
Assertions.assertThat(postForEntity.headers.containsHeader("x-content-type")).isTrue
6063
Assertions.assertThat(postForEntity.headers["x-content-type"]!![0])
6164
.isEqualTo("application/xml")
6265
Assertions.assertThat(postForEntity.headers["foo"]!![0]).isEqualTo("bar")
6366

6467
// test simple type payload
65-
postForEntity = rest.postForEntity(
68+
var postForEntity2 = rest.postForEntity(
6669
URI("/functions/stringSuspend"),
6770
"HELLO", String::class.java
6871
)
69-
Assertions.assertThat(postForEntity.body).isEqualTo("[\"HELLO\"]")
70-
Assertions.assertThat(postForEntity.headers.containsHeader("x-content-type")).isTrue
71-
Assertions.assertThat(postForEntity.headers["x-content-type"]!![0])
72+
Assertions.assertThat(postForEntity2.body).isEqualTo("[\"HELLO\"]")
73+
Assertions.assertThat(postForEntity2.headers.containsHeader("x-content-type")).isTrue
74+
Assertions.assertThat(postForEntity2.headers["x-content-type"]!![0])
7275
.isEqualTo("application/xml")
73-
Assertions.assertThat(postForEntity.headers["foo"]!![0]).isEqualTo("bar")
76+
Assertions.assertThat(postForEntity2.headers["foo"]!![0]).isEqualTo("bar")
7477
}
7578

7679
@EnableAutoConfiguration

spring-cloud-function-kotlin/src/test/kotlin/org/springframework/cloud/function/kotlin/web/HeadersToMessageTests.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.springframework.cloud.function.web.RestApplication
2626
import org.springframework.context.annotation.Bean
2727
import org.springframework.http.MediaType
2828
import org.springframework.http.RequestEntity
29+
import org.springframework.http.ResponseEntity
2930
import org.springframework.messaging.Message
3031
import org.springframework.messaging.support.MessageBuilder
3132
import org.springframework.test.context.ContextConfiguration
@@ -52,24 +53,25 @@ open class HeadersToMessageTests {
5253
.exchange(
5354
RequestEntity.post(URI("/functions/employee"))
5455
.contentType(MediaType.APPLICATION_JSON)
55-
.body("{\"name\":\"Bob\",\"age\":25}"), String::class.java
56-
)
57-
Assertions.assertThat(postForEntity.body).isEqualTo("{\"name\":\"Bob\",\"age\":25}")
56+
.body("{\"name\":\"Bob\",\"age\":25}"), Map::class.java
57+
) as ResponseEntity<Map<String, Object>>
58+
val map = hashMapOf("name" to "Bob", "age" to 25) as Map<String, Object>
59+
Assertions.assertThat(postForEntity.body).containsExactlyInAnyOrderEntriesOf(map)
5860
Assertions.assertThat(postForEntity.headers.containsHeader("x-content-type")).isTrue
5961
Assertions.assertThat(postForEntity.headers["x-content-type"]!![0])
6062
.isEqualTo("application/xml")
6163
Assertions.assertThat(postForEntity.headers["foo"]!![0]).isEqualTo("bar")
6264

6365
// test simple type payload
64-
postForEntity = rest.postForEntity(
66+
var postForEntity2 = rest.postForEntity(
6567
URI("/functions/string"),
6668
"{\"name\":\"Bob\",\"age\":25}", String::class.java
6769
)
68-
Assertions.assertThat(postForEntity.body).isEqualTo("{\"name\":\"Bob\",\"age\":25}")
69-
Assertions.assertThat(postForEntity.headers.containsHeader("x-content-type")).isTrue
70-
Assertions.assertThat(postForEntity.headers["x-content-type"]!![0])
70+
Assertions.assertThat(postForEntity2.body).isEqualTo("{\"name\":\"Bob\",\"age\":25}")
71+
Assertions.assertThat(postForEntity2.headers.containsHeader("x-content-type")).isTrue
72+
Assertions.assertThat(postForEntity2.headers["x-content-type"]!![0])
7173
.isEqualTo("application/xml")
72-
Assertions.assertThat(postForEntity.headers["foo"]!![0]).isEqualTo("bar")
74+
Assertions.assertThat(postForEntity2.headers["foo"]!![0]).isEqualTo("bar")
7375
}
7476

7577
@EnableAutoConfiguration

spring-cloud-function-web/src/test/java/org/springframework/cloud/function/web/flux/HeadersToMessageTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.cloud.function.web.flux;
1818

1919
import java.net.URI;
20+
import java.util.Map;
2021
import java.util.function.Function;
2122

2223
import org.junit.jupiter.api.Test;
@@ -55,20 +56,20 @@ public class HeadersToMessageTests {
5556
@Test
5657
public void testBodyAndCustomHeaderFromMessagePropagation() throws Exception {
5758
// test POJO paylod
58-
ResponseEntity<String> postForEntity = this.rest
59+
ResponseEntity<Map> postForEntity = this.rest
5960
.exchange(RequestEntity.post(new URI("/functions/employee"))
6061
.contentType(MediaType.APPLICATION_JSON)
61-
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
62-
assertThat(postForEntity.getBody()).isEqualTo("{\"name\":\"Bob\",\"age\":25}");
62+
.body("{\"name\":\"Bob\",\"age\":25}"), Map.class);
63+
assertThat(postForEntity.getBody()).containsExactlyInAnyOrderEntriesOf(Map.of("name", "Bob", "age", 25));
6364
assertThat(postForEntity.getHeaders().containsHeader("x-content-type")).isTrue();
6465
assertThat(postForEntity.getHeaders().get("x-content-type").get(0))
6566
.isEqualTo("application/xml");
6667
assertThat(postForEntity.getHeaders().get("foo").get(0)).isEqualTo("bar");
6768

6869
// test simple type payload
6970
postForEntity = this.rest.postForEntity(new URI("/functions/string"),
70-
"{\"name\":\"Bob\",\"age\":25}", String.class);
71-
assertThat(postForEntity.getBody()).isEqualTo("{\"name\":\"Bob\",\"age\":25}");
71+
"{\"name\":\"Bob\",\"age\":25}", Map.class);
72+
assertThat(postForEntity.getBody()).containsExactlyInAnyOrderEntriesOf(Map.of("name", "Bob", "age", 25));
7273
assertThat(postForEntity.getHeaders().containsHeader("x-content-type")).isTrue();
7374
assertThat(postForEntity.getHeaders().get("x-content-type").get(0))
7475
.isEqualTo("application/xml");

spring-cloud-function-web/src/test/java/org/springframework/cloud/function/web/mvc/HeadersToMessageTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ public class HeadersToMessageTests {
5555

5656
@Test
5757
public void testBodyAndCustomHeaderFromMessagePropagation() throws Exception {
58-
HttpEntity<String> postForEntity = this.rest
58+
HttpEntity<Map> postForEntity = this.rest
5959
.exchange(RequestEntity.post(new URI("/functions/employee"))
6060
.contentType(MediaType.APPLICATION_JSON)
61-
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
62-
assertThat(postForEntity.getBody()).isEqualTo("{\"name\":\"Bob\",\"age\":25}");
61+
.body("{\"name\":\"Bob\",\"age\":25}"), Map.class);
62+
assertThat(postForEntity.getBody()).containsExactlyInAnyOrderEntriesOf(Map.of("name", "Bob", "age", 25));
6363
assertThat(postForEntity.getHeaders().containsHeader("x-content-type")).isTrue();
6464
assertThat(postForEntity.getHeaders().get("x-content-type").get(0))
6565
.isEqualTo("application/xml");
@@ -68,13 +68,13 @@ public void testBodyAndCustomHeaderFromMessagePropagation() throws Exception {
6868

6969
@Test
7070
public void testHeadersPropagatedByDefault() throws Exception {
71-
HttpEntity<String> postForEntity = this.rest
71+
HttpEntity<Map> postForEntity = this.rest
7272
.exchange(RequestEntity.post(new URI("/functions/vanilla"))
7373
.contentType(MediaType.APPLICATION_JSON)
7474
.header("x-context-type", "rubbish")
75-
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
76-
assertThat(postForEntity.getBody())
77-
.isEqualTo("{\"name\":\"Bob\",\"age\":25,\"foo\":\"bar\"}");
75+
.body("{\"name\":\"Bob\",\"age\":25}"), Map.class);
76+
assertThat(postForEntity.getBody()).containsExactlyInAnyOrderEntriesOf(Map.of("name", "Bob", "age", 25, "foo", "bar"));
77+
7878
assertThat(postForEntity.getHeaders().containsHeader("x-context-type")).isTrue();
7979
assertThat(postForEntity.getHeaders().get("x-context-type").get(0))
8080
.isEqualTo("rubbish");

0 commit comments

Comments
 (0)