Refactor tests with ScriptedSubscriber
Reactor recently added the `ScriptedSubscriber` in its new `reactor-addons` module. This `Subscriber` revissits the previous `TestSubscriber` with many improvements, including: * scripting each expectation * builder API that guides you until the final verification step * virtual time support This commit refactor all existing tests to use this new infrastructure and removed the `TestSubscriber` implementation. Issue: SPR-14800
This commit is contained in:
@@ -23,6 +23,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -34,7 +35,6 @@ import org.springframework.http.codec.EncoderHttpMessageWriter;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
@@ -52,7 +52,9 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
||||
import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
|
||||
import org.springframework.web.server.session.MockWebSessionManager;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -97,9 +99,13 @@ public class DispatcherHandlerErrorTests {
|
||||
this.request.setUri("/does-not-exist");
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(this.exchange);
|
||||
|
||||
TestSubscriber.subscribe(publisher)
|
||||
.assertError(ResponseStatusException.class)
|
||||
.assertErrorMessage("Request failure [status: 404, reason: \"No matching handler\"]");
|
||||
ScriptedSubscriber.<Void>create()
|
||||
.consumeErrorWith(error -> {
|
||||
assertThat(error, instanceOf(ResponseStatusException.class));
|
||||
assertThat(error.getMessage(),
|
||||
is("Request failure [status: 404, reason: \"No matching handler\"]"));
|
||||
})
|
||||
.verify(publisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,9 +113,12 @@ public class DispatcherHandlerErrorTests {
|
||||
this.request.setUri("/unknown-argument-type");
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(this.exchange);
|
||||
|
||||
TestSubscriber.subscribe(publisher)
|
||||
.assertError(IllegalStateException.class)
|
||||
.assertErrorWith(ex -> assertThat(ex.getMessage(), startsWith("No resolver for argument [0]")));
|
||||
ScriptedSubscriber.<Void>create()
|
||||
.consumeErrorWith(error -> {
|
||||
assertThat(error, instanceOf(IllegalStateException.class));
|
||||
assertThat(error.getMessage(), startsWith("No resolver for argument [0]"));
|
||||
})
|
||||
.verify(publisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,8 +126,11 @@ public class DispatcherHandlerErrorTests {
|
||||
this.request.setUri("/error-signal");
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(this.exchange);
|
||||
|
||||
TestSubscriber.subscribe(publisher)
|
||||
.assertErrorWith(ex -> assertSame(EXCEPTION, ex));
|
||||
ScriptedSubscriber.<Void>create()
|
||||
.consumeErrorWith(error -> {
|
||||
assertSame(EXCEPTION, error);
|
||||
})
|
||||
.verify(publisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,8 +138,11 @@ public class DispatcherHandlerErrorTests {
|
||||
this.request.setUri("/raise-exception");
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(this.exchange);
|
||||
|
||||
TestSubscriber.subscribe(publisher)
|
||||
.assertErrorWith(ex -> assertSame(EXCEPTION, ex));
|
||||
ScriptedSubscriber.<Void>create()
|
||||
.consumeErrorWith(error -> {
|
||||
assertSame(EXCEPTION, error);
|
||||
})
|
||||
.verify(publisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,9 +150,12 @@ public class DispatcherHandlerErrorTests {
|
||||
this.request.setUri("/unknown-return-type");
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(this.exchange);
|
||||
|
||||
TestSubscriber.subscribe(publisher)
|
||||
.assertError(IllegalStateException.class)
|
||||
.assertErrorWith(ex -> assertThat(ex.getMessage(), startsWith("No HandlerResultHandler")));
|
||||
ScriptedSubscriber.<Void>create()
|
||||
.consumeErrorWith(error -> {
|
||||
assertThat(error, instanceOf(IllegalStateException.class));
|
||||
assertThat(error.getMessage(), startsWith("No HandlerResultHandler"));
|
||||
})
|
||||
.verify(publisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,8 +163,11 @@ public class DispatcherHandlerErrorTests {
|
||||
this.request.setUri("/request-body").setHeader("Accept", "application/json").setBody("body");
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(this.exchange);
|
||||
|
||||
TestSubscriber.subscribe(publisher)
|
||||
.assertError(NotAcceptableStatusException.class);
|
||||
ScriptedSubscriber.<Void>create()
|
||||
.consumeErrorWith(error -> {
|
||||
assertThat(error, instanceOf(NotAcceptableStatusException.class));
|
||||
})
|
||||
.verify(publisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,9 +175,12 @@ public class DispatcherHandlerErrorTests {
|
||||
this.request.setUri("/request-body").setBody(Mono.error(EXCEPTION));
|
||||
Mono<Void> publisher = this.dispatcherHandler.handle(this.exchange);
|
||||
|
||||
TestSubscriber.subscribe(publisher)
|
||||
.assertError(ServerWebInputException.class)
|
||||
.assertErrorWith(ex -> assertSame(EXCEPTION, ex.getCause()));
|
||||
ScriptedSubscriber.<Void>create()
|
||||
.consumeErrorWith(error -> {
|
||||
assertThat(error, instanceOf(ServerWebInputException.class));
|
||||
assertSame(EXCEPTION, error.getCause());
|
||||
})
|
||||
.verify(publisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,15 +24,16 @@ import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.web.reactive.HandlerMapping;
|
||||
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
|
||||
import org.springframework.web.reactive.resource.AppCacheManifestTransformer;
|
||||
@@ -99,9 +100,11 @@ public class ResourceHandlerRegistryTests {
|
||||
ResourceWebHandler handler = getHandler("/resources/**");
|
||||
handler.handle(this.exchange).blockMillis(5000);
|
||||
|
||||
TestSubscriber.subscribe(this.response.getBody())
|
||||
.assertValuesWith(buf -> assertEquals("test stylesheet content",
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)));
|
||||
ScriptedSubscriber.<DataBuffer>create()
|
||||
.consumeNextWith(buf -> assertEquals("test stylesheet content",
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)))
|
||||
.expectComplete()
|
||||
.verify(this.response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,12 +23,12 @@ import org.junit.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.http.codec.BodyExtractors;
|
||||
import org.springframework.http.codec.ServerSentEvent;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.web.client.reactive.ClientRequest;
|
||||
import org.springframework.web.client.reactive.WebClient;
|
||||
|
||||
@@ -74,10 +74,11 @@ public class SseHandlerFunctionIntegrationTests
|
||||
.map(s -> (s.replace("\n", "")))
|
||||
.take(2);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(result)
|
||||
.await(Duration.ofSeconds(5))
|
||||
.assertValues("data:foo 0", "data:foo 1");
|
||||
ScriptedSubscriber.<String>create()
|
||||
.expectNext("data:foo 0")
|
||||
.expectNext("data:foo 1")
|
||||
.expectComplete()
|
||||
.verify(result, Duration.ofSeconds(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,10 +97,10 @@ public class SseHandlerFunctionIntegrationTests
|
||||
.takeUntil(s -> s.endsWith("foo 1\"}"))
|
||||
.reduce((s1, s2) -> s1 + s2);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(result)
|
||||
.await(Duration.ofSeconds(5))
|
||||
.assertValues("data:{\"name\":\"foo 0\"}data:{\"name\":\"foo 1\"}");
|
||||
ScriptedSubscriber.<String>create()
|
||||
.expectNext("data:{\"name\":\"foo 0\"}data:{\"name\":\"foo 1\"}")
|
||||
.expectComplete()
|
||||
.verify(result, Duration.ofSeconds(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,14 +118,11 @@ public class SseHandlerFunctionIntegrationTests
|
||||
.map(s -> s.replace("\n", ""))
|
||||
.take(2);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(result)
|
||||
.await(Duration.ofSeconds(5))
|
||||
.assertValues(
|
||||
"id:0:bardata:foo",
|
||||
"id:1:bardata:foo"
|
||||
);
|
||||
;
|
||||
ScriptedSubscriber.<String>create()
|
||||
.expectNext("id:0:bardata:foo")
|
||||
.expectNext("id:1:bardata:foo")
|
||||
.expectComplete()
|
||||
.verify(result, Duration.ofSeconds(5));
|
||||
}
|
||||
|
||||
private static class SseHandler {
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.web.reactive.resource;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.web.reactive.HandlerMapping.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
@@ -32,6 +28,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -48,17 +45,22 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.reactive.accept.CompositeContentTypeResolver;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
import org.springframework.web.server.MethodNotAllowedException;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
||||
import org.springframework.web.server.session.DefaultWebSessionManager;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.web.reactive.HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ResourceWebHandler}.
|
||||
*
|
||||
@@ -525,7 +527,10 @@ public class ResourceWebHandlerTests {
|
||||
this.request.addHeader("Range", "bytes= foo bar");
|
||||
this.exchange.getAttributes().put(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.txt");
|
||||
|
||||
TestSubscriber.subscribe(this.handler.handle(this.exchange)).assertComplete();
|
||||
ScriptedSubscriber.create()
|
||||
.expectNextCount(0)
|
||||
.expectComplete()
|
||||
.verify(this.handler.handle(this.exchange));
|
||||
|
||||
assertEquals(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE, this.response.getStatusCode());
|
||||
assertEquals("bytes", this.response.getHeaders().getFirst("Accept-Ranges"));
|
||||
@@ -550,8 +555,8 @@ public class ResourceWebHandlerTests {
|
||||
return previous;
|
||||
});
|
||||
|
||||
TestSubscriber.subscribe(reduced)
|
||||
.assertValuesWith(buf -> {
|
||||
ScriptedSubscriber.<DataBuffer>create()
|
||||
.consumeNextWith(buf -> {
|
||||
String content = DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8);
|
||||
String[] ranges = StringUtils.tokenizeToStringArray(content, "\r\n", false, true);
|
||||
|
||||
@@ -569,7 +574,9 @@ public class ResourceWebHandlerTests {
|
||||
assertEquals("Content-Type: text/plain", ranges[9]);
|
||||
assertEquals("Content-Range: bytes 8-9/10", ranges[10]);
|
||||
assertEquals("t.", ranges[11]);
|
||||
});
|
||||
})
|
||||
.expectComplete()
|
||||
.verify(reduced);
|
||||
}
|
||||
|
||||
@Test // SPR-14005
|
||||
@@ -591,9 +598,11 @@ public class ResourceWebHandlerTests {
|
||||
}
|
||||
|
||||
private void assertResponseBody(String responseBody) {
|
||||
TestSubscriber.subscribe(this.response.getBody())
|
||||
.assertValuesWith(buf -> assertEquals(responseBody,
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)));
|
||||
ScriptedSubscriber.<DataBuffer>create()
|
||||
.consumeNextWith(buf -> assertEquals(responseBody,
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)))
|
||||
.expectComplete()
|
||||
.verify(this.response.getBody());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ import java.util.Set;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.PathMatcher;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -100,7 +100,7 @@ public class HandlerMethodMappingTests {
|
||||
this.mapping.registerMapping("/fo?", this.handler, this.method2);
|
||||
Mono<Object> result = this.mapping.getHandler(createExchange(HttpMethod.GET, "/foo"));
|
||||
|
||||
TestSubscriber.subscribe(result).assertError(IllegalStateException.class);
|
||||
ScriptedSubscriber.create().expectError(IllegalStateException.class).verify(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,11 +193,13 @@ public class HandlerMethodMappingTests {
|
||||
@Controller
|
||||
private static class MyHandler {
|
||||
|
||||
@RequestMapping @SuppressWarnings("unused")
|
||||
@RequestMapping
|
||||
@SuppressWarnings("unused")
|
||||
public void handlerMethod1() {
|
||||
}
|
||||
|
||||
@RequestMapping @SuppressWarnings("unused")
|
||||
@RequestMapping
|
||||
@SuppressWarnings("unused")
|
||||
public void handlerMethod2() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ import java.util.Optional;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.web.reactive.HandlerResult;
|
||||
import org.springframework.web.reactive.result.ResolvableMethod;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
@@ -33,7 +33,10 @@ import org.springframework.web.server.UnsupportedMediaTypeStatusException;
|
||||
import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
||||
import org.springframework.web.server.session.MockWebSessionManager;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -89,10 +92,13 @@ public class InvocableHandlerMethodTests {
|
||||
InvocableHandlerMethod hm = handlerMethod("singleArg");
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
|
||||
TestSubscriber.subscribe(mono)
|
||||
.assertError(IllegalStateException.class)
|
||||
.assertErrorMessage("No resolver for argument [0] of type [java.lang.String] " +
|
||||
"on method [" + hm.getMethod().toGenericString() + "]");
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.consumeErrorWith(error -> {
|
||||
assertThat(error, instanceOf(IllegalStateException.class));
|
||||
assertThat(error.getMessage(), is("No resolver for argument [0] of type [java.lang.String] " +
|
||||
"on method [" + hm.getMethod().toGenericString() + "]"));
|
||||
})
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,9 +107,12 @@ public class InvocableHandlerMethodTests {
|
||||
addResolver(hm, Mono.error(new UnsupportedMediaTypeStatusException("boo")));
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
|
||||
TestSubscriber.subscribe(mono)
|
||||
.assertError(UnsupportedMediaTypeStatusException.class)
|
||||
.assertErrorMessage("Request failure [status: 415, reason: \"boo\"]");
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.consumeErrorWith(error -> {
|
||||
assertThat(error, instanceOf(UnsupportedMediaTypeStatusException.class));
|
||||
assertThat(error.getMessage(), is("Request failure [status: 415, reason: \"boo\"]"));
|
||||
})
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,11 +121,14 @@ public class InvocableHandlerMethodTests {
|
||||
addResolver(hm, Mono.just(1));
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
|
||||
TestSubscriber.subscribe(mono)
|
||||
.assertError(IllegalStateException.class)
|
||||
.assertErrorMessage("Failed to invoke controller with resolved arguments: " +
|
||||
"[0][type=java.lang.Integer][value=1] " +
|
||||
"on method [" + hm.getMethod().toGenericString() + "]");
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.consumeErrorWith(error -> {
|
||||
assertThat(error, instanceOf(IllegalStateException.class));
|
||||
assertThat(error.getMessage(), is("Failed to invoke controller with resolved arguments: " +
|
||||
"[0][type=java.lang.Integer][value=1] " +
|
||||
"on method [" + hm.getMethod().toGenericString() + "]"));
|
||||
})
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,9 +136,12 @@ public class InvocableHandlerMethodTests {
|
||||
InvocableHandlerMethod hm = handlerMethod("exceptionMethod");
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
|
||||
TestSubscriber.subscribe(mono)
|
||||
.assertError(IllegalStateException.class)
|
||||
.assertErrorMessage("boo");
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.consumeErrorWith(error -> {
|
||||
assertThat(error, instanceOf(IllegalStateException.class));
|
||||
assertThat(error.getMessage(), is("boo"));
|
||||
})
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,11 +158,14 @@ public class InvocableHandlerMethodTests {
|
||||
}
|
||||
|
||||
private void assertHandlerResultValue(Mono<HandlerResult> mono, String expected) {
|
||||
TestSubscriber.subscribe(mono).assertValuesWith(result -> {
|
||||
Optional<?> optional = result.getReturnValue();
|
||||
assertTrue(optional.isPresent());
|
||||
assertEquals(expected, optional.get());
|
||||
});
|
||||
ScriptedSubscriber.<HandlerResult>create()
|
||||
.consumeNextWith(result -> {
|
||||
Optional<?> optional = result.getReturnValue();
|
||||
assertTrue(optional.isPresent());
|
||||
assertEquals(expected, optional.get());
|
||||
})
|
||||
.expectComplete()
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.function.Consumer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
@@ -39,7 +40,6 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
@@ -164,7 +164,9 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
this.handlerMapping.registerHandler(new UserController());
|
||||
Mono<Object> mono = this.handlerMapping.getHandler(exchange);
|
||||
|
||||
TestSubscriber.subscribe(mono).assertError(NotAcceptableStatusException.class);
|
||||
ScriptedSubscriber.<Object>create()
|
||||
.expectError(NotAcceptableStatusException.class)
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
@Test // SPR-8462
|
||||
@@ -350,12 +352,14 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> void assertError(Mono<Object> mono, final Class<T> exceptionClass, final Consumer<T> consumer) {
|
||||
TestSubscriber
|
||||
.subscribe(mono)
|
||||
.assertErrorWith(ex -> {
|
||||
assertEquals(exceptionClass, ex.getClass());
|
||||
consumer.accept((T) ex);
|
||||
});
|
||||
|
||||
ScriptedSubscriber.<Object>create()
|
||||
.consumeErrorWith(error -> {
|
||||
assertEquals(exceptionClass, error.getClass());
|
||||
consumer.accept((T) error);
|
||||
|
||||
})
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.lang.reflect.Method;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.web.bind.annotation.CookieValue;
|
||||
import org.springframework.web.reactive.result.method.BindingContext;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
@@ -119,9 +119,10 @@ public class CookieValueMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void notFound() {
|
||||
Mono<Object> mono = resolver.resolveArgument(this.cookieParameter, this.bindingContext, this.exchange);
|
||||
TestSubscriber
|
||||
.subscribe(mono)
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.create()
|
||||
.expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
import rx.Observable;
|
||||
import rx.RxReactiveStreams;
|
||||
import rx.Single;
|
||||
@@ -44,7 +45,6 @@ import org.springframework.http.codec.DecoderHttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.web.reactive.result.ResolvableMethod;
|
||||
import org.springframework.web.reactive.result.method.BindingContext;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
@@ -128,10 +128,7 @@ public class HttpEntityArgumentResolverTests {
|
||||
ResolvableType type = httpEntityType(forClassWithGenerics(Mono.class, String.class));
|
||||
HttpEntity<Mono<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
TestSubscriber.subscribe(entity.getBody())
|
||||
.assertNoError()
|
||||
.assertComplete()
|
||||
.assertNoValues();
|
||||
ScriptedSubscriber.create().expectNextCount(0).expectComplete().verify(entity.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,10 +136,7 @@ public class HttpEntityArgumentResolverTests {
|
||||
ResolvableType type = httpEntityType(forClassWithGenerics(Flux.class, String.class));
|
||||
HttpEntity<Flux<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
TestSubscriber.subscribe(entity.getBody())
|
||||
.assertNoError()
|
||||
.assertComplete()
|
||||
.assertNoValues();
|
||||
ScriptedSubscriber.create().expectNextCount(0).expectComplete().verify(entity.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,9 +144,10 @@ public class HttpEntityArgumentResolverTests {
|
||||
ResolvableType type = httpEntityType(forClassWithGenerics(Single.class, String.class));
|
||||
HttpEntity<Single<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
TestSubscriber.subscribe(RxReactiveStreams.toPublisher(entity.getBody()))
|
||||
.assertNoValues()
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber
|
||||
.create().expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify(RxReactiveStreams.toPublisher(entity.getBody()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,9 +155,10 @@ public class HttpEntityArgumentResolverTests {
|
||||
ResolvableType type = httpEntityType(forClassWithGenerics(io.reactivex.Single.class, String.class));
|
||||
HttpEntity<io.reactivex.Single<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
TestSubscriber.subscribe(entity.getBody().toFlowable())
|
||||
.assertNoValues()
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber
|
||||
.create().expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify(entity.getBody().toFlowable());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,10 +166,10 @@ public class HttpEntityArgumentResolverTests {
|
||||
ResolvableType type = httpEntityType(forClassWithGenerics(Observable.class, String.class));
|
||||
HttpEntity<Observable<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
TestSubscriber.subscribe(RxReactiveStreams.toPublisher(entity.getBody()))
|
||||
.assertNoError()
|
||||
.assertComplete()
|
||||
.assertNoValues();
|
||||
ScriptedSubscriber
|
||||
.create().expectNextCount(0)
|
||||
.expectComplete()
|
||||
.verify(RxReactiveStreams.toPublisher(entity.getBody()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,10 +177,10 @@ public class HttpEntityArgumentResolverTests {
|
||||
ResolvableType type = httpEntityType(forClassWithGenerics(io.reactivex.Observable.class, String.class));
|
||||
HttpEntity<io.reactivex.Observable<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
TestSubscriber.subscribe(entity.getBody().toFlowable(BackpressureStrategy.BUFFER))
|
||||
.assertNoError()
|
||||
.assertComplete()
|
||||
.assertNoValues();
|
||||
ScriptedSubscriber
|
||||
.create().expectNextCount(0)
|
||||
.expectComplete()
|
||||
.verify(entity.getBody().toFlowable(BackpressureStrategy.BUFFER));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,10 +188,9 @@ public class HttpEntityArgumentResolverTests {
|
||||
ResolvableType type = httpEntityType(forClassWithGenerics(Flowable.class, String.class));
|
||||
HttpEntity<Flowable<String>> entity = resolveValueWithEmptyBody(type);
|
||||
|
||||
TestSubscriber.subscribe(entity.getBody())
|
||||
.assertNoError()
|
||||
.assertComplete()
|
||||
.assertNoValues();
|
||||
ScriptedSubscriber
|
||||
.create().expectNextCount(0)
|
||||
.expectComplete().verify(entity.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -266,7 +261,13 @@ public class HttpEntityArgumentResolverTests {
|
||||
HttpEntity<Flux<String>> httpEntity = resolveValue(type, body);
|
||||
|
||||
assertEquals(this.request.getHeaders(), httpEntity.getHeaders());
|
||||
TestSubscriber.subscribe(httpEntity.getBody()).assertValues("line1\n", "line2\n", "line3\n");
|
||||
ScriptedSubscriber
|
||||
.<String>create()
|
||||
.expectNext("line1\n")
|
||||
.expectNext("line2\n")
|
||||
.expectNext("line3\n")
|
||||
.expectComplete()
|
||||
.verify(httpEntity.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
@@ -45,7 +46,6 @@ import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -102,8 +102,7 @@ public class MessageReaderArgumentResolverTests {
|
||||
MethodParameter param = this.testMethod.resolveParam(type);
|
||||
Mono<Object> result = this.resolver.readBody(param, true, this.bindingContext, this.exchange);
|
||||
|
||||
TestSubscriber.subscribe(result)
|
||||
.assertError(UnsupportedMediaTypeStatusException.class);
|
||||
ScriptedSubscriber.create().expectError(UnsupportedMediaTypeStatusException.class).verify(result);
|
||||
}
|
||||
|
||||
// More extensive "empty body" tests in RequestBody- and HttpEntityArgumentResolverTests
|
||||
@@ -116,7 +115,7 @@ public class MessageReaderArgumentResolverTests {
|
||||
Mono<TestBean> result = (Mono<TestBean>) this.resolver.readBody(
|
||||
param, true, this.bindingContext, this.exchange).block();
|
||||
|
||||
TestSubscriber.subscribe(result).assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.create().expectError(ServerWebInputException.class).verify(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -263,9 +262,7 @@ public class MessageReaderArgumentResolverTests {
|
||||
MethodParameter param = this.testMethod.resolveParam(type);
|
||||
Mono<TestBean> mono = resolveValue(param, body);
|
||||
|
||||
TestSubscriber.subscribe(mono)
|
||||
.assertNoValues()
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.create().expectNextCount(0).expectError(ServerWebInputException.class).verify(mono);
|
||||
}
|
||||
|
||||
@Test @SuppressWarnings("unchecked")
|
||||
@@ -275,16 +272,17 @@ public class MessageReaderArgumentResolverTests {
|
||||
MethodParameter param = this.testMethod.resolveParam(type);
|
||||
Flux<TestBean> flux = resolveValue(param, body);
|
||||
|
||||
TestSubscriber.subscribe(flux)
|
||||
.assertValues(new TestBean("f1", "b1"))
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.<TestBean>create()
|
||||
.expectNext(new TestBean("f1", "b1"))
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify(flux);
|
||||
}
|
||||
|
||||
@Test // SPR-9964
|
||||
public void parameterizedMethodArgument() throws Exception {
|
||||
Method method = AbstractParameterizedController.class.getMethod("handleDto", Identifiable.class);
|
||||
HandlerMethod handlerMethod = new HandlerMethod(new ConcreteParameterizedController(), method);
|
||||
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
|
||||
HandlerMethod handlerMethod = new HandlerMethod(new ConcreteParameterizedController(), method);
|
||||
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
|
||||
SimpleBean simpleBean = resolveValue(methodParam, "{\"name\" : \"Jad\"}");
|
||||
|
||||
assertEquals("Jad", simpleBean.getName());
|
||||
@@ -417,7 +415,7 @@ public class MessageReaderArgumentResolverTests {
|
||||
void setId(Long id);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "serial" })
|
||||
@SuppressWarnings({"serial"})
|
||||
private static class SimpleBean implements Identifiable {
|
||||
|
||||
private Long id;
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
import rx.Completable;
|
||||
import rx.Observable;
|
||||
|
||||
@@ -42,6 +43,7 @@ import org.springframework.core.codec.ByteBufferEncoder;
|
||||
import org.springframework.core.codec.CharSequenceEncoder;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.codec.EncoderHttpMessageWriter;
|
||||
@@ -52,7 +54,6 @@ import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
@@ -136,7 +137,7 @@ public class MessageWriterResultHandlerTests {
|
||||
HttpMessageWriter<?> writer = new EncoderHttpMessageWriter<>(new ByteBufferEncoder());
|
||||
Mono<Void> mono = createResultHandler(writer).writeBody(body, returnType(type), this.exchange);
|
||||
|
||||
TestSubscriber.subscribe(mono).assertError(IllegalStateException.class);
|
||||
ScriptedSubscriber.create().expectError(IllegalStateException.class).verify(mono);
|
||||
}
|
||||
|
||||
@Test // SPR-12811
|
||||
@@ -193,9 +194,11 @@ public class MessageWriterResultHandlerTests {
|
||||
}
|
||||
|
||||
private void assertResponseBody(String responseBody) {
|
||||
TestSubscriber.subscribe(this.response.getBody())
|
||||
.assertValuesWith(buf -> assertEquals(responseBody,
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)));
|
||||
ScriptedSubscriber.<DataBuffer>create()
|
||||
.consumeNextWith(buf -> assertEquals(responseBody,
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)))
|
||||
.expectComplete()
|
||||
.verify(this.response.getBody());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Optional;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
@@ -32,7 +33,6 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
@@ -134,35 +134,40 @@ public class PathVariableMethodArgumentResolverTests {
|
||||
public void handleMissingValue() throws Exception {
|
||||
BindingContext bindingContext = new BindingContext();
|
||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedString, bindingContext, this.exchange);
|
||||
TestSubscriber
|
||||
.subscribe(mono)
|
||||
.assertError(ServerErrorException.class);
|
||||
ScriptedSubscriber
|
||||
.create().expectNextCount(0)
|
||||
.expectError(ServerErrorException.class)
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullIfNotRequired() throws Exception {
|
||||
BindingContext bindingContext = new BindingContext();
|
||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramNotRequired, bindingContext, this.exchange);
|
||||
TestSubscriber
|
||||
.subscribe(mono)
|
||||
.assertComplete()
|
||||
.assertNoValues();
|
||||
ScriptedSubscriber
|
||||
.create().expectNextCount(0)
|
||||
.expectComplete()
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrapEmptyWithOptional() throws Exception {
|
||||
BindingContext bindingContext = new BindingContext();
|
||||
Mono<Object> mono = this.resolver.resolveArgument(this.paramOptional, bindingContext, this.exchange);
|
||||
Object result = mono.block();
|
||||
TestSubscriber
|
||||
.subscribe(mono)
|
||||
.assertValues(Optional.empty());
|
||||
|
||||
ScriptedSubscriber.create()
|
||||
.consumeNextWith(value -> {
|
||||
assertTrue(value instanceof Optional);
|
||||
assertFalse(((Optional) value).isPresent());
|
||||
})
|
||||
.expectComplete()
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void handle(@PathVariable(value = "name") String param1, String param2,
|
||||
@PathVariable(name="name", required = false) String param3,
|
||||
@PathVariable(name = "name", required = false) String param3,
|
||||
@PathVariable("name") Optional<String> param4) {
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Optional;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
@@ -32,7 +33,6 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.RequestAttribute;
|
||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
@@ -89,9 +89,9 @@ public class RequestAttributeMethodArgumentResolverTests {
|
||||
public void resolve() throws Exception {
|
||||
MethodParameter param = initMethodParameter(0);
|
||||
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
||||
TestSubscriber
|
||||
.subscribe(mono)
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify(mono);
|
||||
|
||||
Foo foo = new Foo();
|
||||
this.exchange.getAttributes().put("foo", foo);
|
||||
|
||||
@@ -26,6 +26,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
import rx.Completable;
|
||||
import rx.Observable;
|
||||
import rx.RxReactiveStreams;
|
||||
import rx.Single;
|
||||
@@ -38,7 +40,6 @@ import org.springframework.http.codec.DecoderHttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.reactive.result.ResolvableMethod;
|
||||
import org.springframework.web.reactive.result.method.BindingContext;
|
||||
@@ -124,26 +125,26 @@ public class RequestBodyArgumentResolverTests {
|
||||
public void emptyBodyWithMono() throws Exception {
|
||||
ResolvableType type = forClassWithGenerics(Mono.class, String.class);
|
||||
|
||||
TestSubscriber.subscribe(resolveValueWithEmptyBody(type, true))
|
||||
.assertNoValues()
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.<Void>create().expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify((Mono<Void>) resolveValueWithEmptyBody(type, true));
|
||||
|
||||
TestSubscriber.subscribe(resolveValueWithEmptyBody(type, false))
|
||||
.assertNoValues()
|
||||
.assertComplete();
|
||||
ScriptedSubscriber.<Void>create().expectNextCount(0)
|
||||
.expectComplete()
|
||||
.verify((Mono<Void>) resolveValueWithEmptyBody(type, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyBodyWithFlux() throws Exception {
|
||||
ResolvableType type = forClassWithGenerics(Flux.class, String.class);
|
||||
|
||||
TestSubscriber.subscribe(resolveValueWithEmptyBody(type, true))
|
||||
.assertNoValues()
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.<Void>create().expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify((Flux<Void>) resolveValueWithEmptyBody(type, true));
|
||||
|
||||
TestSubscriber.subscribe(resolveValueWithEmptyBody(type, false))
|
||||
.assertNoValues()
|
||||
.assertComplete();
|
||||
ScriptedSubscriber.<Void>create().expectNextCount(0)
|
||||
.expectComplete()
|
||||
.verify((Flux<Void>) resolveValueWithEmptyBody(type, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,14 +152,14 @@ public class RequestBodyArgumentResolverTests {
|
||||
ResolvableType type = forClassWithGenerics(Single.class, String.class);
|
||||
|
||||
Single<String> single = resolveValueWithEmptyBody(type, true);
|
||||
TestSubscriber.subscribe(RxReactiveStreams.toPublisher(single))
|
||||
.assertNoValues()
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.<String>create().expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify(RxReactiveStreams.toPublisher(single));
|
||||
|
||||
single = resolveValueWithEmptyBody(type, false);
|
||||
TestSubscriber.subscribe(RxReactiveStreams.toPublisher(single))
|
||||
.assertNoValues()
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.<String>create().expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify(RxReactiveStreams.toPublisher(single));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,14 +167,14 @@ public class RequestBodyArgumentResolverTests {
|
||||
ResolvableType type = forClassWithGenerics(Observable.class, String.class);
|
||||
|
||||
Observable<String> observable = resolveValueWithEmptyBody(type, true);
|
||||
TestSubscriber.subscribe(RxReactiveStreams.toPublisher(observable))
|
||||
.assertNoValues()
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.<String>create().expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify(RxReactiveStreams.toPublisher(observable));
|
||||
|
||||
observable = resolveValueWithEmptyBody(type, false);
|
||||
TestSubscriber.subscribe(RxReactiveStreams.toPublisher(observable))
|
||||
.assertNoValues()
|
||||
.assertComplete();
|
||||
ScriptedSubscriber.<String>create().expectNextCount(0)
|
||||
.expectComplete()
|
||||
.verify(RxReactiveStreams.toPublisher(observable));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Map;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -35,7 +36,6 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
@@ -203,9 +203,9 @@ public class RequestHeaderMethodArgumentResolverTests {
|
||||
Mono<Object> mono = resolver.resolveArgument(
|
||||
this.paramNamedValueStringArray, this.bindingContext, this.exchange);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(mono)
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Optional;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -34,7 +35,6 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
@@ -159,9 +159,9 @@ public class RequestParamMethodArgumentResolverTests {
|
||||
Mono<Object> mono = this.resolver.resolveArgument(
|
||||
this.paramNamedStringArray, this.bindingContext, this.exchange);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(mono)
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.expectError(ServerWebInputException.class)
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
import rx.Completable;
|
||||
import rx.Single;
|
||||
|
||||
@@ -36,6 +37,7 @@ import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.ByteBufferEncoder;
|
||||
import org.springframework.core.codec.CharSequenceEncoder;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -48,7 +50,6 @@ import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.reactive.HandlerResult;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
||||
@@ -64,8 +65,8 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.core.ResolvableType.forClassWithGenerics;
|
||||
import static org.springframework.http.ResponseEntity.ok;
|
||||
import static org.springframework.http.ResponseEntity.notFound;
|
||||
import static org.springframework.http.ResponseEntity.ok;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ResponseEntityResultHandler}. When adding a test also
|
||||
@@ -113,7 +114,8 @@ public class ResponseEntityResultHandlerTests {
|
||||
}
|
||||
|
||||
|
||||
@Test @SuppressWarnings("ConstantConditions")
|
||||
@Test
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void supports() throws NoSuchMethodException {
|
||||
|
||||
Object value = null;
|
||||
@@ -201,7 +203,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
@Test
|
||||
public void handleReturnValueLastModified() throws Exception {
|
||||
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
||||
Instant oneMinAgo = currentTime.minusSeconds(60);
|
||||
Instant oneMinAgo = currentTime.minusSeconds(60);
|
||||
this.request.getHeaders().setIfModifiedSince(currentTime.toEpochMilli());
|
||||
|
||||
ResponseEntity<String> entity = ok().lastModified(oneMinAgo.toEpochMilli()).body("body");
|
||||
@@ -241,7 +243,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
this.request.getHeaders().setIfNoneMatch(eTag);
|
||||
|
||||
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
||||
Instant oneMinAgo = currentTime.minusSeconds(60);
|
||||
Instant oneMinAgo = currentTime.minusSeconds(60);
|
||||
this.request.getHeaders().setIfModifiedSince(currentTime.toEpochMilli());
|
||||
|
||||
ResponseEntity<String> entity = ok().eTag(eTag).lastModified(oneMinAgo.toEpochMilli()).body("body");
|
||||
@@ -258,7 +260,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
this.request.getHeaders().setIfNoneMatch(etag);
|
||||
|
||||
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
|
||||
Instant oneMinAgo = currentTime.minusSeconds(60);
|
||||
Instant oneMinAgo = currentTime.minusSeconds(60);
|
||||
this.request.getHeaders().setIfModifiedSince(currentTime.toEpochMilli());
|
||||
|
||||
ResponseEntity<String> entity = ok().eTag(newEtag).lastModified(oneMinAgo.toEpochMilli()).body("body");
|
||||
@@ -289,12 +291,14 @@ public class ResponseEntityResultHandlerTests {
|
||||
}
|
||||
|
||||
private void assertResponseBody(String responseBody) {
|
||||
TestSubscriber.subscribe(this.response.getBody())
|
||||
.assertValuesWith(buf -> assertEquals(responseBody,
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)));
|
||||
ScriptedSubscriber.<DataBuffer>create()
|
||||
.consumeNextWith(buf -> assertEquals(responseBody,
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)))
|
||||
.expectComplete()
|
||||
.verify(this.response.getBody());
|
||||
}
|
||||
|
||||
private void assertConditionalResponse(HttpStatus status, String body, String etag, Instant lastModified) {
|
||||
private void assertConditionalResponse(HttpStatus status, String body, String etag, Instant lastModified) throws Exception {
|
||||
assertEquals(status, this.response.getStatusCode());
|
||||
if (body != null) {
|
||||
assertResponseBody(body);
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Optional;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
@@ -32,7 +33,6 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.SessionAttribute;
|
||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
@@ -96,9 +96,7 @@ public class SessionAttributeMethodArgumentResolverTests {
|
||||
public void resolve() throws Exception {
|
||||
MethodParameter param = initMethodParameter(0);
|
||||
Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
|
||||
TestSubscriber
|
||||
.subscribe(mono)
|
||||
.assertError(ServerWebInputException.class);
|
||||
ScriptedSubscriber.create().expectError(ServerWebInputException.class).verify(mono);
|
||||
|
||||
Foo foo = new Foo();
|
||||
when(this.session.getAttribute("foo")).thenReturn(Optional.of(foo));
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.http.codec.BodyExtractors;
|
||||
import org.springframework.http.codec.ServerSentEvent;
|
||||
import org.springframework.http.server.reactive.AbstractHttpHandlerIntegrationTests;
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.reactive.ClientRequest;
|
||||
@@ -87,10 +87,11 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
||||
.map(s -> (s.replace("\n", "")))
|
||||
.take(2);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(result)
|
||||
.await(Duration.ofSeconds(5))
|
||||
.assertValues("data:foo 0", "data:foo 1");
|
||||
ScriptedSubscriber.<String>create()
|
||||
.expectNext("data:foo 0")
|
||||
.expectNext("data:foo 1")
|
||||
.expectComplete()
|
||||
.verify(result, Duration.ofSeconds(5L));
|
||||
}
|
||||
@Test
|
||||
public void sseAsPerson() throws Exception {
|
||||
@@ -108,10 +109,10 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
||||
.takeUntil(s -> s.endsWith("foo 1\"}"))
|
||||
.reduce((s1, s2) -> s1 + s2);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(result)
|
||||
.await(Duration.ofSeconds(5))
|
||||
.assertValues("data:{\"name\":\"foo 0\"}data:{\"name\":\"foo 1\"}");
|
||||
ScriptedSubscriber.<String>create()
|
||||
.expectNext("data:{\"name\":\"foo 0\"}data:{\"name\":\"foo 1\"}")
|
||||
.expectComplete()
|
||||
.verify(result, Duration.ofSeconds(5L));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,13 +129,11 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
||||
.map(s -> s.replace("\n", ""))
|
||||
.take(2);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(result)
|
||||
.await(Duration.ofSeconds(5))
|
||||
.assertValues(
|
||||
"id:0:bardata:foo",
|
||||
"id:1:bardata:foo"
|
||||
);
|
||||
ScriptedSubscriber.<String>create()
|
||||
.expectNext("id:0:bardata:foo")
|
||||
.expectNext("id:1:bardata:foo")
|
||||
.expectComplete()
|
||||
.verify(result, Duration.ofSeconds(5L));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,13 +151,11 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
||||
.map(s -> s.replace("\n", ""))
|
||||
.take(2);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(result)
|
||||
.await(Duration.ofSeconds(5))
|
||||
.assertValues(
|
||||
"id:0:bardata:foo",
|
||||
"id:1:bardata:foo"
|
||||
);
|
||||
ScriptedSubscriber.<String>create()
|
||||
.expectNext("id:0:bardata:foo")
|
||||
.expectNext("id:1:bardata:foo")
|
||||
.expectComplete()
|
||||
.verify(result, Duration.ofSeconds(5L));
|
||||
}
|
||||
|
||||
@RestController
|
||||
|
||||
@@ -26,8 +26,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.core.codec.CharSequenceEncoder;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -35,7 +37,6 @@ import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.ui.ExtendedModelMap;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.util.MimeType;
|
||||
@@ -45,7 +46,10 @@ import org.springframework.web.server.session.DefaultWebSessionManager;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
||||
/**
|
||||
@@ -151,10 +155,12 @@ public class HttpMessageWriterViewTests {
|
||||
|
||||
this.view.render(this.model, MediaType.APPLICATION_JSON, exchange);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(response.getBody())
|
||||
.assertValuesWith(buf -> assertEquals("{\"foo\":\"f\",\"bar\":\"b\"}",
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)));
|
||||
ScriptedSubscriber.<DataBuffer>create()
|
||||
.consumeNextWith( buf -> assertEquals("{\"foo\":\"f\",\"bar\":\"b\"}",
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8))
|
||||
)
|
||||
.expectComplete()
|
||||
.verify(response.getBody());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
import rx.Completable;
|
||||
import rx.Single;
|
||||
|
||||
@@ -42,10 +43,9 @@ import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.ui.ExtendedModelMap;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.ui.ModelMap;
|
||||
@@ -180,7 +180,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
|
||||
ModelMap model = new ExtendedModelMap().addAttribute("id", "123");
|
||||
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType(type), model);
|
||||
ViewResolutionResultHandler handler = createResultHandler(new TestViewResolver("account"));
|
||||
ViewResolutionResultHandler handler = createResultHandler(new TestViewResolver("account"));
|
||||
|
||||
this.request.setUri("/account");
|
||||
handler.handleResult(this.exchange, result).block(Duration.ofSeconds(5));
|
||||
@@ -204,7 +204,9 @@ public class ViewResolutionResultHandlerTests {
|
||||
this.request.setUri("/path");
|
||||
Mono<Void> mono = createResultHandler().handleResult(this.exchange, handlerResult);
|
||||
|
||||
TestSubscriber.subscribe(mono).assertErrorMessage("Could not resolve view with name 'account'.");
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.expectErrorWith(err -> err.getMessage().equals("Could not resolve view with name 'account'."))
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -237,7 +239,9 @@ public class ViewResolutionResultHandlerTests {
|
||||
|
||||
ViewResolutionResultHandler resultHandler = createResultHandler(new TestViewResolver("account"));
|
||||
Mono<Void> mono = resultHandler.handleResult(this.exchange, handlerResult);
|
||||
TestSubscriber.subscribe(mono).assertError(NotAcceptableStatusException.class);
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.expectError(NotAcceptableStatusException.class)
|
||||
.verify(mono);
|
||||
}
|
||||
|
||||
|
||||
@@ -271,7 +275,7 @@ public class ViewResolutionResultHandlerTests {
|
||||
private void testHandle(String path, ResolvableType returnType, Object returnValue,
|
||||
String responseBody, ViewResolver... resolvers) throws URISyntaxException {
|
||||
|
||||
testHandle(path, ResolvableMethod.onClass(TestController.class).returning(returnType),
|
||||
testHandle(path, ResolvableMethod.onClass(TestController.class).returning(returnType),
|
||||
returnValue, responseBody, resolvers);
|
||||
}
|
||||
|
||||
@@ -287,9 +291,11 @@ public class ViewResolutionResultHandlerTests {
|
||||
}
|
||||
|
||||
private void assertResponseBody(String responseBody) {
|
||||
TestSubscriber.subscribe(this.response.getBody())
|
||||
.assertValuesWith(buf -> assertEquals(responseBody,
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)));
|
||||
ScriptedSubscriber.<DataBuffer>create()
|
||||
.consumeNextWith(buf -> assertEquals(responseBody,
|
||||
DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)))
|
||||
.expectComplete()
|
||||
.verify(this.response.getBody());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import reactor.test.subscriber.ScriptedSubscriber;
|
||||
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
@@ -32,7 +33,6 @@ import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
import org.springframework.tests.TestSubscriber;
|
||||
import org.springframework.ui.ExtendedModelMap;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
@@ -123,10 +123,12 @@ public class FreeMarkerViewTests {
|
||||
model.addAttribute("hello", "hi FreeMarker");
|
||||
view.render(model, null, this.exchange);
|
||||
|
||||
TestSubscriber
|
||||
.subscribe(this.response.getBody())
|
||||
.assertValuesWith(dataBuffer ->
|
||||
assertEquals("<html><body>hi FreeMarker</body></html>", asString(dataBuffer)));
|
||||
ScriptedSubscriber.<DataBuffer>create()
|
||||
.consumeNextWith(buf -> {
|
||||
assertEquals("<html><body>hi FreeMarker</body></html>", asString(buf));
|
||||
})
|
||||
.expectComplete()
|
||||
.verify(this.response.getBody());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user