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

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

View File

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

View File

@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.MonoProcessor;
import reactor.core.publisher.Sinks;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpHeaders;
@ -41,13 +42,14 @@ import static org.mockito.Mockito.mock;
/**
* Unit tests for {@link HeaderAssertions}.
*
* @author Rossen Stoyanchev
* @author Sam Brannen
*/
public class HeaderAssertionTests {
class HeaderAssertionTests {
@Test
public void valueEquals() {
void valueEquals() {
HttpHeaders headers = new HttpHeaders();
headers.add("foo", "bar");
HeaderAssertions assertions = headerAssertions(headers);
@ -69,7 +71,7 @@ public class HeaderAssertionTests {
}
@Test
public void valueEqualsWithMultipleValues() {
void valueEqualsWithMultipleValues() {
HttpHeaders headers = new HttpHeaders();
headers.add("foo", "bar");
headers.add("foo", "baz");
@ -85,11 +87,10 @@ public class HeaderAssertionTests {
// Too few values
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
assertions.valueEquals("foo", "bar"));
}
@Test
public void valueMatches() {
void valueMatches() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
HeaderAssertions assertions = headerAssertions(headers);
@ -106,7 +107,7 @@ public class HeaderAssertionTests {
}
@Test
public void valuesMatch() {
void valuesMatch() {
HttpHeaders headers = new HttpHeaders();
headers.add("foo", "value1");
headers.add("foo", "value2");
@ -128,7 +129,7 @@ public class HeaderAssertionTests {
}
@Test
public void valueMatcher() {
void valueMatcher() {
HttpHeaders headers = new HttpHeaders();
headers.add("foo", "bar");
HeaderAssertions assertions = headerAssertions(headers);
@ -137,7 +138,7 @@ public class HeaderAssertionTests {
}
@Test
public void valuesMatcher() {
void valuesMatcher() {
HttpHeaders headers = new HttpHeaders();
headers.add("foo", "bar");
headers.add("foo", "baz");
@ -147,7 +148,7 @@ public class HeaderAssertionTests {
}
@Test
public void exists() {
void exists() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HeaderAssertions assertions = headerAssertions(headers);
@ -162,7 +163,7 @@ public class HeaderAssertionTests {
}
@Test
public void doesNotExist() {
void doesNotExist() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
HeaderAssertions assertions = headerAssertions(headers);
@ -178,7 +179,7 @@ public class HeaderAssertionTests {
}
@Test
public void contentTypeCompatibleWith() {
void contentTypeCompatibleWith() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
HeaderAssertions assertions = headerAssertions(headers);
@ -194,7 +195,7 @@ public class HeaderAssertionTests {
}
@Test
public void cacheControl() {
void cacheControl() {
CacheControl control = CacheControl.maxAge(1, TimeUnit.HOURS).noTransform();
HttpHeaders headers = new HttpHeaders();
@ -210,7 +211,7 @@ public class HeaderAssertionTests {
}
@Test
public void expires() {
void expires() {
HttpHeaders headers = new HttpHeaders();
ZonedDateTime expires = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
headers.setExpires(expires);
@ -223,7 +224,7 @@ public class HeaderAssertionTests {
}
@Test
public void lastModified() {
void lastModified() {
HttpHeaders headers = new HttpHeaders();
ZonedDateTime lastModified = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
headers.setLastModified(lastModified.toInstant().toEpochMilli());
@ -240,7 +241,7 @@ public class HeaderAssertionTests {
MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK);
response.getHeaders().putAll(responseHeaders);
MonoProcessor<byte[]> emptyContent = MonoProcessor.create();
MonoProcessor<byte[]> emptyContent = MonoProcessor.fromSink(Sinks.one());
emptyContent.onComplete();
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");
* 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 reactor.core.publisher.MonoProcessor;
import reactor.core.publisher.Sinks;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
@ -34,12 +35,13 @@ import static org.mockito.Mockito.mock;
/**
* Unit tests for {@link StatusAssertions}.
*
* @author Rossen Stoyanchev
*/
public class StatusAssertionTests {
class StatusAssertionTests {
@Test
public void isEqualTo() {
void isEqualTo() {
StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT);
// Success
@ -56,12 +58,12 @@ public class StatusAssertionTests {
}
@Test // gh-23630
public void isEqualToWithCustomStatus() {
void isEqualToWithCustomStatus() {
statusAssertions(600).isEqualTo(600);
}
@Test
public void reasonEquals() {
void reasonEquals() {
StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT);
// Success
@ -73,7 +75,7 @@ public class StatusAssertionTests {
}
@Test
public void statusSerius1xx() {
void statusSerius1xx() {
StatusAssertions assertions = statusAssertions(HttpStatus.CONTINUE);
// Success
@ -86,7 +88,7 @@ public class StatusAssertionTests {
}
@Test
public void statusSerius2xx() {
void statusSerius2xx() {
StatusAssertions assertions = statusAssertions(HttpStatus.OK);
// Success
@ -98,7 +100,7 @@ public class StatusAssertionTests {
}
@Test
public void statusSerius3xx() {
void statusSerius3xx() {
StatusAssertions assertions = statusAssertions(HttpStatus.PERMANENT_REDIRECT);
// Success
@ -110,7 +112,7 @@ public class StatusAssertionTests {
}
@Test
public void statusSerius4xx() {
void statusSerius4xx() {
StatusAssertions assertions = statusAssertions(HttpStatus.BAD_REQUEST);
// Success
@ -122,7 +124,7 @@ public class StatusAssertionTests {
}
@Test
public void statusSerius5xx() {
void statusSerius5xx() {
StatusAssertions assertions = statusAssertions(HttpStatus.INTERNAL_SERVER_ERROR);
// Success
@ -134,7 +136,7 @@ public class StatusAssertionTests {
}
@Test
public void matches() {
void matches() {
StatusAssertions assertions = statusAssertions(HttpStatus.CONFLICT);
// Success
@ -155,7 +157,7 @@ public class StatusAssertionTests {
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/"));
MockClientHttpResponse response = new MockClientHttpResponse(status);
MonoProcessor<byte[]> emptyContent = MonoProcessor.create();
MonoProcessor<byte[]> emptyContent = MonoProcessor.fromSink(Sinks.one());
emptyContent.onComplete();
ExchangeResult result = new ExchangeResult(request, response, emptyContent, emptyContent, Duration.ZERO, null);