Update tests due to deprecations in Reactor

This commit is contained in:
Sam Brannen 2020-08-12 13:46:32 +02:00
parent 4d3dd9b9f6
commit 13183c89ce
4 changed files with 45 additions and 44 deletions

View File

@ -47,7 +47,7 @@ import org.springframework.stereotype.Controller;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Brian Clozel * @author Brian Clozel
*/ */
public class RSocketServerToClientIntegrationTests { class RSocketServerToClientIntegrationTests {
private static AnnotationConfigApplicationContext context; private static AnnotationConfigApplicationContext context;
@ -56,8 +56,7 @@ public class RSocketServerToClientIntegrationTests {
@BeforeAll @BeforeAll
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public static void setupOnce() { static void setupOnce() {
context = new AnnotationConfigApplicationContext(RSocketConfig.class); context = new AnnotationConfigApplicationContext(RSocketConfig.class);
RSocketMessageHandler messageHandler = context.getBean(RSocketMessageHandler.class); RSocketMessageHandler messageHandler = context.getBean(RSocketMessageHandler.class);
SocketAcceptor responder = messageHandler.responder(); SocketAcceptor responder = messageHandler.responder();
@ -69,34 +68,33 @@ public class RSocketServerToClientIntegrationTests {
} }
@AfterAll @AfterAll
public static void tearDownOnce() { static void tearDownOnce() {
server.dispose(); server.dispose();
} }
@Test @Test
public void echo() { void echo() {
connectAndRunTest("echo"); connectAndRunTest("echo");
} }
@Test @Test
public void echoAsync() { void echoAsync() {
connectAndRunTest("echo-async"); connectAndRunTest("echo-async");
} }
@Test @Test
public void echoStream() { void echoStream() {
connectAndRunTest("echo-stream"); connectAndRunTest("echo-stream");
} }
@Test @Test
public void echoChannel() { void echoChannel() {
connectAndRunTest("echo-channel"); connectAndRunTest("echo-channel");
} }
private static void connectAndRunTest(String connectionRoute) { private static void connectAndRunTest(String connectionRoute) {
context.getBean(ServerController.class).reset(); context.getBean(ServerController.class).reset();
RSocketStrategies strategies = context.getBean(RSocketStrategies.class); RSocketStrategies strategies = context.getBean(RSocketStrategies.class);
@ -131,11 +129,11 @@ public class RSocketServerToClientIntegrationTests {
volatile MonoProcessor<Void> result; volatile MonoProcessor<Void> result;
public void reset() { void reset() {
this.result = MonoProcessor.create(); this.result = MonoProcessor.fromSink(Sinks.one());
} }
public void await(Duration duration) { void await(Duration duration) {
this.result.block(duration); this.result.block(duration);
} }
@ -250,19 +248,19 @@ public class RSocketServerToClientIntegrationTests {
static class RSocketConfig { static class RSocketConfig {
@Bean @Bean
public ServerController serverController() { ServerController serverController() {
return new ServerController(); return new ServerController();
} }
@Bean @Bean
public RSocketMessageHandler serverMessageHandler() { RSocketMessageHandler serverMessageHandler() {
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setRSocketStrategies(rsocketStrategies()); handler.setRSocketStrategies(rsocketStrategies());
return handler; return handler;
} }
@Bean @Bean
public RSocketStrategies rsocketStrategies() { RSocketStrategies rsocketStrategies() {
return RSocketStrategies.create(); return RSocketStrategies.create();
} }
} }

View File

@ -593,7 +593,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
@MessageMapping("mono") @MessageMapping("mono")
public Mono<String> handleMono() { public Mono<String> handleMono() {
this.monoProcessor = MonoProcessor.create(); this.monoProcessor = MonoProcessor.fromSink(Sinks.one());
return this.monoProcessor; return this.monoProcessor;
} }

View File

@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import reactor.core.publisher.MonoProcessor; import reactor.core.publisher.MonoProcessor;
import reactor.core.publisher.Sinks;
import org.springframework.http.CacheControl; import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -41,13 +42,14 @@ import static org.mockito.Mockito.mock;
/** /**
* Unit tests for {@link HeaderAssertions}. * Unit tests for {@link HeaderAssertions}.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sam Brannen * @author Sam Brannen
*/ */
public class HeaderAssertionTests { class HeaderAssertionTests {
@Test @Test
public void valueEquals() { void valueEquals() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("foo", "bar"); headers.add("foo", "bar");
HeaderAssertions assertions = headerAssertions(headers); HeaderAssertions assertions = headerAssertions(headers);
@ -69,7 +71,7 @@ public class HeaderAssertionTests {
} }
@Test @Test
public void valueEqualsWithMultipleValues() { void valueEqualsWithMultipleValues() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("foo", "bar"); headers.add("foo", "bar");
headers.add("foo", "baz"); headers.add("foo", "baz");
@ -85,11 +87,10 @@ public class HeaderAssertionTests {
// Too few values // Too few values
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
assertions.valueEquals("foo", "bar")); assertions.valueEquals("foo", "bar"));
} }
@Test @Test
public void valueMatches() { void valueMatches() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
HeaderAssertions assertions = headerAssertions(headers); HeaderAssertions assertions = headerAssertions(headers);
@ -106,7 +107,7 @@ public class HeaderAssertionTests {
} }
@Test @Test
public void valuesMatch() { void valuesMatch() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("foo", "value1"); headers.add("foo", "value1");
headers.add("foo", "value2"); headers.add("foo", "value2");
@ -128,7 +129,7 @@ public class HeaderAssertionTests {
} }
@Test @Test
public void valueMatcher() { void valueMatcher() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("foo", "bar"); headers.add("foo", "bar");
HeaderAssertions assertions = headerAssertions(headers); HeaderAssertions assertions = headerAssertions(headers);
@ -137,7 +138,7 @@ public class HeaderAssertionTests {
} }
@Test @Test
public void valuesMatcher() { void valuesMatcher() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("foo", "bar"); headers.add("foo", "bar");
headers.add("foo", "baz"); headers.add("foo", "baz");
@ -147,7 +148,7 @@ public class HeaderAssertionTests {
} }
@Test @Test
public void exists() { void exists() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON);
HeaderAssertions assertions = headerAssertions(headers); HeaderAssertions assertions = headerAssertions(headers);
@ -162,7 +163,7 @@ public class HeaderAssertionTests {
} }
@Test @Test
public void doesNotExist() { void doesNotExist() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
HeaderAssertions assertions = headerAssertions(headers); HeaderAssertions assertions = headerAssertions(headers);
@ -178,7 +179,7 @@ public class HeaderAssertionTests {
} }
@Test @Test
public void contentTypeCompatibleWith() { void contentTypeCompatibleWith() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML); headers.setContentType(MediaType.APPLICATION_XML);
HeaderAssertions assertions = headerAssertions(headers); HeaderAssertions assertions = headerAssertions(headers);
@ -194,7 +195,7 @@ public class HeaderAssertionTests {
} }
@Test @Test
public void cacheControl() { void cacheControl() {
CacheControl control = CacheControl.maxAge(1, TimeUnit.HOURS).noTransform(); CacheControl control = CacheControl.maxAge(1, TimeUnit.HOURS).noTransform();
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
@ -210,7 +211,7 @@ public class HeaderAssertionTests {
} }
@Test @Test
public void expires() { void expires() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
ZonedDateTime expires = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")); ZonedDateTime expires = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
headers.setExpires(expires); headers.setExpires(expires);
@ -223,7 +224,7 @@ public class HeaderAssertionTests {
} }
@Test @Test
public void lastModified() { void lastModified() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
ZonedDateTime lastModified = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")); ZonedDateTime lastModified = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
headers.setLastModified(lastModified.toInstant().toEpochMilli()); headers.setLastModified(lastModified.toInstant().toEpochMilli());
@ -240,7 +241,7 @@ public class HeaderAssertionTests {
MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK); MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
response.getHeaders().putAll(responseHeaders); response.getHeaders().putAll(responseHeaders);
MonoProcessor<byte[]> emptyContent = MonoProcessor.create(); MonoProcessor<byte[]> emptyContent = MonoProcessor.fromSink(Sinks.one());
emptyContent.onComplete(); emptyContent.onComplete();
ExchangeResult result = new ExchangeResult(request, response, emptyContent, emptyContent, Duration.ZERO, null); ExchangeResult result = new ExchangeResult(request, response, emptyContent, emptyContent, Duration.ZERO, null);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2020 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.
@ -21,6 +21,7 @@ import java.time.Duration;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import reactor.core.publisher.MonoProcessor; import reactor.core.publisher.MonoProcessor;
import reactor.core.publisher.Sinks;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -34,12 +35,13 @@ import static org.mockito.Mockito.mock;
/** /**
* Unit tests for {@link StatusAssertions}. * Unit tests for {@link StatusAssertions}.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
*/ */
public class StatusAssertionTests { class StatusAssertionTests {
@Test @Test
public void isEqualTo() { void isEqualTo() {
StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT); StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT);
// Success // Success
@ -56,12 +58,12 @@ public class StatusAssertionTests {
} }
@Test // gh-23630 @Test // gh-23630
public void isEqualToWithCustomStatus() { void isEqualToWithCustomStatus() {
statusAssertions(600).isEqualTo(600); statusAssertions(600).isEqualTo(600);
} }
@Test @Test
public void reasonEquals() { void reasonEquals() {
StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT); StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT);
// Success // Success
@ -73,7 +75,7 @@ public class StatusAssertionTests {
} }
@Test @Test
public void statusSerius1xx() { void statusSerius1xx() {
StatusAssertions assertions = statusAssertions(HttpStatus.CONTINUE); StatusAssertions assertions = statusAssertions(HttpStatus.CONTINUE);
// Success // Success
@ -86,7 +88,7 @@ public class StatusAssertionTests {
} }
@Test @Test
public void statusSerius2xx() { void statusSerius2xx() {
StatusAssertions assertions = statusAssertions(HttpStatus.OK); StatusAssertions assertions = statusAssertions(HttpStatus.OK);
// Success // Success
@ -98,7 +100,7 @@ public class StatusAssertionTests {
} }
@Test @Test
public void statusSerius3xx() { void statusSerius3xx() {
StatusAssertions assertions = statusAssertions(HttpStatus.PERMANENT_REDIRECT); StatusAssertions assertions = statusAssertions(HttpStatus.PERMANENT_REDIRECT);
// Success // Success
@ -110,7 +112,7 @@ public class StatusAssertionTests {
} }
@Test @Test
public void statusSerius4xx() { void statusSerius4xx() {
StatusAssertions assertions = statusAssertions(HttpStatus.BAD_REQUEST); StatusAssertions assertions = statusAssertions(HttpStatus.BAD_REQUEST);
// Success // Success
@ -122,7 +124,7 @@ public class StatusAssertionTests {
} }
@Test @Test
public void statusSerius5xx() { void statusSerius5xx() {
StatusAssertions assertions = statusAssertions(HttpStatus.INTERNAL_SERVER_ERROR); StatusAssertions assertions = statusAssertions(HttpStatus.INTERNAL_SERVER_ERROR);
// Success // Success
@ -134,7 +136,7 @@ public class StatusAssertionTests {
} }
@Test @Test
public void matches() { void matches() {
StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT); StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT);
// Success // Success
@ -155,7 +157,7 @@ public class StatusAssertionTests {
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/")); MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/"));
MockClientHttpResponse response = new MockClientHttpResponse(status); MockClientHttpResponse response = new MockClientHttpResponse(status);
MonoProcessor<byte[]> emptyContent = MonoProcessor.create(); MonoProcessor<byte[]> emptyContent = MonoProcessor.fromSink(Sinks.one());
emptyContent.onComplete(); emptyContent.onComplete();
ExchangeResult result = new ExchangeResult(request, response, emptyContent, emptyContent, Duration.ZERO, null); ExchangeResult result = new ExchangeResult(request, response, emptyContent, emptyContent, Duration.ZERO, null);