1 //package jdk.sun.management.jmxremote;
   2 
   3 /*
   4  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 import java.util.ArrayList;
  27 import java.util.Collections;
  28 import java.util.HashMap;
  29 import java.util.LinkedHashMap;
  30 import java.util.List;
  31 import java.util.Map;
  32 
  33 import jdk.test.lib.process.ProcessTools;
  34 
  35 /**
  36  * @test 
  37  * @bug 8187498
  38  * @summary Unit test for -Xmanagement Flags for JMX agent
  39  * @library /test/lib
  40  * @run main XmanagementAgentTest
  41  */
  42 public class XmanagementAgentTest {
  43 
  44     static final Map<String, String> fragments = new HashMap<>();
  45 
  46     static {
  47         fragments.put("config_file", System.getProperty("test.src") + "/bootstrap/management_ssltest06_ok.properties.in");
  48         fragments.put("port", "2345");
  49         fragments.put("local", "false");
  50         fragments.put("host", "localhost");
  51         fragments.put("rmiserver_port", "4456");
  52         fragments.put("ssl", "true");
  53         fragments.put("rmi_registry_ssl", "false");
  54 //        fragments.put("ssl_config_file", System.getProperty("test.src") + "/bootstrap/jmxremote_ssltest12_ok.ssl.in");
  55         fragments.put("ssl_client_auth", "true");
  56         fragments.put("authenticate", "false");
  57         fragments.put("password_file", System.getProperty("test.src") + "/bootstrap/jmxremote_ssltest06_ok.password.in");
  58         fragments.put("access_file", System.getProperty("test.src") + "/bootstrap/jmxremote_ssltest10_ok.access.in");
  59     }
  60 
  61     public static void main(String[] args) throws Exception {
  62         List<String> keys = new ArrayList<>(fragments.keySet());
  63         Collections.shuffle(keys);
  64         StringBuilder stringBuffer = new StringBuilder();
  65         stringBuffer.append("-Xmanagement:");
  66 
  67         keys.forEach(k -> stringBuffer.append(k).append("=").append(fragments.get(k)).append(","));
  68         String commandLine = stringBuffer.toString().replaceAll(",$", "");
  69 
  70         List<String> pbArgs = new ArrayList<>();
  71         pbArgs.add(commandLine);
  72         pbArgs.add(XmgmtVerfifier.class.getName());
  73 
  74         int exitValue = ProcessTools.executeTestJava(pbArgs.toArray(new String[0]))
  75                 .outputTo(System.out)
  76                 .errorTo(System.err)
  77                 .getExitValue();
  78         if (exitValue != 0) {
  79             throw new RuntimeException("Test Failed!!");
  80         }
  81     }
  82 }
  83 
  84 class XmgmtVerfifier {
  85 
  86     private static final Map<String, String> XMANAGEMENTFLAS = Collections.unmodifiableMap(new LinkedHashMap<>() {
  87         {
  88             put("config_file", "com.sun.management.config.file");
  89             put("local", "com.sun.management.jmxremote");
  90             put("port", "com.sun.management.jmxremote.port");
  91             put("host", "com.sun.management.jmxremote.host");
  92             put("rmiserver_port", "com.sun.management.jmxremote.rmi.port");
  93             put("rmi_registry_ssl", "com.sun.management.jmxremote.registry.ssl");
  94             put("ssl", "com.sun.management.jmxremote.ssl");
  95             put("ssl_config_file", "com.sun.management.jmxremote.ssl.config.file");
  96             put("ssl_client_auth", "com.sun.management.jmxremote.ssl.need.client.auth");
  97             put("password_file", "com.sun.management.jmxremote.password.file");
  98             put("authenticate", "com.sun.management.jmxremote.authenticate");
  99             put("access_file", "com.sun.management.jmxremote.access.file");
 100         }
 101     });
 102 
 103     public static void main(String[] args) {
 104         XMANAGEMENTFLAS.values().forEach(a -> System.out.println(a + " -> " + System.getProperty(a)));
 105     }
 106 }
 107