Skip to content

Commit

Permalink
Merge pull request spring-projects#17301 from spencergibb
Browse files Browse the repository at this point in the history
* pr/17301:
  Polish "Make rSocketServerBootstrap @ConditionalOnMissingBean"
  Make rSocketServerBootstrap @ConditionalOnMissingBean

Closes spring-projectsgh-17301
  • Loading branch information
bclozel committed Jun 25, 2019
2 parents 7405efa + 9166b6d commit e2d92b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public RSocketServerFactory rSocketServerFactory(RSocketProperties properties,
}

@Bean
@ConditionalOnMissingBean
public RSocketServerBootstrap rSocketServerBootstrap(RSocketServerFactory rSocketServerFactory,
RSocketMessageHandler rSocketMessageHandler) {
return new RSocketServerBootstrap(rSocketServerFactory, rSocketMessageHandler.serverAcceptor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

/**
* Tests for {@link RSocketServerAutoConfiguration}.
Expand Down Expand Up @@ -77,6 +78,12 @@ void shouldCreateDefaultBeansForRSocketServerWhenPortIsSet() {
.hasSingleBean(RSocketServerBootstrap.class));
}

@Test
void shoudUseCustomServerBootstrap() {
contextRunner().withUserConfiguration(CustomServerBootstrapConfig.class).run((context) -> assertThat(context)
.getBeanNames(RSocketServerBootstrap.class).containsExactly("customServerBootstrap"));
}

private ApplicationContextRunner contextRunner() {
return new ApplicationContextRunner().withUserConfiguration(BaseConfiguration.class)
.withConfiguration(AutoConfigurations.of(RSocketServerAutoConfiguration.class));
Expand All @@ -100,4 +107,14 @@ public RSocketMessageHandler messageHandler() {

}

@Configuration(proxyBeanMethods = false)
static class CustomServerBootstrapConfig {

@Bean
public RSocketServerBootstrap customServerBootstrap() {
return mock(RSocketServerBootstrap.class);
}

}

}

0 comments on commit e2d92b3

Please sign in to comment.