1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
package sample ;
17
17
18
18
import org .springframework .beans .factory .annotation .Autowired ;
19
- import org .springframework .boot .rsocket .context .RSocketServerInitializedEvent ;
19
+ import org .springframework .boot .rsocket .context .LocalRSocketServerPort ;
20
20
import org .springframework .boot .test .context .SpringBootTest ;
21
- import org .springframework .boot .test .context .TestConfiguration ;
22
- import org .springframework .context .ApplicationListener ;
23
21
import org .springframework .messaging .rsocket .RSocketRequester ;
24
22
import org .springframework .security .rsocket .metadata .BasicAuthenticationEncoder ;
25
23
import org .springframework .security .rsocket .metadata .UsernamePasswordMetadata ;
36
34
37
35
/**
38
36
* @author Rob Winch
37
+ * @author Eddú Meléndez
39
38
* @since 5.0
40
39
*/
41
40
@ RunWith (SpringRunner .class )
@@ -46,13 +45,16 @@ public class HelloRSocketApplicationITests {
46
45
@ Autowired
47
46
RSocketRequester .Builder requester ;
48
47
48
+ @ LocalRSocketServerPort
49
+ int port ;
50
+
49
51
@ Test
50
52
public void messageWhenAuthenticatedThenSuccess () {
51
53
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata ("user" , "password" );
52
54
RSocketRequester requester = this .requester
53
55
.rsocketStrategies (builder -> builder .encoder (new BasicAuthenticationEncoder ()))
54
56
.setupMetadata (credentials , BASIC_AUTHENTICATION_MIME_TYPE )
55
- .connectTcp ("localhost" , getPort () )
57
+ .connectTcp ("localhost" , this . port )
56
58
.block ();
57
59
58
60
String message = requester .route ("message" )
@@ -66,7 +68,7 @@ public void messageWhenAuthenticatedThenSuccess() {
66
68
@ Test
67
69
public void messageWhenNotAuthenticatedThenError () {
68
70
RSocketRequester requester = this .requester
69
- .connectTcp ("localhost" , getPort () )
71
+ .connectTcp ("localhost" , this . port )
70
72
.block ();
71
73
72
74
assertThatThrownBy (() -> requester .route ("message" )
@@ -76,23 +78,4 @@ public void messageWhenNotAuthenticatedThenError() {
76
78
.isNotNull ();
77
79
}
78
80
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
- }
98
81
}
0 commit comments