GH-1025 Ad more test for DELETE method
This commit is contained in:
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.function.web;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.function.context.FunctionProperties;
|
||||
|
||||
@@ -27,60 +25,59 @@ import org.springframework.cloud.function.context.FunctionProperties;
|
||||
* @since 4.0.4
|
||||
*
|
||||
*/
|
||||
|
||||
@ConfigurationProperties(prefix = FunctionProperties.PREFIX + ".http")
|
||||
public class FunctionHttpProperties {
|
||||
|
||||
/**
|
||||
* Blah.
|
||||
* Function definition mappings for GET method (e.g. 'spring.cloud.function.http.GET=foo;bar|baz')
|
||||
*/
|
||||
public List<String> get;
|
||||
public String get;
|
||||
|
||||
|
||||
/**
|
||||
* Blah.
|
||||
* Function definition mappings for POST method (e.g. 'spring.cloud.function.http.POST=foo;bar|baz')
|
||||
*/
|
||||
public List<String> post;
|
||||
public String post;
|
||||
|
||||
/**
|
||||
* Blah.
|
||||
* Function definition mappings for PUT method (e.g. 'spring.cloud.function.http.PUT=foo;bar|baz')
|
||||
*/
|
||||
public List<String> put;
|
||||
public String put;
|
||||
|
||||
/**
|
||||
* Blah.
|
||||
* Function definition mappings for DELETE method (e.g. 'spring.cloud.function.http.DELETE=foo;bar|baz')
|
||||
*/
|
||||
public List<String> delete;
|
||||
public String delete;
|
||||
|
||||
public List<String> getGet() {
|
||||
public String getGet() {
|
||||
return this.get;
|
||||
}
|
||||
|
||||
public void setGet(List<String> get) {
|
||||
public void setGet(String get) {
|
||||
this.get = get;
|
||||
}
|
||||
|
||||
public List<String> getPost() {
|
||||
public String getPost() {
|
||||
return post;
|
||||
}
|
||||
|
||||
public void setPost(List<String> post) {
|
||||
public void setPost(String post) {
|
||||
this.post = post;
|
||||
}
|
||||
|
||||
public List<String> getPut() {
|
||||
public String getPut() {
|
||||
return put;
|
||||
}
|
||||
|
||||
public void setPut(List<String> put) {
|
||||
public void setPut(String put) {
|
||||
this.put = put;
|
||||
}
|
||||
|
||||
public List<String> getDelete() {
|
||||
public String getDelete() {
|
||||
return delete;
|
||||
}
|
||||
|
||||
public void setDelete(List<String> delete) {
|
||||
public void setDelete(String delete) {
|
||||
this.delete = delete;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.stream.Collectors;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.netty.http.server.HttpServerRequest;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||
@@ -56,8 +55,6 @@ import org.springframework.web.context.request.WebRequest;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.function.web.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -34,7 +35,6 @@ import org.springframework.cloud.function.web.FunctionHttpProperties;
|
||||
import org.springframework.cloud.function.web.constants.WebRequestConstants;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.RequestEntity.HeadersBuilder;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.ResponseEntity.BodyBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -42,8 +42,6 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* !INTERNAL USE ONLY!
|
||||
*
|
||||
@@ -74,7 +72,7 @@ public final class FunctionWebRequestProcessingHelper {
|
||||
}
|
||||
|
||||
public static boolean isValidFunction(String httpMethod, String functionDefinition, FunctionHttpProperties functionHttpProperties) {
|
||||
List<String> functionDefinitions = null;
|
||||
String functionDefinitions = null;
|
||||
switch (httpMethod) {
|
||||
case "GET":
|
||||
functionDefinitions = functionHttpProperties.getGet();
|
||||
@@ -91,7 +89,10 @@ public final class FunctionWebRequestProcessingHelper {
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return CollectionUtils.isEmpty(functionDefinitions) || functionDefinitions.contains(functionDefinition);
|
||||
if (StringUtils.hasText(functionDefinitions)) {
|
||||
return Arrays.asList(functionDefinitions.split(";")).contains(functionDefinition);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String buildBadMappingErrorMessage(String httpMethod, String functionDefinition) {
|
||||
|
||||
@@ -17,28 +17,20 @@
|
||||
package org.springframework.cloud.function.web.mvc;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.cloud.function.json.JsonMapper;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
@@ -49,9 +41,9 @@ public class GeneralIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testMappedAndUnmappedDeleteFunction() throws Exception {
|
||||
ApplicationContext context = SpringApplication.run(MultipleConsumerConfiguration.class, "--server.port=0", "--spring.cloud.function.http.DELETE=delete2");
|
||||
ApplicationContext context = SpringApplication.run(MultipleConsumerConfiguration.class, "--server.port=0",
|
||||
"--spring.cloud.function.http.DELETE=delete2;deleteFunction|delete1");
|
||||
String port = context.getEnvironment().getProperty("local.server.port");
|
||||
JsonMapper mapper = context.getBean(JsonMapper.class);
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
|
||||
ResponseEntity<Void> result = template.exchange(
|
||||
@@ -63,6 +55,16 @@ public class GeneralIntegrationTests {
|
||||
RequestEntity.delete(new URI("http://localhost:" + port + "/delete2"))
|
||||
.build(), Void.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||
|
||||
result = template.exchange(
|
||||
RequestEntity.delete(new URI("http://localhost:" + port + "/deleteFunction,delete1"))
|
||||
.build(), Void.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||
|
||||
result = template.exchange(
|
||||
RequestEntity.delete(new URI("http://localhost:" + port + "/supplier"))
|
||||
.build(), Void.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,5 +80,15 @@ public class GeneralIntegrationTests {
|
||||
public Consumer<String> delete2() {
|
||||
return v -> {};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, String> deleteFunction() {
|
||||
return v -> v;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Supplier<String> supplier() {
|
||||
return () -> "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user