6 import javax.net.ssl.HttpsURLConnection; |
6 import javax.net.ssl.HttpsURLConnection; |
7 import javax.net.ssl.KeyManagerFactory; |
7 import javax.net.ssl.KeyManagerFactory; |
8 import javax.net.ssl.SSLContext; |
8 import javax.net.ssl.SSLContext; |
9 import javax.net.ssl.TrustManagerFactory; |
9 import javax.net.ssl.TrustManagerFactory; |
10 import java.io.*; |
10 import java.io.*; |
|
11 import java.lang.reflect.Method; |
11 import java.net.InetAddress; |
12 import java.net.InetAddress; |
12 import java.net.UnknownHostException; |
13 import java.net.UnknownHostException; |
13 import java.security.KeyStore; |
14 import java.security.KeyStore; |
14 import java.util.ArrayList; |
|
15 import java.util.List; |
|
16 import java.util.Properties; |
15 import java.util.Properties; |
17 |
16 import java.util.Set; |
|
17 import java.util.stream.Collectors; |
|
18 import java.util.stream.Stream; |
18 |
19 |
19 /* @test |
20 /* @test |
20 * @summary Configuration test for rest adapter |
21 * @summary Configuration test for rest adapter |
21 * @library /test/lib |
22 * @library /test/lib |
22 * @modules java.management.rest/com.oracle.jmx.remote.rest.http |
23 * @modules java.management.rest/com.oracle.jmx.remote.rest.http |
31 public class RestAdapterConfigTest { |
32 public class RestAdapterConfigTest { |
32 private static String sslAgentConfig; |
33 private static String sslAgentConfig; |
33 private static String sslClientConfig; |
34 private static String sslClientConfig; |
34 private static String passwordFile; |
35 private static String passwordFile; |
35 private static String configFile; |
36 private static String configFile; |
36 private static final List<Runnable> tasks = new ArrayList<>(); |
37 private static RestAdapterTest restAdapterTest = new RestAdapterTest(); |
37 private static RestAdapterTest test = new RestAdapterTest(); |
38 private static final Set<Method> tests; |
38 |
39 |
39 static { |
40 static { |
40 tasks.add(test::testAllMBeanServers); |
41 tests = Stream.of(RestAdapterTest.class.getMethods()) |
41 tasks.add(test::testAllMBeanInfo); |
42 .filter(a -> a.getName().startsWith("test")) |
42 tasks.add(test::testAllMBeans); |
43 .collect(Collectors.toSet()); |
43 tasks.add(test::testMBeanFiltering); |
|
44 tasks.add(test::testMBeanGetAttributes); |
|
45 tasks.add(test::testMBeanSetAttributes); |
|
46 tasks.add(test::testMbeanNoArgOperations); |
|
47 tasks.add(test::testAllMBeansBulkRequest); |
|
48 tasks.add(test::testThreadMXBeanBulkRequest); |
|
49 tasks.add(test::testThreadMXBeanThreadInfo); |
|
50 } |
44 } |
51 |
45 |
52 private void createAgentSslConfigFile(String fileName) throws IOException { |
46 private void createAgentSslConfigFile(String fileName) throws IOException { |
53 File f = new File(fileName); |
47 File f = new File(fileName); |
54 if (f.exists()) { |
48 if (f.exists()) { |
181 } |
175 } |
182 |
176 |
183 @Test |
177 @Test |
184 public void testHttpNoAuth() throws Exception { |
178 public void testHttpNoAuth() throws Exception { |
185 setupMgmtConfig(configFile, false, false); |
179 setupMgmtConfig(configFile, false, false); |
186 test.setupServers(); |
180 restAdapterTest.setupServers(); |
187 tasks.forEach(Runnable::run); |
181 for (Method m : tests) { |
188 test.tearDownServers(); |
182 m.invoke(restAdapterTest); |
|
183 } |
|
184 restAdapterTest.tearDownServers(); |
189 } |
185 } |
190 |
186 |
191 public void testHttpsNoAuth() throws Exception { |
187 public void testHttpsNoAuth() throws Exception { |
192 setupMgmtConfig(configFile, true, false); |
188 setupMgmtConfig(configFile, true, false); |
193 test.setupServers(); |
189 restAdapterTest.setupServers(); |
194 tasks.forEach(Runnable::run); |
190 for (Method m : tests) { |
195 test.tearDownServers(); |
191 m.invoke(restAdapterTest); |
|
192 } |
|
193 restAdapterTest.tearDownServers(); |
196 } |
194 } |
197 |
195 |
198 public void testHttpAuth() throws Exception { |
196 public void testHttpAuth() throws Exception { |
199 setupMgmtConfig(configFile, false, true); |
197 setupMgmtConfig(configFile, false, true); |
200 test.setupServers(); |
198 restAdapterTest.setupServers(); |
201 tasks.forEach(Runnable::run); |
199 for (Method m : tests) { |
202 test.tearDownServers(); |
200 m.invoke(restAdapterTest); |
|
201 } |
|
202 restAdapterTest.tearDownServers(); |
203 } |
203 } |
204 |
204 |
205 public void testHttpsAuth() throws Exception { |
205 public void testHttpsAuth() throws Exception { |
206 setupMgmtConfig(configFile, true, true); |
206 setupMgmtConfig(configFile, true, true); |
207 test.setupServers(); |
207 restAdapterTest.setupServers(); |
208 tasks.forEach(Runnable::run); |
208 for (Method m : tests) { |
209 test.tearDownServers(); |
209 m.invoke(restAdapterTest); |
|
210 } |
|
211 restAdapterTest.tearDownServers(); |
210 } |
212 } |
211 |
213 |
212 @AfterClass |
214 @AfterClass |
213 public void tearDown() { |
215 public void tearDown() { |
214 File f = new File(sslAgentConfig); |
216 File f = new File(sslAgentConfig); |