Turned on checkstyle
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -28,6 +28,8 @@ import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -52,13 +54,10 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Tests for vanilla MVC handling (no function layer). Validates the MVC customizations
|
||||
* that are added in this project independently of the specific concerns of function.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@@ -67,28 +66,31 @@ import reactor.core.publisher.Mono;
|
||||
public class FluxRestApplicationTests {
|
||||
|
||||
private static final MediaType EVENT_STREAM = MediaType.valueOf("text/event-stream");
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Autowired
|
||||
private TestConfiguration test;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
test.list.clear();
|
||||
this.test.list.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wordsSSE() throws Exception {
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.get(new URI("/words")).accept(EVENT_STREAM).build(),
|
||||
String.class).getBody()).isEqualTo(sse("foo", "bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wordsJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -97,7 +99,7 @@ public class FluxRestApplicationTests {
|
||||
@Test
|
||||
@Ignore("Fix error handling")
|
||||
public void errorJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/bang"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\"]");
|
||||
@@ -105,7 +107,7 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -113,7 +115,7 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void foos() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/foos")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody())
|
||||
@@ -122,7 +124,7 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void getMore() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/get/more")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -131,44 +133,44 @@ public class FluxRestApplicationTests {
|
||||
@Test
|
||||
@Ignore("Should this even work? Or do we need to be explicit about the JSON?")
|
||||
public void updates() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.post(new URI("/updates")).body("one\ntwo"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isEqualTo("onetwo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatesJson() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/updates")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"one\",\"two\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isEqualTo("[\"one\",\"two\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/addFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody())
|
||||
.isEqualTo("[{\"value\":\"foo\"},{\"value\":\"bar\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeout() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/timeout")).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/empty"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[]");
|
||||
@@ -176,22 +178,23 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void sentences() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/sentences")).build(), String.class)
|
||||
.getBody()).isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sentencesAcceptAny() throws Exception {
|
||||
assertThat(rest.exchange(
|
||||
RequestEntity.get(new URI("/sentences")).accept(MediaType.ALL).build(),
|
||||
String.class).getBody())
|
||||
.isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
assertThat(
|
||||
this.rest
|
||||
.exchange(RequestEntity.get(new URI("/sentences"))
|
||||
.accept(MediaType.ALL).build(), String.class)
|
||||
.getBody()).isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sentencesAcceptJson() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.get(new URI("/sentences"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(),
|
||||
@@ -203,7 +206,7 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void uppercase() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"[FOO]\",\"[BAR]\"]");
|
||||
@@ -211,7 +214,7 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/upFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class);
|
||||
assertThat(result.getBody())
|
||||
@@ -220,7 +223,7 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void transform() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/transform")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"[FOO]\",\"[BAR]\"]");
|
||||
@@ -228,7 +231,7 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void postMore() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/post/more")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"[FOO]\",\"[BAR]\"]");
|
||||
@@ -236,21 +239,21 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseGet() throws Exception {
|
||||
assertThat(rest.exchange(RequestEntity.get(new URI("/uppercase/foo"))
|
||||
assertThat(this.rest.exchange(RequestEntity.get(new URI("/uppercase/foo"))
|
||||
.accept(MediaType.TEXT_PLAIN).build(), String.class).getBody())
|
||||
.isEqualTo("[FOO]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertGet() throws Exception {
|
||||
assertThat(rest.exchange(RequestEntity.get(new URI("/wrap/123"))
|
||||
assertThat(this.rest.exchange(RequestEntity.get(new URI("/wrap/123"))
|
||||
.accept(MediaType.TEXT_PLAIN).build(), String.class).getBody())
|
||||
.isEqualTo("..123..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertGetJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/entity/321"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("{\"value\":321}");
|
||||
@@ -259,7 +262,7 @@ public class FluxRestApplicationTests {
|
||||
@Test
|
||||
public void uppercaseJsonStream() throws Exception {
|
||||
assertThat(
|
||||
rest.exchange(
|
||||
this.rest.exchange(
|
||||
RequestEntity.post(new URI("/maps"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"),
|
||||
@@ -269,7 +272,7 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseSSE() throws Exception {
|
||||
assertThat(rest.exchange(RequestEntity.post(new URI("/uppercase"))
|
||||
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]"));
|
||||
@@ -277,9 +280,10 @@ public class FluxRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void altSSE() throws Exception {
|
||||
assertThat(rest.exchange(RequestEntity.post(new URI("/alt")).accept(EVENT_STREAM)
|
||||
.contentType(MediaType.APPLICATION_JSON).body("[\"foo\",\"bar\"]"),
|
||||
String.class).getBody()).isEqualTo(sse("[FOO]", "[BAR]"));
|
||||
assertThat(this.rest.exchange(RequestEntity.post(new URI("/alt"))
|
||||
.accept(EVENT_STREAM).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class).getBody())
|
||||
.isEqualTo(sse("[FOO]", "[BAR]"));
|
||||
}
|
||||
|
||||
private String sse(String... values) {
|
||||
@@ -396,6 +400,7 @@ public class FluxRestApplicationTests {
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
|
||||
private String value;
|
||||
|
||||
public Foo(String value) {
|
||||
@@ -406,11 +411,13 @@ public class FluxRestApplicationTests {
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -27,6 +27,8 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -51,13 +53,10 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Tests for vanilla MVC handling (no function layer). Validates the MVC customizations
|
||||
* that are added in this project independently of the specific concerns of function.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@@ -66,28 +65,31 @@ import reactor.core.publisher.Mono;
|
||||
public class MvcRestApplicationTests {
|
||||
|
||||
private static final MediaType EVENT_STREAM = MediaType.valueOf("text/event-stream");
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Autowired
|
||||
private TestConfiguration test;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
test.list.clear();
|
||||
this.test.list.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wordsSSE() throws Exception {
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.get(new URI("/words")).accept(EVENT_STREAM).build(),
|
||||
String.class).getBody()).isEqualTo(sse("foo", "bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wordsJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -96,7 +98,7 @@ public class MvcRestApplicationTests {
|
||||
@Test
|
||||
@Ignore("Fix error handling")
|
||||
public void errorJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/bang"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\"]");
|
||||
@@ -104,7 +106,7 @@ public class MvcRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -112,7 +114,7 @@ public class MvcRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void foos() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/foos")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody())
|
||||
@@ -121,7 +123,7 @@ public class MvcRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void getMore() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/get/more")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -130,44 +132,44 @@ public class MvcRestApplicationTests {
|
||||
@Test
|
||||
@Ignore("Should this even work? Or do we need to be explicit about the JSON?")
|
||||
public void updates() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.post(new URI("/updates")).body("one\ntwo"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isEqualTo("onetwo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatesJson() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/updates")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"one\",\"two\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isEqualTo("[\"one\",\"two\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/addFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody())
|
||||
.isEqualTo("[{\"value\":\"foo\"},{\"value\":\"bar\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeout() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/timeout")).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/empty"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[]");
|
||||
@@ -175,22 +177,23 @@ public class MvcRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void sentences() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/sentences")).build(), String.class)
|
||||
.getBody()).isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sentencesAcceptAny() throws Exception {
|
||||
assertThat(rest.exchange(
|
||||
RequestEntity.get(new URI("/sentences")).accept(MediaType.ALL).build(),
|
||||
String.class).getBody())
|
||||
.isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
assertThat(
|
||||
this.rest
|
||||
.exchange(RequestEntity.get(new URI("/sentences"))
|
||||
.accept(MediaType.ALL).build(), String.class)
|
||||
.getBody()).isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sentencesAcceptJson() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.get(new URI("/sentences"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(),
|
||||
@@ -202,7 +205,7 @@ public class MvcRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void uppercase() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"[FOO]\",\"[BAR]\"]");
|
||||
@@ -210,7 +213,7 @@ public class MvcRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/upFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class);
|
||||
assertThat(result.getBody())
|
||||
@@ -219,7 +222,7 @@ public class MvcRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void transform() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/transform")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"[FOO]\",\"[BAR]\"]");
|
||||
@@ -227,7 +230,7 @@ public class MvcRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void postMore() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/post/more")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"[FOO]\",\"[BAR]\"]");
|
||||
@@ -235,17 +238,19 @@ public class MvcRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseGet() {
|
||||
assertThat(rest.getForObject("/uppercase/foo", String.class)).isEqualTo("[FOO]");
|
||||
assertThat(this.rest.getForObject("/uppercase/foo", String.class))
|
||||
.isEqualTo("[FOO]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertGet() {
|
||||
assertThat(rest.getForObject("/wrap/123", String.class)).isEqualTo("..123..");
|
||||
assertThat(this.rest.getForObject("/wrap/123", String.class))
|
||||
.isEqualTo("..123..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertGetJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/entity/321"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("{\"value\":321}");
|
||||
@@ -254,7 +259,7 @@ public class MvcRestApplicationTests {
|
||||
@Test
|
||||
public void uppercaseJsonStream() throws Exception {
|
||||
assertThat(
|
||||
rest.exchange(
|
||||
this.rest.exchange(
|
||||
RequestEntity.post(new URI("/maps"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"),
|
||||
@@ -264,7 +269,7 @@ public class MvcRestApplicationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseSSE() throws Exception {
|
||||
assertThat(rest.exchange(RequestEntity.post(new URI("/uppercase"))
|
||||
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]"));
|
||||
@@ -374,6 +379,7 @@ public class MvcRestApplicationTests {
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
|
||||
private String value;
|
||||
|
||||
public Foo(String value) {
|
||||
@@ -384,11 +390,13 @@ public class MvcRestApplicationTests {
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -22,6 +22,7 @@ import java.util.function.Function;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -39,8 +40,6 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -51,20 +50,22 @@ public class ComponentTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private Greeter greeter;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
assertThat(greeter).isNotNull();
|
||||
assertThat(this.greeter).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("FIXME")
|
||||
public void greeter() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.post(new URI("/greeter"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("World"),
|
||||
@@ -76,14 +77,17 @@ public class ComponentTests {
|
||||
@SpringBootApplication
|
||||
@ComponentScan
|
||||
protected static class TestConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@Component("greeter")
|
||||
protected static class Greeter implements Function<Flux<String>, Flux<String>> {
|
||||
|
||||
@Override
|
||||
public Flux<String> apply(Flux<String> flux) {
|
||||
return flux.map(name -> "Hello " + name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -20,6 +20,7 @@ import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
@@ -30,8 +31,6 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -48,16 +47,19 @@ public class ExplicitNonFunctionalTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
client.post().uri("/").body(Mono.just("foo"), String.class).exchange()
|
||||
this.client.post().uri("/").body(Mono.just("foo"), String.class).exchange()
|
||||
.expectStatus().isOk().expectBody(String.class).isEqualTo("FOO");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
protected static class TestConfiguration implements Function<String, String> {
|
||||
|
||||
@Override
|
||||
public String apply(String value) {
|
||||
return value.toUpperCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -20,6 +20,7 @@ import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
@@ -28,14 +29,12 @@ import org.springframework.cloud.function.context.test.FunctionalSpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
//Only need web-application-type because MVC is on the classpath
|
||||
// Only need web-application-type because MVC is on the classpath
|
||||
@FunctionalSpringBootTest("spring.main.web-application-type=reactive")
|
||||
@AutoConfigureWebTestClient
|
||||
public class FunctionalTests {
|
||||
@@ -45,15 +44,18 @@ public class FunctionalTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
client.post().uri("/").body(Mono.just("foo"), String.class).exchange()
|
||||
this.client.post().uri("/").body(Mono.just("foo"), String.class).exchange()
|
||||
.expectStatus().isOk().expectBody(String.class).isEqualTo("FOO");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
protected static class TestConfiguration implements Function<String, String> {
|
||||
|
||||
@Override
|
||||
public String apply(String value) {
|
||||
return value.toUpperCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -22,6 +22,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
@@ -30,8 +31,6 @@ import org.springframework.cloud.function.context.test.FunctionalSpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -46,18 +45,22 @@ public class FunctionalWithInputListTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
client.post().uri("/").body(Mono.just("[{\"value\":\"foo\"}, {\"value\":\"bar\"}]"), String.class)
|
||||
this.client.post().uri("/")
|
||||
.body(Mono.just("[{\"value\":\"foo\"}, {\"value\":\"bar\"}]"),
|
||||
String.class)
|
||||
.exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.isEqualTo("{\"value\":\"FOOBAR\"}");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
protected static class TestConfiguration implements Function<List<Foo>, Foo> {
|
||||
|
||||
@Override
|
||||
public Foo apply(List<Foo> value) {
|
||||
return new Foo(value.stream().map(foo -> foo.getValue().toUpperCase())
|
||||
.collect(Collectors.joining()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
@@ -85,4 +88,5 @@ public class FunctionalWithInputListTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package org.springframework.cloud.function.test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
@@ -32,7 +31,7 @@ import org.springframework.cloud.function.context.test.FunctionalSpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -48,8 +47,11 @@ public class FunctionalWithInputSetTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
String reply = client.post().uri("/").body(Mono.just("[{\"value\":\"foo\"}, {\"value\":\"bar\"}]"), String.class)
|
||||
.exchange().expectStatus().isOk().expectBody(String.class).returnResult().getResponseBody();
|
||||
String reply = this.client.post().uri("/")
|
||||
.body(Mono.just("[{\"value\":\"foo\"}, {\"value\":\"bar\"}]"),
|
||||
String.class)
|
||||
.exchange().expectStatus().isOk().expectBody(String.class).returnResult()
|
||||
.getResponseBody();
|
||||
assertTrue(reply.contains("FOO"));
|
||||
assertTrue(reply.contains("BAR"));
|
||||
assertTrue(reply.contains("{\"value\":\""));
|
||||
@@ -57,11 +59,13 @@ public class FunctionalWithInputSetTests {
|
||||
|
||||
@SpringBootConfiguration
|
||||
protected static class TestConfiguration implements Function<Set<Foo>, Foo> {
|
||||
|
||||
@Override
|
||||
public Foo apply(Set<Foo> value) {
|
||||
return new Foo(value.stream().map(foo -> foo.getValue().toUpperCase())
|
||||
.collect(Collectors.joining()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
@@ -89,4 +93,5 @@ public class FunctionalWithInputSetTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -19,6 +19,7 @@ import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
@@ -29,10 +30,7 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
@@ -47,7 +45,7 @@ public class HeadersToMessageTests {
|
||||
|
||||
@Test
|
||||
public void testBodyAndCustomHeaderFromMessagePropagation() throws Exception {
|
||||
client.post().uri("/").body(Mono.just("foo"), String.class).exchange()
|
||||
this.client.post().uri("/").body(Mono.just("foo"), String.class).exchange()
|
||||
.expectStatus().isOk().expectHeader()
|
||||
.valueEquals("x-content-type", "application/xml").expectHeader()
|
||||
.valueEquals("foo", "bar").expectBody(String.class).isEqualTo("FOO");
|
||||
@@ -56,11 +54,15 @@ public class HeadersToMessageTests {
|
||||
@SpringBootConfiguration
|
||||
protected static class TestConfiguration
|
||||
implements Function<Message<String>, Message<String>> {
|
||||
|
||||
public Message<String> apply(Message<String> request) {
|
||||
Message<String> message = MessageBuilder.withPayload(request.getPayload().toUpperCase())
|
||||
Message<String> message = MessageBuilder
|
||||
.withPayload(request.getPayload().toUpperCase())
|
||||
.setHeader("X-Content-Type", "application/xml")
|
||||
.setHeader("foo", "bar").build();
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -20,6 +20,7 @@ import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
@@ -31,8 +32,6 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -48,16 +47,19 @@ public class ImplicitNonFunctionalTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
client.post().uri("/").body(Mono.just("foo"), String.class).exchange()
|
||||
this.client.post().uri("/").body(Mono.just("foo"), String.class).exchange()
|
||||
.expectStatus().isOk().expectBody(String.class).isEqualTo("FOO");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public Function<String, String> uppercase() {
|
||||
return value -> value.toUpperCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -20,6 +20,8 @@ import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -30,8 +32,6 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
@@ -39,7 +39,7 @@ import reactor.core.publisher.Mono;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest({ "spring.main.web-application-type=REACTIVE",
|
||||
"spring.functional.enabled=false",
|
||||
"spring.cloud.function.definition=uppercase|reverse"})
|
||||
"spring.cloud.function.definition=uppercase|reverse" })
|
||||
@AutoConfigureWebTestClient
|
||||
@DirtiesContext
|
||||
public class MoreThenOneFunctionRootMappingTests {
|
||||
@@ -49,13 +49,14 @@ public class MoreThenOneFunctionRootMappingTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
client.post().uri("/").body(Mono.just("star"), String.class).exchange()
|
||||
this.client.post().uri("/").body(Mono.just("star"), String.class).exchange()
|
||||
.expectStatus().isOk().expectBody(String.class).isEqualTo("RATS");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public Function<String, String> uppercase() {
|
||||
return v -> v.toUpperCase();
|
||||
@@ -65,5 +66,7 @@ public class MoreThenOneFunctionRootMappingTests {
|
||||
public Function<String, String> reverse() {
|
||||
return v -> new StringBuilder(v).reverse().toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -20,6 +20,7 @@ import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
@@ -28,14 +29,12 @@ import org.springframework.cloud.function.context.test.FunctionalSpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
//Only need web-application-type because MVC is on the classpath
|
||||
// Only need web-application-type because MVC is on the classpath
|
||||
@FunctionalSpringBootTest("spring.main.web-application-type=reactive")
|
||||
@AutoConfigureWebTestClient
|
||||
public class PojoTests {
|
||||
@@ -45,23 +44,30 @@ public class PojoTests {
|
||||
|
||||
@Test
|
||||
public void single() throws Exception {
|
||||
client.post().uri("/").body(Mono.just("{\"value\":\"foo\"}"), String.class).exchange()
|
||||
.expectStatus().isOk().expectBody(String.class).isEqualTo("{\"value\":\"FOO\"}");
|
||||
this.client.post().uri("/").body(Mono.just("{\"value\":\"foo\"}"), String.class)
|
||||
.exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.isEqualTo("{\"value\":\"FOO\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiple() throws Exception {
|
||||
client.post().uri("/").body(Mono.just("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class).exchange()
|
||||
.expectStatus().isOk().expectBody(String.class).isEqualTo("[{\"value\":\"FOO\"},{\"value\":\"BAR\"}]");
|
||||
this.client.post().uri("/")
|
||||
.body(Mono.just("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"),
|
||||
String.class)
|
||||
.exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.isEqualTo("[{\"value\":\"FOO\"},{\"value\":\"BAR\"}]");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
protected static class TestConfiguration implements Function<Foo, Foo> {
|
||||
|
||||
@Override
|
||||
public Foo apply(Foo value) {
|
||||
return new Foo(value.getValue().toUpperCase());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Foo {
|
||||
@@ -88,4 +94,4 @@ class Foo {
|
||||
return "Foo [value=" + this.value + "]";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018-2019 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -41,7 +41,6 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
@@ -50,7 +49,7 @@ import static org.junit.Assert.assertTrue;
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"spring.cloud.function.web.path=/functions",
|
||||
"spring.main.web-application-type=reactive" })
|
||||
@ContextConfiguration(classes= {RestApplication.class, TestConfiguration.class})
|
||||
@ContextConfiguration(classes = { RestApplication.class, TestConfiguration.class })
|
||||
public class HeadersToMessageTests {
|
||||
|
||||
@Autowired
|
||||
@@ -59,9 +58,10 @@ public class HeadersToMessageTests {
|
||||
@Test
|
||||
public void testBodyAndCustomHeaderFromMessagePropagation() throws Exception {
|
||||
// test POJO paylod
|
||||
ResponseEntity<String> postForEntity = rest.exchange(RequestEntity
|
||||
.post(new URI("/functions/employee")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
|
||||
ResponseEntity<String> postForEntity = this.rest
|
||||
.exchange(RequestEntity.post(new URI("/functions/employee"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
|
||||
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
|
||||
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
|
||||
assertEquals("application/xml",
|
||||
@@ -69,9 +69,8 @@ public class HeadersToMessageTests {
|
||||
assertEquals("bar", postForEntity.getHeaders().get("foo").get(0));
|
||||
|
||||
// test simple type payload
|
||||
postForEntity = rest.postForEntity(
|
||||
new URI("/functions/string"), "{\"name\":\"Bob\",\"age\":25}",
|
||||
String.class);
|
||||
postForEntity = this.rest.postForEntity(new URI("/functions/string"),
|
||||
"{\"name\":\"Bob\",\"age\":25}", String.class);
|
||||
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
|
||||
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
|
||||
assertEquals("application/xml",
|
||||
@@ -82,6 +81,7 @@ public class HeadersToMessageTests {
|
||||
@EnableAutoConfiguration
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@Bean({ "string" })
|
||||
public Function<Message<String>, Message<String>> functiono() {
|
||||
return request -> {
|
||||
@@ -95,29 +95,39 @@ public class HeadersToMessageTests {
|
||||
@Bean({ "employee" })
|
||||
public Function<Message<Employee>, Message<Employee>> function1() {
|
||||
return request -> {
|
||||
Message<Employee> message = MessageBuilder.withPayload(request.getPayload())
|
||||
Message<Employee> message = MessageBuilder
|
||||
.withPayload(request.getPayload())
|
||||
.setHeader("X-Content-Type", "application/xml")
|
||||
.setHeader("foo", "bar").build();
|
||||
return message;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused") // used by json converter
|
||||
private static class Employee {
|
||||
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
return this.age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -30,6 +30,7 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -53,44 +54,46 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=reactive")
|
||||
@ContextConfiguration(classes= {RestApplication.class, ApplicationConfiguration.class})
|
||||
@ContextConfiguration(classes = { RestApplication.class, ApplicationConfiguration.class })
|
||||
public class HttpGetIntegrationTests {
|
||||
|
||||
private static final MediaType EVENT_STREAM = MediaType.TEXT_EVENT_STREAM;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Autowired
|
||||
private ApplicationConfiguration test;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
test.list.clear();
|
||||
this.test.list.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticResource() {
|
||||
assertThat(rest.getForObject("/test.html", String.class)).contains("<body>Test");
|
||||
assertThat(this.rest.getForObject("/test.html", String.class))
|
||||
.contains("<body>Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wordsSSE() throws Exception {
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.get(new URI("/words")).accept(EVENT_STREAM).build(),
|
||||
String.class).getBody()).isEqualTo(sse("foo", "bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wordsJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -99,7 +102,7 @@ public class HttpGetIntegrationTests {
|
||||
@Test
|
||||
@Ignore("Fix error handling")
|
||||
public void errorJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/bang"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\"]");
|
||||
@@ -107,7 +110,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -115,7 +118,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void word() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.get(new URI("/word")).accept(MediaType.TEXT_PLAIN).build(),
|
||||
String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@@ -124,7 +127,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void foos() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/foos")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody())
|
||||
@@ -133,7 +136,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void getMore() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/get/more")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -141,7 +144,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void bareWords() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/bareWords")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -149,7 +152,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void timeoutJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/timeout"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\"]");
|
||||
@@ -157,7 +160,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void emptyJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/empty"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[]");
|
||||
@@ -165,22 +168,23 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void sentences() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/sentences")).build(), String.class)
|
||||
.getBody()).isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sentencesAcceptAny() throws Exception {
|
||||
assertThat(rest.exchange(
|
||||
RequestEntity.get(new URI("/sentences")).accept(MediaType.ALL).build(),
|
||||
String.class).getBody())
|
||||
.isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
assertThat(
|
||||
this.rest
|
||||
.exchange(RequestEntity.get(new URI("/sentences"))
|
||||
.accept(MediaType.ALL).build(), String.class)
|
||||
.getBody()).isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sentencesAcceptJson() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.get(new URI("/sentences"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(),
|
||||
@@ -192,7 +196,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void sentencesAcceptSse() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.get(new URI("/sentences")).accept(EVENT_STREAM).build(),
|
||||
String.class);
|
||||
assertThat(result.getBody())
|
||||
@@ -203,7 +207,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void postMoreFoo() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.get(new URI("/post/more/foo")).accept(MediaType.TEXT_PLAIN).build(),
|
||||
String.class);
|
||||
assertThat(result.getBody()).isEqualTo("(FOO)");
|
||||
@@ -211,7 +215,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseGet() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.get(new URI("/uppercase/foo")).accept(MediaType.TEXT_PLAIN).build(),
|
||||
String.class);
|
||||
assertThat(result.getBody()).isEqualTo("(FOO)");
|
||||
@@ -219,7 +223,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void convertGet() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.get(new URI("/wrap/123")).accept(MediaType.TEXT_PLAIN).build(),
|
||||
String.class);
|
||||
assertThat(result.getBody()).isEqualTo("..123..");
|
||||
@@ -227,13 +231,13 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void supplierFirst() {
|
||||
assertThat(rest.getForObject("/not/a/function", String.class))
|
||||
assertThat(this.rest.getForObject("/not/a/function", String.class))
|
||||
.isEqualTo("[\"hello\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertGetJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/entity/321"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("{\"value\":321}");
|
||||
@@ -339,6 +343,7 @@ public class HttpGetIntegrationTests {
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
|
||||
private String value;
|
||||
|
||||
public Foo(String value) {
|
||||
@@ -349,12 +354,13 @@ public class HttpGetIntegrationTests {
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -29,6 +29,8 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -57,9 +59,6 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@@ -69,23 +68,26 @@ import reactor.core.publisher.Mono;
|
||||
public class HttpPostIntegrationTests {
|
||||
|
||||
private static final MediaType EVENT_STREAM = MediaType.TEXT_EVENT_STREAM;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Autowired
|
||||
private ApplicationConfiguration test;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
test.list.clear();
|
||||
this.test.list.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void qualifierFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity.post(new URI("/foos"))
|
||||
.contentType(MediaType.APPLICATION_JSON).body("[\"foo\",\"bar\"]"),
|
||||
String.class);
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/foos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody())
|
||||
.isEqualTo("[{\"value\":\"[FOO]\"},{\"value\":\"[BAR]\"}]");
|
||||
@@ -93,47 +95,47 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void updates() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
RequestEntity.post(new URI("/updates")).contentType(MediaType.APPLICATION_JSON).body("[\"one\", \"two\"]"),
|
||||
String.class);
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/updates")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"one\", \"two\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatesJson() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/updates")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"one\",\"two\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/addFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bareUpdates() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/bareUpdates")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"one\",\"two\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isEqualTo("[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uppercase() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"(FOO)\",\"(BAR)\"]");
|
||||
@@ -141,7 +143,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void messages() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/messages")).contentType(MediaType.APPLICATION_JSON)
|
||||
.header("x-foo", "bar").body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getHeaders().getFirst("x-foo")).isEqualTo("bar");
|
||||
@@ -151,7 +153,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void headers() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/headers")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getHeaders().getFirst("foo")).isEqualTo("bar");
|
||||
@@ -161,7 +163,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseSingleValue() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.post(new URI("/uppercase"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("foo"),
|
||||
@@ -172,7 +174,7 @@ public class HttpPostIntegrationTests {
|
||||
@Test
|
||||
@Ignore("WebFlux would split the request body into lines: TODO make this work the same")
|
||||
public void uppercasePlainText() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.post(new URI("/uppercase"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("foo\nbar"),
|
||||
String.class);
|
||||
@@ -181,7 +183,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/upFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class);
|
||||
assertThat(result.getBody())
|
||||
@@ -191,7 +193,7 @@ public class HttpPostIntegrationTests {
|
||||
@Test
|
||||
public void uppercaseFoo() throws Exception {
|
||||
// Single Foo can be parsed
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/upFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"value\":\"foo\"}"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[{\"value\":\"FOO\"}]");
|
||||
@@ -199,7 +201,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void bareUppercaseFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/bareUpFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class);
|
||||
assertThat(result.getBody())
|
||||
@@ -208,18 +210,18 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void typelessFunctionPassingArray() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
.post(new URI("/typelessFunctionExpectingText")).contentType(MediaType.TEXT_PLAIN)
|
||||
.body("[{\"value\":\"foo\"}]"), String.class);
|
||||
assertThat(result.getBody())
|
||||
.isEqualTo("[{\"value\":\"foo\"}]");
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.post(new URI("/typelessFunctionExpectingText"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("[{\"value\":\"foo\"}]"),
|
||||
String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[{\"value\":\"foo\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bareUppercaseFoo() throws Exception {
|
||||
// Single Foo can be parsed and returns a single value if the function is defined
|
||||
// that way
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/bareUpFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"value\":\"foo\"}"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("{\"value\":\"FOO\"}");
|
||||
@@ -227,7 +229,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void bareUppercase() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/bareUppercase")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"(FOO)\",\"(BAR)\"]");
|
||||
@@ -235,7 +237,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void singleValuedText() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.post(new URI("/bareUppercase")).accept(MediaType.TEXT_PLAIN)
|
||||
.contentType(MediaType.TEXT_PLAIN).body("foo"),
|
||||
String.class);
|
||||
@@ -244,7 +246,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void transform() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/transform")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"(FOO)\",\"(BAR)\"]");
|
||||
@@ -252,7 +254,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void postMore() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/post/more")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"(FOO)\",\"(BAR)\"]");
|
||||
@@ -260,8 +262,11 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void convertPost() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity.post(new URI("/wrap"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("123"), String.class);
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.post(new URI("/wrap"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("123"),
|
||||
String.class);
|
||||
// Result is multi-valued so it has to come out as an array
|
||||
assertThat(result.getBody()).isEqualTo("[\"..123..\"]");
|
||||
}
|
||||
@@ -270,7 +275,7 @@ public class HttpPostIntegrationTests {
|
||||
public void convertPostJson() throws Exception {
|
||||
// If you POST a single value to a Function<Flux<Integer>,Flux<Integer>> it can't
|
||||
// determine if the output is single valued, so it has to send an array back
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.post(new URI("/doubler"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("123"),
|
||||
@@ -280,7 +285,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseJsonArray() throws Exception {
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.post(new URI("/maps"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
// The new line in the middle is optional
|
||||
@@ -291,7 +296,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseSSE() throws Exception {
|
||||
assertThat(rest.exchange(RequestEntity.post(new URI("/uppercase"))
|
||||
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)"));
|
||||
@@ -305,7 +310,7 @@ public class HttpPostIntegrationTests {
|
||||
map.put("A", Arrays.asList("1", "2", "3"));
|
||||
map.put("B", Arrays.asList("5", "6"));
|
||||
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.post(new URI("/sum")).accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED).body(map),
|
||||
String.class).getBody()).isEqualTo("[{\"A\":6,\"B\":11}]");
|
||||
@@ -319,7 +324,7 @@ public class HttpPostIntegrationTests {
|
||||
map.put("A", Arrays.asList("1", "2", "3"));
|
||||
map.put("B", Arrays.asList("5", "6"));
|
||||
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.post(new URI("/sum")).accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA).body(map),
|
||||
String.class).getBody()).isEqualTo("[{\"A\":6,\"B\":11}]");
|
||||
@@ -328,7 +333,7 @@ public class HttpPostIntegrationTests {
|
||||
@Test
|
||||
public void count() throws Exception {
|
||||
List<String> list = Arrays.asList("A", "B", "A");
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.post(new URI("/count")).accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_JSON).body(list),
|
||||
String.class).getBody()).isEqualTo("{\"A\":2,\"B\":1}");
|
||||
@@ -390,14 +395,14 @@ public class HttpPostIntegrationTests {
|
||||
return value -> {
|
||||
Assert.isInstanceOf(String.class, value);
|
||||
return value;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public Function<byte[],?> byteArrayInputFunction() {
|
||||
//// return value -> new Foo(value.getValue().trim().toUpperCase());
|
||||
// throw new UnsupportedOperationException("boom?");
|
||||
// }
|
||||
// @Bean
|
||||
// public Function<byte[],?> byteArrayInputFunction() {
|
||||
//// return value -> new Foo(value.getValue().trim().toUpperCase());
|
||||
// throw new UnsupportedOperationException("boom?");
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public Function<Flux<Integer>, Flux<String>> wrap() {
|
||||
@@ -422,22 +427,22 @@ public class HttpPostIntegrationTests {
|
||||
public Function<String, Foo> qualifier() {
|
||||
return value -> {
|
||||
return new Foo("[" + value.trim().toUpperCase() + "]");
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Consumer<Flux<String>> updates() {
|
||||
return flux -> flux.subscribe(value -> list.add(value));
|
||||
return flux -> flux.subscribe(value -> this.list.add(value));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Consumer<Flux<Foo>> addFoos() {
|
||||
return flux -> flux.subscribe(value -> list.add(value.getValue()));
|
||||
return flux -> flux.subscribe(value -> this.list.add(value.getValue()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Consumer<String> bareUpdates() {
|
||||
return value -> list.add(value);
|
||||
return value -> this.list.add(value);
|
||||
}
|
||||
|
||||
@Bean("not/a")
|
||||
@@ -457,9 +462,11 @@ public class HttpPostIntegrationTests {
|
||||
return flux -> flux.collect(HashMap::new,
|
||||
(map, word) -> map.merge(word, 1, Integer::sum));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
|
||||
private String value;
|
||||
|
||||
public Foo(String value) {
|
||||
@@ -470,12 +477,13 @@ public class HttpPostIntegrationTests {
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -21,6 +21,7 @@ import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -39,8 +40,6 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -49,17 +48,18 @@ import reactor.core.publisher.Flux;
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"spring.main.web-application-type=reactive",
|
||||
"spring.cloud.function.web.path=/functions", "debug" })
|
||||
@ContextConfiguration(classes= {RestApplication.class, TestConfiguration.class})
|
||||
@ContextConfiguration(classes = { RestApplication.class, TestConfiguration.class })
|
||||
public class PrefixTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.get(new URI("/functions/words")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -67,7 +67,7 @@ public class PrefixTests {
|
||||
|
||||
@Test
|
||||
public void missing() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
@@ -75,9 +75,12 @@ public class PrefixTests {
|
||||
@EnableAutoConfiguration
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@Bean({ "words", "get/more" })
|
||||
public Supplier<Flux<String>> words() {
|
||||
return () -> Flux.fromArray(new String[] { "foo", "bar" });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -21,6 +21,7 @@ import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -44,25 +45,24 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=reactive")
|
||||
@ContextConfiguration(classes= {RestApplication.class, TestConfiguration.class})
|
||||
@ContextConfiguration(classes = { RestApplication.class, TestConfiguration.class })
|
||||
public class SingletonTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -71,6 +71,7 @@ public class SingletonTests {
|
||||
@EnableAutoConfiguration
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public static BeanDefinitionRegistryPostProcessor processor() {
|
||||
return new BeanDefinitionRegistryPostProcessor() {
|
||||
@@ -91,12 +92,16 @@ public class SingletonTests {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class MySupplier implements Supplier<Flux<String>> {
|
||||
|
||||
@Override
|
||||
public Flux<String> get() {
|
||||
return Flux.just("foo", "bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -22,6 +22,7 @@ import java.util.function.Function;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -40,26 +41,25 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "")
|
||||
@ContextConfiguration(classes= {RestApplication.class, TestConfiguration.class})
|
||||
@ContextConfiguration(classes = { RestApplication.class, TestConfiguration.class })
|
||||
public class DefaultRouteTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Test
|
||||
@Ignore("FIXME")
|
||||
public void explicit() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.post(new URI("/uppercase")).body("foo"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("FOO");
|
||||
@@ -68,8 +68,8 @@ public class DefaultRouteTests {
|
||||
@Test
|
||||
@Ignore("FIXME")
|
||||
public void implicit() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
RequestEntity.post(new URI("/")).body("foo"), String.class);
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.post(new URI("/")).body("foo"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("FOO");
|
||||
}
|
||||
@@ -77,9 +77,12 @@ public class DefaultRouteTests {
|
||||
@EnableAutoConfiguration
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public Function<Flux<String>, Flux<String>> uppercase() {
|
||||
return flux -> flux.map(value -> value.toUpperCase());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -43,7 +43,6 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
@@ -59,9 +58,10 @@ public class HeadersToMessageTests {
|
||||
|
||||
@Test
|
||||
public void testBodyAndCustomHeaderFromMessagePropagation() throws Exception {
|
||||
HttpEntity<String> postForEntity = rest.exchange(RequestEntity
|
||||
.post(new URI("/functions/employee")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
|
||||
HttpEntity<String> postForEntity = this.rest
|
||||
.exchange(RequestEntity.post(new URI("/functions/employee"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
|
||||
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
|
||||
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
|
||||
assertEquals("application/xml",
|
||||
@@ -71,9 +71,11 @@ public class HeadersToMessageTests {
|
||||
|
||||
@Test
|
||||
public void testHeadersPropagatedByDefault() throws Exception {
|
||||
HttpEntity<String> postForEntity = rest.exchange(RequestEntity
|
||||
.post(new URI("/functions/vanilla")).contentType(MediaType.APPLICATION_JSON).header("x-context-type", "rubbish")
|
||||
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
|
||||
HttpEntity<String> postForEntity = this.rest
|
||||
.exchange(RequestEntity.post(new URI("/functions/vanilla"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("x-context-type", "rubbish")
|
||||
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
|
||||
assertEquals("{\"name\":\"Bob\",\"age\":25,\"foo\":\"bar\"}",
|
||||
postForEntity.getBody());
|
||||
assertTrue(postForEntity.getHeaders().containsKey("x-context-type"));
|
||||
@@ -83,6 +85,7 @@ public class HeadersToMessageTests {
|
||||
@EnableAutoConfiguration
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@Bean({ "employee" })
|
||||
public Function<Message<Map<String, Object>>, Message<Map<String, Object>>> function() {
|
||||
return request -> {
|
||||
@@ -102,5 +105,7 @@ public class HeadersToMessageTests {
|
||||
return message;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -30,6 +30,7 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -53,44 +54,46 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties="spring.main.web-application-type=servlet")
|
||||
@ContextConfiguration(classes= {RestApplication.class, ApplicationConfiguration.class})
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=servlet")
|
||||
@ContextConfiguration(classes = { RestApplication.class, ApplicationConfiguration.class })
|
||||
public class HttpGetIntegrationTests {
|
||||
|
||||
private static final MediaType EVENT_STREAM = MediaType.TEXT_EVENT_STREAM;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Autowired
|
||||
private ApplicationConfiguration test;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
test.list.clear();
|
||||
this.test.list.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticResource() {
|
||||
assertThat(rest.getForObject("/test.html", String.class)).contains("<body>Test");
|
||||
assertThat(this.rest.getForObject("/test.html", String.class))
|
||||
.contains("<body>Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wordsSSE() throws Exception {
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.get(new URI("/words")).accept(EVENT_STREAM).build(),
|
||||
String.class).getBody()).isEqualTo(sse("foo", "bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wordsJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -99,7 +102,7 @@ public class HttpGetIntegrationTests {
|
||||
@Test
|
||||
@Ignore("Fix error handling")
|
||||
public void errorJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/bang"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\"]");
|
||||
@@ -107,7 +110,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -115,7 +118,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void word() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/word")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("foo");
|
||||
@@ -123,7 +126,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void foos() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/foos")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody())
|
||||
@@ -132,7 +135,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void getMore() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/get/more")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -140,7 +143,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void bareWords() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/bareWords")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -148,7 +151,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void timeoutJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/timeout"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\"]");
|
||||
@@ -156,7 +159,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void emptyJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/empty"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[]");
|
||||
@@ -164,22 +167,23 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void sentences() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/sentences")).build(), String.class)
|
||||
.getBody()).isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sentencesAcceptAny() throws Exception {
|
||||
assertThat(rest.exchange(
|
||||
RequestEntity.get(new URI("/sentences")).accept(MediaType.ALL).build(),
|
||||
String.class).getBody())
|
||||
.isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
assertThat(
|
||||
this.rest
|
||||
.exchange(RequestEntity.get(new URI("/sentences"))
|
||||
.accept(MediaType.ALL).build(), String.class)
|
||||
.getBody()).isEqualTo("[[\"go\",\"home\"],[\"come\",\"back\"]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sentencesAcceptJson() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.get(new URI("/sentences"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(),
|
||||
@@ -191,7 +195,7 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void sentencesAcceptSse() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.get(new URI("/sentences")).accept(EVENT_STREAM).build(),
|
||||
String.class);
|
||||
assertThat(result.getBody())
|
||||
@@ -202,28 +206,31 @@ public class HttpGetIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void postMoreFoo() {
|
||||
assertThat(rest.getForObject("/post/more/foo", String.class)).isEqualTo("(FOO)");
|
||||
assertThat(this.rest.getForObject("/post/more/foo", String.class))
|
||||
.isEqualTo("(FOO)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uppercaseGet() {
|
||||
assertThat(rest.getForObject("/uppercase/foo", String.class)).isEqualTo("(FOO)");
|
||||
assertThat(this.rest.getForObject("/uppercase/foo", String.class))
|
||||
.isEqualTo("(FOO)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertGet() {
|
||||
assertThat(rest.getForObject("/wrap/123", String.class)).isEqualTo("..123..");
|
||||
assertThat(this.rest.getForObject("/wrap/123", String.class))
|
||||
.isEqualTo("..123..");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supplierFirst() {
|
||||
assertThat(rest.getForObject("/not/a/function", String.class))
|
||||
assertThat(this.rest.getForObject("/not/a/function", String.class))
|
||||
.isEqualTo("[\"hello\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertGetJson() throws Exception {
|
||||
assertThat(rest
|
||||
assertThat(this.rest
|
||||
.exchange(RequestEntity.get(new URI("/entity/321"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("{\"value\":321}");
|
||||
@@ -329,6 +336,7 @@ public class HttpGetIntegrationTests {
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
|
||||
private String value;
|
||||
|
||||
public Foo(String value) {
|
||||
@@ -339,12 +347,13 @@ public class HttpGetIntegrationTests {
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -29,6 +29,8 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -56,34 +58,35 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties="spring.main.web-application-type=servlet")
|
||||
@ContextConfiguration(classes= {RestApplication.class, ApplicationConfiguration.class})
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=servlet")
|
||||
@ContextConfiguration(classes = { RestApplication.class, ApplicationConfiguration.class })
|
||||
public class HttpPostIntegrationTests {
|
||||
|
||||
private static final MediaType EVENT_STREAM = MediaType.TEXT_EVENT_STREAM;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Autowired
|
||||
private ApplicationConfiguration test;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
test.list.clear();
|
||||
this.test.list.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void qualifierFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity.post(new URI("/foos"))
|
||||
.contentType(MediaType.APPLICATION_JSON).body("[\"foo\",\"bar\"]"),
|
||||
String.class);
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/foos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody())
|
||||
.isEqualTo("[{\"value\":\"[FOO]\"},{\"value\":\"[BAR]\"}]");
|
||||
@@ -91,48 +94,47 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void updates() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
RequestEntity.post(new URI("/updates")).contentType(MediaType.APPLICATION_JSON).body("[\"one\", \"two\"]"),
|
||||
String.class);
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/updates")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"one\", \"two\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatesJson() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/updates")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"one\",\"two\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/addFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(result.getBody())
|
||||
.isEqualTo(null);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bareUpdates() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/bareUpdates")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"one\",\"two\"]"), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(test.list).hasSize(2);
|
||||
assertThat(this.test.list).hasSize(2);
|
||||
assertThat(result.getBody()).isEqualTo("[]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uppercase() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"(FOO)\",\"(BAR)\"]");
|
||||
@@ -140,7 +142,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void messages() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/messages")).contentType(MediaType.APPLICATION_JSON)
|
||||
// Remove this when Spring 5.0.8 is used
|
||||
.accept(MediaType.valueOf("application/stream+json"))
|
||||
@@ -152,7 +154,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void headers() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/headers")).contentType(MediaType.APPLICATION_JSON)
|
||||
// Remove this when Spring 5.0.8 is used
|
||||
.accept(MediaType.valueOf("application/stream+json"))
|
||||
@@ -164,7 +166,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseSingleValue() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.post(new URI("/uppercase"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("foo"),
|
||||
@@ -176,7 +178,7 @@ public class HttpPostIntegrationTests {
|
||||
@Test
|
||||
@Ignore("WebFlux would split the request body into lines: TODO make this work the same")
|
||||
public void uppercasePlainText() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.post(new URI("/uppercase"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("foo\nbar"),
|
||||
String.class);
|
||||
@@ -185,7 +187,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/upFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class);
|
||||
assertThat(result.getBody())
|
||||
@@ -195,7 +197,7 @@ public class HttpPostIntegrationTests {
|
||||
@Test
|
||||
public void uppercaseFoo() throws Exception {
|
||||
// Single Foo can be parsed
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/upFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"value\":\"foo\"}"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[{\"value\":\"FOO\"}]");
|
||||
@@ -203,7 +205,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void bareUppercaseFoos() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/bareUpFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[{\"value\":\"foo\"},{\"value\":\"bar\"}]"), String.class);
|
||||
assertThat(result.getBody())
|
||||
@@ -214,7 +216,7 @@ public class HttpPostIntegrationTests {
|
||||
public void bareUppercaseFoo() throws Exception {
|
||||
// Single Foo can be parsed and returns a single value if the function is defined
|
||||
// that way
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/bareUpFoos")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"value\":\"foo\"}"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("{\"value\":\"FOO\"}");
|
||||
@@ -222,7 +224,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void bareUppercase() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/bareUppercase")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"(FOO)\",\"(BAR)\"]");
|
||||
@@ -230,7 +232,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void singleValuedText() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.post(new URI("/bareUppercase"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("foo"),
|
||||
@@ -240,7 +242,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void transform() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/transform")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"(FOO)\",\"(BAR)\"]");
|
||||
@@ -248,7 +250,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void postMore() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity
|
||||
.post(new URI("/post/more")).contentType(MediaType.APPLICATION_JSON)
|
||||
.body("[\"foo\",\"bar\"]"), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[\"(FOO)\",\"(BAR)\"]");
|
||||
@@ -256,8 +258,11 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void convertPost() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity.post(new URI("/wrap"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("123"), String.class);
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.post(new URI("/wrap"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("123"),
|
||||
String.class);
|
||||
// Result is multi-valued so it has to come out as an array
|
||||
assertThat(result.getBody()).isEqualTo("[\"..123..\"]");
|
||||
}
|
||||
@@ -266,7 +271,7 @@ public class HttpPostIntegrationTests {
|
||||
public void convertPostJson() throws Exception {
|
||||
// If you POST a single value to a Function<Flux<Integer>,Flux<Integer>> it can't
|
||||
// determine if the output is single valued, so it has to send an array back
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(
|
||||
RequestEntity.post(new URI("/doubler"))
|
||||
.contentType(MediaType.TEXT_PLAIN).body("123"),
|
||||
@@ -276,7 +281,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseJsonArray() throws Exception {
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.post(new URI("/maps"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
// The new line in the middle is optional
|
||||
@@ -287,7 +292,7 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void uppercaseSSE() throws Exception {
|
||||
assertThat(rest.exchange(RequestEntity.post(new URI("/uppercase"))
|
||||
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)"));
|
||||
@@ -301,7 +306,7 @@ public class HttpPostIntegrationTests {
|
||||
map.put("A", Arrays.asList("1", "2", "3"));
|
||||
map.put("B", Arrays.asList("5", "6"));
|
||||
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.post(new URI("/sum")).accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA).body(map),
|
||||
String.class).getBody()).isEqualTo("[{\"A\":6,\"B\":11}]");
|
||||
@@ -315,7 +320,7 @@ public class HttpPostIntegrationTests {
|
||||
map.put("A", Arrays.asList("1", "2", "3"));
|
||||
map.put("B", Arrays.asList("5", "6"));
|
||||
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.post(new URI("/sum")).accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA).body(map),
|
||||
String.class).getBody()).isEqualTo("[{\"A\":6,\"B\":11}]");
|
||||
@@ -324,7 +329,7 @@ public class HttpPostIntegrationTests {
|
||||
@Test
|
||||
public void count() throws Exception {
|
||||
List<String> list = Arrays.asList("A", "B", "A");
|
||||
assertThat(rest.exchange(
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.post(new URI("/count")).accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_JSON).body(list),
|
||||
String.class).getBody()).isEqualTo("{\"A\":2,\"B\":1}");
|
||||
@@ -407,17 +412,17 @@ public class HttpPostIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public Consumer<Flux<String>> updates() {
|
||||
return flux -> flux.subscribe(value -> list.add(value));
|
||||
return flux -> flux.subscribe(value -> this.list.add(value));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Consumer<Flux<Foo>> addFoos() {
|
||||
return flux -> flux.subscribe(value -> list.add(value.getValue()));
|
||||
return flux -> flux.subscribe(value -> this.list.add(value.getValue()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Consumer<String> bareUpdates() {
|
||||
return value -> list.add(value);
|
||||
return value -> this.list.add(value);
|
||||
}
|
||||
|
||||
@Bean("not/a")
|
||||
@@ -437,9 +442,11 @@ public class HttpPostIntegrationTests {
|
||||
return flux -> flux.collect(HashMap::new,
|
||||
(map, word) -> map.merge(word, 1, Integer::sum));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
|
||||
private String value;
|
||||
|
||||
public Foo(String value) {
|
||||
@@ -450,12 +457,13 @@ public class HttpPostIntegrationTests {
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -21,6 +21,7 @@ import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -39,8 +40,6 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -49,17 +48,18 @@ import reactor.core.publisher.Flux;
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"spring.main.web-application-type=servlet",
|
||||
"spring.cloud.function.web.path=/functions" })
|
||||
@ContextConfiguration(classes= {RestApplication.class, TestConfiguration.class})
|
||||
@ContextConfiguration(classes = { RestApplication.class, TestConfiguration.class })
|
||||
public class PrefixTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
ResponseEntity<String> result = this.rest.exchange(
|
||||
RequestEntity.get(new URI("/functions/words")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
@@ -67,7 +67,7 @@ public class PrefixTests {
|
||||
|
||||
@Test
|
||||
public void missing() throws Exception {
|
||||
ResponseEntity<String> result = rest
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
@@ -75,9 +75,12 @@ public class PrefixTests {
|
||||
@EnableAutoConfiguration
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@Bean({ "words", "get/more" })
|
||||
public Supplier<Flux<String>> words() {
|
||||
return () -> Flux.fromArray(new String[] { "foo", "bar" });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -21,6 +21,7 @@ import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -44,26 +45,25 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@ContextConfiguration(classes= {RestApplication.class, TestConfiguration.class})
|
||||
@ContextConfiguration(classes = { RestApplication.class, TestConfiguration.class })
|
||||
public class SingletonTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(
|
||||
RequestEntity.get(new URI("/words")).build(), String.class);
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words")).build(), String.class);
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]");
|
||||
}
|
||||
@@ -71,6 +71,7 @@ public class SingletonTests {
|
||||
@EnableAutoConfiguration
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public static BeanDefinitionRegistryPostProcessor processor() {
|
||||
return new BeanDefinitionRegistryPostProcessor() {
|
||||
@@ -85,17 +86,22 @@ public class SingletonTests {
|
||||
public void postProcessBeanDefinitionRegistry(
|
||||
BeanDefinitionRegistry registry) throws BeansException {
|
||||
// Simulates what happens when you add a compiled function
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(MySupplier.class);
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(
|
||||
MySupplier.class);
|
||||
registry.registerBeanDefinition("words", beanDefinition);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class MySupplier implements Supplier<Flux<String>> {
|
||||
|
||||
@Override
|
||||
public Flux<String> get() {
|
||||
return Flux.just("foo", "bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -49,21 +49,24 @@ public class SourceAutoConfigurationIntegrationTests {
|
||||
@Test
|
||||
public void fails() throws Exception {
|
||||
int count = 0;
|
||||
while(forwarder.isRunning() && count++<100) {
|
||||
while (this.forwarder.isRunning() && count++ < 100) {
|
||||
Thread.sleep(20);
|
||||
}
|
||||
// It completed
|
||||
assertThat(forwarder.isRunning()).isFalse();
|
||||
assertThat(this.forwarder.isRunning()).isFalse();
|
||||
// But failed
|
||||
assertThat(forwarder.isOk()).isFalse();
|
||||
assertThat(this.forwarder.isOk()).isFalse();
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@TestConfiguration
|
||||
public static class ApplicationConfiguration {
|
||||
|
||||
@Bean
|
||||
public Supplier<String> word() {
|
||||
return () -> "foo";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -54,12 +54,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
// in a webapp we have to explicitly enable the export
|
||||
"spring.cloud.function.web.supplier.enabled=true",
|
||||
// manually so we know the webapp is listening when we start
|
||||
"spring.cloud.function.web.supplier.autoStartup=false"})
|
||||
"spring.cloud.function.web.supplier.autoStartup=false" })
|
||||
@ContextConfiguration(classes = { RestApplication.class, ApplicationConfiguration.class })
|
||||
public class WebAppIntegrationTests {
|
||||
|
||||
|
||||
private static Log logger = LogFactory.getLog(WebAppIntegrationTests.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private SupplierExporter forwarder;
|
||||
|
||||
@@ -68,16 +68,18 @@ public class WebAppIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void posts() throws Exception {
|
||||
forwarder.start();
|
||||
app.latch.await(10, TimeUnit.SECONDS);
|
||||
assertThat(app.values).hasSize(1);
|
||||
this.forwarder.start();
|
||||
this.app.latch.await(10, TimeUnit.SECONDS);
|
||||
assertThat(this.app.values).hasSize(1);
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@TestConfiguration
|
||||
@RestController
|
||||
public static class ApplicationConfiguration {
|
||||
|
||||
private List<String> values = new ArrayList<>();
|
||||
|
||||
private CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
@Bean
|
||||
@@ -89,9 +91,11 @@ public class WebAppIntegrationTests {
|
||||
@PostMapping("/values")
|
||||
public String value(@RequestBody String body) {
|
||||
logger.info("Body: " + body);
|
||||
values.add(body);
|
||||
latch.countDown();
|
||||
this.values.add(body);
|
||||
this.latch.countDown();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
<html><body>Test</body></html>
|
||||
<html>
|
||||
<body>Test</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user