Skip to content

Commit 27aa61b

Browse files
eddumelendezeleftherias
authored andcommitted
Use LocalRSocketServerPort annotation
1 parent 4f82be7 commit 27aa61b

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

samples/boot/hellorsocket/src/integration-test/java/sample/HelloRSocketApplicationITests.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,8 @@
1616
package sample;
1717

1818
import org.springframework.beans.factory.annotation.Autowired;
19-
import org.springframework.boot.rsocket.context.RSocketServerInitializedEvent;
19+
import org.springframework.boot.rsocket.context.LocalRSocketServerPort;
2020
import org.springframework.boot.test.context.SpringBootTest;
21-
import org.springframework.boot.test.context.TestConfiguration;
22-
import org.springframework.context.ApplicationListener;
2321
import org.springframework.messaging.rsocket.RSocketRequester;
2422
import org.springframework.security.rsocket.metadata.BasicAuthenticationEncoder;
2523
import org.springframework.security.rsocket.metadata.UsernamePasswordMetadata;
@@ -36,6 +34,7 @@
3634

3735
/**
3836
* @author Rob Winch
37+
* @author Eddú Meléndez
3938
* @since 5.0
4039
*/
4140
@RunWith(SpringRunner.class)
@@ -46,13 +45,16 @@ public class HelloRSocketApplicationITests {
4645
@Autowired
4746
RSocketRequester.Builder requester;
4847

48+
@LocalRSocketServerPort
49+
int port;
50+
4951
@Test
5052
public void messageWhenAuthenticatedThenSuccess() {
5153
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("user", "password");
5254
RSocketRequester requester = this.requester
5355
.rsocketStrategies(builder -> builder.encoder(new BasicAuthenticationEncoder()))
5456
.setupMetadata(credentials, BASIC_AUTHENTICATION_MIME_TYPE)
55-
.connectTcp("localhost", getPort())
57+
.connectTcp("localhost", this.port)
5658
.block();
5759

5860
String message = requester.route("message")
@@ -66,7 +68,7 @@ public void messageWhenAuthenticatedThenSuccess() {
6668
@Test
6769
public void messageWhenNotAuthenticatedThenError() {
6870
RSocketRequester requester = this.requester
69-
.connectTcp("localhost", getPort())
71+
.connectTcp("localhost", this.port)
7072
.block();
7173

7274
assertThatThrownBy(() -> requester.route("message")
@@ -76,23 +78,4 @@ public void messageWhenNotAuthenticatedThenError() {
7678
.isNotNull();
7779
}
7880

79-
// FIXME: Waiting for @LocalRSocketServerPort
80-
// https://github.com/spring-projects/spring-boot/pull/18287
81-
82-
@Autowired
83-
Config config;
84-
85-
private int getPort() {
86-
return this.config.port;
87-
}
88-
89-
@TestConfiguration
90-
static class Config implements ApplicationListener<RSocketServerInitializedEvent> {
91-
private int port;
92-
93-
@Override
94-
public void onApplicationEvent(RSocketServerInitializedEvent event) {
95-
this.port = event.getServer().address().getPort();
96-
}
97-
}
9881
}

0 commit comments

Comments
 (0)