Commit 985c8f75 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish RSocket support

parent 704b5fb2
......@@ -44,7 +44,7 @@ import org.springframework.web.util.pattern.PathPatternRouteMatcher;
@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class)
public class RSocketMessagingAutoConfiguration {
private static String PATHPATTERN_ROUTEMATCHER_CLASS = "org.springframework.web.util.pattern.PathPatternRouteMatcher";
private static final String PATHPATTERN_ROUTEMATCHER_CLASS = "org.springframework.web.util.pattern.PathPatternRouteMatcher";
@Bean
@ConditionalOnMissingBean
......
......@@ -35,7 +35,7 @@ public class RSocketProperties {
return this.server;
}
static class Server {
public static class Server {
/**
* Server port.
......
......@@ -48,7 +48,7 @@ public class RSocketRequesterAutoConfiguration {
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
public RSocketRequester.Builder rsocketRequesterBuilder(RSocketStrategies strategies) {
public RSocketRequester.Builder rSocketRequesterBuilder(RSocketStrategies strategies) {
return RSocketRequester.builder().rsocketStrategies(strategies);
}
......
......@@ -81,7 +81,7 @@ public class RSocketServerAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public ReactorResourceFactory reactorServerResourceFactory() {
public ReactorResourceFactory reactorResourceFactory() {
return new ReactorResourceFactory();
}
......@@ -109,7 +109,7 @@ public class RSocketServerAutoConfiguration {
static class OnRSocketWebServerCondition extends AllNestedConditions {
OnRSocketWebServerCondition() {
super(ConfigurationPhase.REGISTER_BEAN);
super(ConfigurationPhase.PARSE_CONFIGURATION);
}
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
......
......@@ -76,7 +76,7 @@ public class RSocketStrategiesAutoConfiguration {
@Bean
@Order(0)
@ConditionalOnBean(Jackson2ObjectMapperBuilder.class)
public RSocketStrategiesCustomizer jacksonCborStrategyCustomizer(Jackson2ObjectMapperBuilder builder) {
public RSocketStrategiesCustomizer jacksonCborRSocketStrategyCustomizer(Jackson2ObjectMapperBuilder builder) {
return (strategy) -> {
ObjectMapper objectMapper = builder.factory(new CBORFactory()).build();
strategy.decoder(new Jackson2CborDecoder(objectMapper, SUPPORTED_TYPES));
......@@ -96,7 +96,7 @@ public class RSocketStrategiesAutoConfiguration {
@Bean
@Order(1)
@ConditionalOnBean(ObjectMapper.class)
public RSocketStrategiesCustomizer jacksonJsonStrategyCustomizer(ObjectMapper objectMapper) {
public RSocketStrategiesCustomizer jacksonJsonRSocketStrategyCustomizer(ObjectMapper objectMapper) {
return (strategy) -> {
strategy.decoder(new Jackson2JsonDecoder(objectMapper, SUPPORTED_TYPES));
strategy.encoder(new Jackson2JsonEncoder(objectMapper, SUPPORTED_TYPES));
......
......@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class RSocketMessagingAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(RSocketMessagingAutoConfiguration.class))
.withUserConfiguration(BaseConfiguration.class);
......@@ -67,7 +67,7 @@ class RSocketMessagingAutoConfigurationTests {
.containsOnly("customMessageHandlerAcceptor"));
}
@Configuration
@Configuration(proxyBeanMethods = false)
static class BaseConfiguration {
@Bean
......@@ -78,7 +78,7 @@ class RSocketMessagingAutoConfigurationTests {
}
@Configuration
@Configuration(proxyBeanMethods = false)
static class CustomMessageHandlerAcceptor {
@Bean
......
......@@ -34,7 +34,7 @@ import static org.mockito.Mockito.mock;
*/
class RSocketRequesterAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
AutoConfigurations.of(RSocketStrategiesAutoConfiguration.class, RSocketRequesterAutoConfiguration.class));
@Test
......
......@@ -42,22 +42,20 @@ class RSocketServerAutoConfigurationTests {
@Test
void shouldNotCreateBeansByDefault() {
ApplicationContextRunner contextRunner = createContextRunner();
contextRunner.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
contextRunner().run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
.doesNotHaveBean(RSocketServerFactory.class).doesNotHaveBean(RSocketServerBootstrap.class));
}
@Test
void shouldNotCreateDefaultBeansForReactiveWebAppWithoutMapping() {
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner();
contextRunner.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
.doesNotHaveBean(RSocketServerFactory.class).doesNotHaveBean(RSocketServerBootstrap.class));
reactiveWebContextRunner()
.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
.doesNotHaveBean(RSocketServerFactory.class).doesNotHaveBean(RSocketServerBootstrap.class));
}
@Test
void shouldNotCreateDefaultBeansForReactiveWebAppWithWrongTransport() {
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner();
contextRunner
reactiveWebContextRunner()
.withPropertyValues("spring.rsocket.server.transport=tcp",
"spring.rsocket.server.mapping-path=/rsocket")
.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
......@@ -66,8 +64,7 @@ class RSocketServerAutoConfigurationTests {
@Test
void shouldCreateDefaultBeansForReactiveWebApp() {
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner();
contextRunner
reactiveWebContextRunner()
.withPropertyValues("spring.rsocket.server.transport=websocket",
"spring.rsocket.server.mapping-path=/rsocket")
.run((context) -> assertThat(context).hasSingleBean(RSocketWebSocketNettyRouteProvider.class));
......@@ -75,22 +72,22 @@ class RSocketServerAutoConfigurationTests {
@Test
void shouldCreateDefaultBeansForRSocketServerWhenPortIsSet() {
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner();
contextRunner.withPropertyValues("spring.rsocket.server.port=0").run((context) -> assertThat(context)
.hasSingleBean(RSocketServerFactory.class).hasSingleBean(RSocketServerBootstrap.class));
reactiveWebContextRunner().withPropertyValues("spring.rsocket.server.port=0")
.run((context) -> assertThat(context).hasSingleBean(RSocketServerFactory.class)
.hasSingleBean(RSocketServerBootstrap.class));
}
private ApplicationContextRunner createContextRunner() {
private ApplicationContextRunner contextRunner() {
return new ApplicationContextRunner().withUserConfiguration(BaseConfiguration.class)
.withConfiguration(AutoConfigurations.of(RSocketServerAutoConfiguration.class));
}
private ReactiveWebApplicationContextRunner createReactiveWebContextRunner() {
private ReactiveWebApplicationContextRunner reactiveWebContextRunner() {
return new ReactiveWebApplicationContextRunner().withUserConfiguration(BaseConfiguration.class)
.withConfiguration(AutoConfigurations.of(RSocketServerAutoConfiguration.class));
}
@Configuration
@Configuration(proxyBeanMethods = false)
static class BaseConfiguration {
@Bean
......
......@@ -16,10 +16,10 @@
package org.springframework.boot.autoconfigure.rsocket;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
......@@ -32,7 +32,6 @@ import org.springframework.http.codec.cbor.Jackson2CborDecoder;
import org.springframework.http.codec.cbor.Jackson2CborEncoder;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.messaging.rsocket.RSocketStrategies;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -44,9 +43,8 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class RSocketStrategiesAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withUserConfiguration(BaseConfiguration.class)
.withConfiguration(AutoConfigurations.of(RSocketStrategiesAutoConfiguration.class));
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
AutoConfigurations.of(JacksonAutoConfiguration.class, RSocketStrategiesAutoConfiguration.class));
@Test
void shouldCreateDefaultBeans() {
......@@ -82,22 +80,7 @@ class RSocketStrategiesAutoConfigurationTests {
});
}
@Configuration
static class BaseConfiguration {
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper();
}
@Bean
public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
return new Jackson2ObjectMapperBuilder();
}
}
@Configuration
@Configuration(proxyBeanMethods = false)
static class UserStrategies {
@Bean
......@@ -108,7 +91,7 @@ class RSocketStrategiesAutoConfigurationTests {
}
@Configuration
@Configuration(proxyBeanMethods = false)
static class StrategiesCustomizer {
@Bean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment