GH-1025 Add POST tests and cleanup
This commit is contained in:
@@ -29,6 +29,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
@@ -42,22 +43,22 @@ public class GeneralIntegrationTests {
|
||||
@Test
|
||||
public void testMappedAndUnmappedDeleteFunction() throws Exception {
|
||||
ApplicationContext context = SpringApplication.run(MultipleConsumerConfiguration.class, "--server.port=0",
|
||||
"--spring.cloud.function.http.DELETE=delete2;deleteFunction|delete1");
|
||||
"--spring.cloud.function.http.DELETE=consumer2;supplier;function|consumer1");
|
||||
String port = context.getEnvironment().getProperty("local.server.port");
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
|
||||
ResponseEntity<Void> result = template.exchange(
|
||||
RequestEntity.delete(new URI("http://localhost:" + port + "/delete1"))
|
||||
RequestEntity.delete(new URI("http://localhost:" + port + "/consumer1"))
|
||||
.build(), Void.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
|
||||
result = template.exchange(
|
||||
RequestEntity.delete(new URI("http://localhost:" + port + "/delete2"))
|
||||
RequestEntity.delete(new URI("http://localhost:" + port + "/consumer2"))
|
||||
.build(), Void.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||
|
||||
result = template.exchange(
|
||||
RequestEntity.delete(new URI("http://localhost:" + port + "/deleteFunction,delete1"))
|
||||
RequestEntity.delete(new URI("http://localhost:" + port + "/function,consumer1"))
|
||||
.build(), Void.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||
|
||||
@@ -67,22 +68,59 @@ public class GeneralIntegrationTests {
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMappedAndUnmappedPostPutFunction() throws Exception {
|
||||
ApplicationContext context = SpringApplication.run(MultipleConsumerConfiguration.class, "--server.port=0",
|
||||
"--spring.cloud.function.http.POST=consumer2;function;supplier;function|consumer1");
|
||||
String port = context.getEnvironment().getProperty("local.server.port");
|
||||
TestRestTemplate template = new TestRestTemplate();
|
||||
|
||||
ResponseEntity<String> result = template.exchange(RequestEntity
|
||||
.post(new URI("http://localhost:" + port + "/consumer1")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
|
||||
result = template.exchange(RequestEntity
|
||||
.post(new URI("http://localhost:" + port + "/consumer2")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(result.getBody()).isNull();
|
||||
|
||||
result = template.exchange(RequestEntity
|
||||
.post(new URI("http://localhost:" + port + "/function,consumer1")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(result.getBody()).isNull();
|
||||
|
||||
result = template.exchange(RequestEntity
|
||||
.post(new URI("http://localhost:" + port + "/function")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
|
||||
result = template.exchange(RequestEntity
|
||||
.post(new URI("http://localhost:" + port + "/supplier")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@EnableAutoConfiguration
|
||||
protected static class MultipleConsumerConfiguration {
|
||||
|
||||
@Bean
|
||||
public Consumer<String> delete1() {
|
||||
return v -> {};
|
||||
public Consumer<String> consumer1() {
|
||||
return v -> { };
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Consumer<String> delete2() {
|
||||
return v -> {};
|
||||
public Consumer<String> consumer2() {
|
||||
return v -> { };
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, String> deleteFunction() {
|
||||
public Function<String, String> function() {
|
||||
return v -> v;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.function.web.mvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -27,6 +25,7 @@ import java.util.function.Function;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -35,7 +34,6 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.cloud.function.web.RestApplication;
|
||||
import org.springframework.cloud.function.web.mvc.HttpDeleteIntegrationTests.ApplicationConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -43,7 +41,8 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
|
||||
Reference in New Issue
Block a user