Search in sources :

Example 1 with RSocketServer

use of org.springframework.boot.rsocket.server.RSocketServer in project spring-boot by spring-projects.

the class RSocketPortInfoApplicationContextInitializerTests method whenServerHasNoAddressThenInitializerDoesNotSetPortProperty.

@Test
void whenServerHasNoAddressThenInitializerDoesNotSetPortProperty() {
    try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class)) {
        context.getBean(RSocketPortInfoApplicationContextInitializer.class).initialize(context);
        RSocketServer server = mock(RSocketServer.class);
        context.publishEvent(new RSocketServerInitializedEvent(server));
        then(server).should().address();
        assertThat(context.getEnvironment().getProperty("local.rsocket.server.port")).isNull();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RSocketServer(org.springframework.boot.rsocket.server.RSocketServer) Test(org.junit.jupiter.api.Test)

Example 2 with RSocketServer

use of org.springframework.boot.rsocket.server.RSocketServer in project spring-boot by spring-projects.

the class RSocketPortInfoApplicationContextInitializerTests method whenServerHasAddressThenInitializerSetsPortProperty.

@Test
void whenServerHasAddressThenInitializerSetsPortProperty() {
    try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class)) {
        context.getBean(RSocketPortInfoApplicationContextInitializer.class).initialize(context);
        RSocketServer server = mock(RSocketServer.class);
        given(server.address()).willReturn(new InetSocketAddress(65535));
        context.publishEvent(new RSocketServerInitializedEvent(server));
        assertThat(context.getEnvironment().getProperty("local.rsocket.server.port")).isEqualTo("65535");
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RSocketServer(org.springframework.boot.rsocket.server.RSocketServer) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 RSocketServer (org.springframework.boot.rsocket.server.RSocketServer)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 InetSocketAddress (java.net.InetSocketAddress)1