15
15
import org .junit .jupiter .api .BeforeAll ;
16
16
import org .junit .jupiter .api .Test ;
17
17
import org .junit .jupiter .api .io .TempDir ;
18
+ import org .junit .jupiter .params .ParameterizedTest ;
19
+ import org .junit .jupiter .params .provider .EnumSource ;
18
20
import org .slf4j .Logger ;
19
21
import org .slf4j .LoggerFactory ;
20
22
import org .testcontainers .containers .GenericContainer ;
@@ -44,6 +46,9 @@ public class JmxConnectionTest {
44
46
45
47
private static Network network ;
46
48
49
+ // temporary folder for files that are copied to container
50
+ @ TempDir private Path tempDir ;
51
+
47
52
@ BeforeAll
48
53
static void beforeAll () {
49
54
network = Network .newNetwork ();
@@ -63,32 +68,43 @@ void connectionError() {
63
68
}
64
69
}
65
70
66
- @ Test
67
- void connectNoAuth () {
71
+ @ ParameterizedTest
72
+ @ EnumSource
73
+ void connectNoAuth (JmxScraperContainer .ConfigSource configSource ) {
68
74
connectionTest (
69
- app -> app .withJmxPort (JMX_PORT ), scraper -> scraper .withRmiServiceUrl (APP_HOST , JMX_PORT ));
75
+ app -> app .withJmxPort (JMX_PORT ),
76
+ scraper -> scraper .withRmiServiceUrl (APP_HOST , JMX_PORT ).withConfigSource (configSource ));
70
77
}
71
78
72
- @ Test
73
- void userPassword () {
79
+ @ ParameterizedTest
80
+ @ EnumSource
81
+ void userPassword (JmxScraperContainer .ConfigSource configSource ) {
74
82
String login = "user" ;
75
83
String pwd = "t0p!Secret" ;
76
84
connectionTest (
77
85
app -> app .withJmxPort (JMX_PORT ).withUserAuth (login , pwd ),
78
- scraper -> scraper .withRmiServiceUrl (APP_HOST , JMX_PORT ).withUser (login ).withPassword (pwd ));
86
+ scraper ->
87
+ scraper
88
+ .withRmiServiceUrl (APP_HOST , JMX_PORT )
89
+ .withUser (login )
90
+ .withPassword (pwd )
91
+ .withConfigSource (configSource ));
79
92
}
80
93
81
- @ Test
82
- void serverSsl (@ TempDir Path tempDir ) {
83
- testServerSsl (tempDir , /* sslRmiRegistry= */ false );
94
+ @ ParameterizedTest
95
+ @ EnumSource
96
+ void serverSsl (JmxScraperContainer .ConfigSource configSource ) {
97
+ testServerSsl (/* sslRmiRegistry= */ false , configSource );
84
98
}
85
99
86
- @ Test
87
- void serverSslWithSslRmiRegistry (@ TempDir Path tempDir ) {
88
- testServerSsl (tempDir , /* sslRmiRegistry= */ true );
100
+ @ ParameterizedTest
101
+ @ EnumSource
102
+ void serverSslWithSslRmiRegistry (JmxScraperContainer .ConfigSource configSource ) {
103
+ testServerSsl (/* sslRmiRegistry= */ true , configSource );
89
104
}
90
105
91
- private static void testServerSsl (Path tempDir , boolean sslRmiRegistry ) {
106
+ private void testServerSsl (
107
+ boolean sslRmiRegistry , JmxScraperContainer .ConfigSource configSource ) {
92
108
// two keystores:
93
109
// server keystore with public/private key pair
94
110
// client trust store with certificate from server
@@ -110,11 +126,13 @@ private static void testServerSsl(Path tempDir, boolean sslRmiRegistry) {
110
126
scraper ->
111
127
(sslRmiRegistry ? scraper .withSslRmiRegistry () : scraper )
112
128
.withRmiServiceUrl (APP_HOST , JMX_PORT )
113
- .withTrustStore (clientTrustStore ));
129
+ .withTrustStore (clientTrustStore )
130
+ .withConfigSource (configSource ));
114
131
}
115
132
116
- @ Test
117
- void serverSslClientSsl (@ TempDir Path tempDir ) {
133
+ @ ParameterizedTest
134
+ @ EnumSource (value = JmxScraperContainer .ConfigSource .class )
135
+ void serverSslClientSsl (JmxScraperContainer .ConfigSource configSource ) {
118
136
// Note: this could have been made simpler by relying on the fact that keystore could be used
119
137
// as a trust store, but having clear split provides also some extra clarity
120
138
//
@@ -153,7 +171,8 @@ void serverSslClientSsl(@TempDir Path tempDir) {
153
171
scraper
154
172
.withRmiServiceUrl (APP_HOST , JMX_PORT )
155
173
.withKeyStore (clientKeyStore )
156
- .withTrustStore (clientTrustStore ));
174
+ .withTrustStore (clientTrustStore )
175
+ .withConfigSource (configSource ));
157
176
}
158
177
159
178
private static void connectionTest (
0 commit comments