GH-274 Fixed empty body request handling

Resolves #274
This commit is contained in:
Oleg Zhurakousky
2019-03-20 08:45:26 +01:00
parent edb4b99be4
commit 7042394bd2
2 changed files with 82 additions and 6 deletions

View File

@@ -0,0 +1,77 @@
/*
* Copyright 2019-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.web.function;
import java.net.URI;
import java.util.function.Function;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.SocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
*
* @author Oleg Zhurakousky
* @since 2.1
*
*/
public class UserSubmittedTests {
@Before
public void init() throws Exception {
String port = "" + SocketUtils.findAvailableTcpPort();
System.setProperty("server.port", port);
}
@After
public void close() throws Exception {
System.clearProperty("server.port");
}
@Test
public void testIssue274() throws Exception {
SpringApplication.run(Issue274Configuration.class);
TestRestTemplate testRestTemplate = new TestRestTemplate();
String port = System.getProperty("server.port");
Thread.sleep(200);
ResponseEntity<String> response = testRestTemplate
.postForEntity(new URI("http://localhost:" + port + "/echo"), "", String.class);
assertThat(response.getBody()).isNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@SpringBootApplication
protected static class Issue274Configuration {
@Bean
public Function<String, String> echo() {
return s -> s.toUpperCase();
}
}
}