GH-792 Fix Supplier streaming in s-c-function-web

Resolves #792
This commit is contained in:
Oleg Zhurakousky
2022-01-24 15:36:24 +01:00
parent f054d4534c
commit 4699f69be5
10 changed files with 109 additions and 51 deletions

View File

@@ -333,6 +333,8 @@ public class HttpPostIntegrationTests {
@Test
@DirtiesContext
public void uppercaseSSE() throws Exception {
String s = this.rest.exchange(RequestEntity.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
.body("[\"foo\",\"bar\"]"), String.class).getBody();
assertThat(this.rest.exchange(RequestEntity.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
.body("[\"foo\",\"bar\"]"), String.class).getBody())
.isEqualTo(sse("(FOO)", "(BAR)"));

View File

@@ -64,6 +64,18 @@ public class UserSubmittedTests {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@Test
public void testIssue274WithData() 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"), "hello", String.class);
assertThat(response.getBody()).isEqualTo("HELLO");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@SpringBootApplication
protected static class Issue274Configuration {

View File

@@ -290,12 +290,29 @@ public class HttpPostIntegrationTests {
@Test
public void uppercaseSSE() throws Exception {
assertThat(this.rest.exchange(RequestEntity.post(new URI("/uppercase"))
.accept(EVENT_STREAM).contentType(MediaType.APPLICATION_JSON)
String s = this.rest.exchange(RequestEntity.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
.body("[\"foo\",\"bar\"]"), String.class).getBody();
assertThat(this.rest.exchange(RequestEntity.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
.body("[\"foo\",\"bar\"]"), String.class).getBody())
.isEqualTo(sse("(FOO)", "(BAR)"));
}
// @Test
// public void uppercaseSSE() throws Exception {
// assertThat(this.rest.exchange(RequestEntity.post(new URI("/uppercase"))
// .accept(EVENT_STREAM).contentType(MediaType.APPLICATION_JSON)
// .body("[\"foo\",\"bar\"]"), String.class).getBody())
// .isEqualTo(sse("(FOO)", "(BAR)"));
//
//// String body = this.rest.exchange(RequestEntity.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
//// .body("[\"foo\",\"bar\"]"), String.class).getBody();
//
//// System.out.println(body);
//
//// assertThat(body)
//// .isEqualTo(sse("(FOO)", "(BAR)"));
// }
@Test
public void sum() throws Exception {
@@ -334,7 +351,8 @@ public class HttpPostIntegrationTests {
}
private String sse(String... values) {
return "data:" + StringUtils.arrayToDelimitedString(values, "\n\ndata:") + "\n\n";
//return "data:" + StringUtils.arrayToDelimitedString(values, "\n\ndata:") + "\n\n";
return "[\"" + StringUtils.arrayToDelimitedString(values, "\",\"") + "\"]";
}
@EnableAutoConfiguration