use of org.springframework.messaging.rsocket.RSocketStrategies in project spring-boot by spring-projects.
the class RSocketStrategiesAutoConfiguration method rSocketStrategies.
@Bean
@ConditionalOnMissingBean
public RSocketStrategies rSocketStrategies(ObjectProvider<RSocketStrategiesCustomizer> customizers) {
RSocketStrategies.Builder builder = RSocketStrategies.builder();
if (ClassUtils.isPresent(PATHPATTERN_ROUTEMATCHER_CLASS, null)) {
builder.routeMatcher(new PathPatternRouteMatcher());
}
customizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
return builder.build();
}
use of org.springframework.messaging.rsocket.RSocketStrategies in project spring-boot by spring-projects.
the class RSocketStrategiesAutoConfigurationTests method shouldUseStrategiesCustomizer.
@Test
void shouldUseStrategiesCustomizer() {
this.contextRunner.withUserConfiguration(StrategiesCustomizer.class).run((context) -> {
assertThat(context).getBeans(RSocketStrategies.class).hasSize(1);
RSocketStrategies strategies = context.getBean(RSocketStrategies.class);
assertThat(strategies.decoders()).hasAtLeastOneElementOfType(CustomDecoder.class);
assertThat(strategies.encoders()).hasAtLeastOneElementOfType(CustomEncoder.class);
});
}
use of org.springframework.messaging.rsocket.RSocketStrategies in project spring-framework by spring-projects.
the class RSocketMessageHandlerTests method getRSocketStrategiesReflectsCurrentState.
@Test
public void getRSocketStrategiesReflectsCurrentState() {
RSocketMessageHandler handler = new RSocketMessageHandler();
// 1. Set properties
handler.setDecoders(Collections.singletonList(new ByteArrayDecoder()));
handler.setEncoders(Collections.singletonList(new ByteArrayEncoder()));
handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
handler.setMetadataExtractor(new DefaultMetadataExtractor());
handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
RSocketStrategies strategies = handler.getRSocketStrategies();
assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
// 2. Set properties again
handler.setDecoders(Collections.singletonList(StringDecoder.allMimeTypes()));
handler.setEncoders(Collections.singletonList(CharSequenceEncoder.allMimeTypes()));
handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
handler.setMetadataExtractor(new DefaultMetadataExtractor());
handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
handler.afterPropertiesSet();
strategies = handler.getRSocketStrategies();
assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
}
use of org.springframework.messaging.rsocket.RSocketStrategies in project spring-framework by spring-projects.
the class RSocketMessageHandlerTests method getRSocketStrategies.
@Test
public void getRSocketStrategies() {
RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setDecoders(Collections.singletonList(new ByteArrayDecoder()));
handler.setEncoders(Collections.singletonList(new ByteArrayEncoder()));
handler.setRouteMatcher(new SimpleRouteMatcher(new AntPathMatcher()));
handler.setMetadataExtractor(new DefaultMetadataExtractor());
handler.setReactiveAdapterRegistry(new ReactiveAdapterRegistry());
RSocketStrategies strategies = handler.getRSocketStrategies();
assertThat(strategies).isNotNull();
assertThat(strategies.encoders()).isEqualTo(handler.getEncoders());
assertThat(strategies.decoders()).isEqualTo(handler.getDecoders());
assertThat(strategies.routeMatcher()).isSameAs(handler.getRouteMatcher());
assertThat(strategies.metadataExtractor()).isSameAs(handler.getMetadataExtractor());
assertThat(strategies.reactiveAdapterRegistry()).isSameAs(handler.getReactiveAdapterRegistry());
}
use of org.springframework.messaging.rsocket.RSocketStrategies in project spring-boot by spring-projects.
the class RSocketStrategiesAutoConfigurationTests method shouldCreateDefaultBeans.
@Test
void shouldCreateDefaultBeans() {
this.contextRunner.run((context) -> {
assertThat(context).getBeans(RSocketStrategies.class).hasSize(1);
RSocketStrategies strategies = context.getBean(RSocketStrategies.class);
assertThat(strategies.decoders()).hasAtLeastOneElementOfType(Jackson2CborDecoder.class).hasAtLeastOneElementOfType(Jackson2JsonDecoder.class);
assertThat(strategies.encoders()).hasAtLeastOneElementOfType(Jackson2CborEncoder.class).hasAtLeastOneElementOfType(Jackson2JsonEncoder.class);
assertThat(strategies.routeMatcher()).isInstanceOf(PathPatternRouteMatcher.class);
});
}
Aggregations