Polishing
This commit is contained in:
parent
7f1a8d78b5
commit
dd4468a74a
|
|
@ -52,10 +52,8 @@ import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.hamcrest.CoreMatchers.startsWith;
|
import static org.hamcrest.CoreMatchers.startsWith;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.springframework.http.MediaType.*;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the effect of exceptions at different stages of request processing by
|
* Test the effect of exceptions at different stages of request processing by
|
||||||
|
|
@ -72,7 +70,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||||
ctx.register(TestConfig.class);
|
ctx.register(TestConfig.class);
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
|
|
@ -81,7 +79,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noHandler() throws Exception {
|
public void noHandler() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/does-not-exist"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/does-not-exist"));
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
|
|
@ -95,7 +93,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void controllerReturnsMonoError() throws Exception {
|
public void controllerReturnsMonoError() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/error-signal"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/error-signal"));
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
|
|
@ -105,7 +103,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void controllerThrowsException() throws Exception {
|
public void controllerThrowsException() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/raise-exception"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/raise-exception"));
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
|
|
@ -115,7 +113,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unknownReturnType() throws Exception {
|
public void unknownReturnType() {
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-return-type"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-return-type"));
|
||||||
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
|
||||||
|
|
||||||
|
|
@ -128,7 +126,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void responseBodyMessageConversionError() throws Exception {
|
public void responseBodyMessageConversionError() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body"));
|
MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body"));
|
||||||
|
|
||||||
|
|
@ -140,7 +138,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestBodyError() throws Exception {
|
public void requestBodyError() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(
|
ServerWebExchange exchange = MockServerWebExchange.from(
|
||||||
MockServerHttpRequest.post("/request-body").body(Mono.error(EXCEPTION)));
|
MockServerHttpRequest.post("/request-body").body(Mono.error(EXCEPTION)));
|
||||||
|
|
||||||
|
|
@ -152,7 +150,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void webExceptionHandler() throws Exception {
|
public void webExceptionHandler() {
|
||||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-argument-type"));
|
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/unknown-argument-type"));
|
||||||
|
|
||||||
List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler());
|
List<WebExceptionHandler> handlers = Collections.singletonList(new ServerError500ExceptionHandler());
|
||||||
|
|
@ -202,12 +200,12 @@ public class DispatcherHandlerErrorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/raise-exception")
|
@RequestMapping("/raise-exception")
|
||||||
public void raiseException() throws Exception {
|
public void raiseException() {
|
||||||
throw EXCEPTION;
|
throw EXCEPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/unknown-return-type")
|
@RequestMapping("/unknown-return-type")
|
||||||
public Foo unknownReturnType() throws Exception {
|
public Foo unknownReturnType() {
|
||||||
return new Foo();
|
return new Foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.web.reactive;
|
package org.springframework.web.reactive;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
@ -32,11 +33,9 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||||
import org.springframework.web.method.ResolvableMethod;
|
import org.springframework.web.method.ResolvableMethod;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.*;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
import static org.mockito.Mockito.withSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link DispatcherHandler}.
|
* Unit tests for {@link DispatcherHandler}.
|
||||||
|
|
@ -49,8 +48,7 @@ public class DispatcherHandlerTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlerMappingOrder() throws Exception {
|
public void handlerMappingOrder() {
|
||||||
|
|
||||||
HandlerMapping hm1 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class));
|
HandlerMapping hm1 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class));
|
||||||
HandlerMapping hm2 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class));
|
HandlerMapping hm2 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class));
|
||||||
when(((Ordered) hm1).getOrder()).thenReturn(1);
|
when(((Ordered) hm1).getOrder()).thenReturn(1);
|
||||||
|
|
@ -90,6 +88,7 @@ public class DispatcherHandlerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class StringHandlerResultHandler implements HandlerResultHandler {
|
private static class StringHandlerResultHandler implements HandlerResultHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -105,4 +104,5 @@ public class DispatcherHandlerTests {
|
||||||
return exchange.getResponse().writeWith(Mono.just(dataBuffer));
|
return exchange.getResponse().writeWith(Mono.just(dataBuffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests for server response flushing behavior.
|
* Integration tests for server response flushing behavior.
|
||||||
|
*
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
|
|
@ -160,4 +161,5 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
|
||||||
return response.bufferFactory().wrap(bytes);
|
return response.bufferFactory().wrap(bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -114,7 +114,6 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
|
|
||||||
this.server.setHandler(createHttpHandler());
|
this.server.setHandler(createHttpHandler());
|
||||||
this.server.afterPropertiesSet();
|
this.server.afterPropertiesSet();
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
|
@ -128,7 +127,7 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void stop() throws Exception {
|
public void stop() {
|
||||||
if (this.client instanceof Lifecycle) {
|
if (this.client instanceof Lifecycle) {
|
||||||
((Lifecycle) this.client).stop();
|
((Lifecycle) this.client).stop();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,11 @@ import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.web.reactive.HandlerMapping;
|
import org.springframework.web.reactive.HandlerMapping;
|
||||||
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
|
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests with server-side {@link WebSocketHandler}s.
|
* Integration tests with server-side {@link WebSocketHandler}s.
|
||||||
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
|
public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
|
||||||
|
|
@ -192,6 +192,7 @@ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class SessionClosingHandler implements WebSocketHandler {
|
private static class SessionClosingHandler implements WebSocketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.web.reactive.socket.server.support;
|
package org.springframework.web.reactive.socket.server.support;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -42,10 +43,8 @@ import static org.mockito.Mockito.*;
|
||||||
*/
|
*/
|
||||||
public class HandshakeWebSocketServiceTests {
|
public class HandshakeWebSocketServiceTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sessionAttributePredicate() {
|
public void sessionAttributePredicate() {
|
||||||
|
|
||||||
MockWebSession session = new MockWebSession();
|
MockWebSession session = new MockWebSession();
|
||||||
session.getAttributes().put("a1", "v1");
|
session.getAttributes().put("a1", "v1");
|
||||||
session.getAttributes().put("a2", "v2");
|
session.getAttributes().put("a2", "v2");
|
||||||
|
|
@ -86,7 +85,6 @@ public class HandshakeWebSocketServiceTests {
|
||||||
|
|
||||||
HandshakeInfo handshakeInfo;
|
HandshakeInfo handshakeInfo;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler webSocketHandler,
|
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler webSocketHandler,
|
||||||
@Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
|
@Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue