|
| 1 | +/* |
| 2 | + * Copyright 2024-2024 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.cloud.function.web.function; |
| 18 | + |
| 19 | + |
| 20 | +import java.net.URI; |
| 21 | +import java.util.Locale; |
| 22 | +import java.util.function.Function; |
| 23 | + |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import org.springframework.boot.SpringApplication; |
| 27 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 28 | +import org.springframework.boot.test.web.client.TestRestTemplate; |
| 29 | +import org.springframework.context.ConfigurableApplicationContext; |
| 30 | +import org.springframework.context.annotation.Bean; |
| 31 | +import org.springframework.http.ResponseEntity; |
| 32 | + |
| 33 | +import static org.assertj.core.api.Assertions.assertThat; |
| 34 | + |
| 35 | +public class HeadersResponseMappingTests { |
| 36 | + |
| 37 | + // see https://github.com/spring-cloud/spring-cloud-function/issues/1220 |
| 38 | + @Test |
| 39 | + public void test_1220() throws Exception { |
| 40 | + ConfigurableApplicationContext context = SpringApplication.run(ApplicationConfiguration.class, |
| 41 | + "--server.port=0"); |
| 42 | + TestRestTemplate testRestTemplate = new TestRestTemplate(); |
| 43 | + String port = context.getEnvironment().getProperty("local.server.port"); |
| 44 | + ResponseEntity<String> response = testRestTemplate.postForEntity( |
| 45 | + new URI("http://localhost:" + port + "/uppercase"), new Person("John", "Doe"), String.class); |
| 46 | + assertThat(response.getBody()).isEqualTo("JOHN"); |
| 47 | + } |
| 48 | + |
| 49 | + static record Person(String firstName, String lastName) { |
| 50 | + } |
| 51 | + |
| 52 | + @SpringBootApplication |
| 53 | + protected static class ApplicationConfiguration { |
| 54 | + |
| 55 | + @Bean |
| 56 | + public Function<Person, String> uppercase() { |
| 57 | + return s -> s.firstName().toUpperCase(Locale.ROOT); |
| 58 | + } |
| 59 | + |
| 60 | + } |
| 61 | +} |
0 commit comments