//package jdk.sun.management.jmxremote; /* * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import jdk.test.lib.process.ProcessTools; /** * @test * @bug 8187498 * @summary Unit test for -Xmanagement Flags for JMX agent * @library /test/lib * @run main XmanagementAgentTest */ public class XmanagementAgentTest { static final Map fragments = new HashMap<>(); static { fragments.put("config_file", System.getProperty("test.src") + "/bootstrap/management_ssltest06_ok.properties.in"); fragments.put("port", "2345"); fragments.put("local", "false"); fragments.put("host", "localhost"); fragments.put("rmiserver_port", "4456"); fragments.put("ssl", "true"); fragments.put("rmi_registry_ssl", "false"); // fragments.put("ssl_config_file", System.getProperty("test.src") + "/bootstrap/jmxremote_ssltest12_ok.ssl.in"); fragments.put("ssl_client_auth", "true"); fragments.put("authenticate", "false"); fragments.put("password_file", System.getProperty("test.src") + "/bootstrap/jmxremote_ssltest06_ok.password.in"); fragments.put("access_file", System.getProperty("test.src") + "/bootstrap/jmxremote_ssltest10_ok.access.in"); } public static void main(String[] args) throws Exception { List keys = new ArrayList<>(fragments.keySet()); Collections.shuffle(keys); StringBuilder stringBuffer = new StringBuilder(); stringBuffer.append("-Xmanagement:"); keys.forEach(k -> stringBuffer.append(k).append("=").append(fragments.get(k)).append(",")); String commandLine = stringBuffer.toString().replaceAll(",$", ""); List pbArgs = new ArrayList<>(); pbArgs.add(commandLine); pbArgs.add(XmgmtVerfifier.class.getName()); int exitValue = ProcessTools.executeTestJava(pbArgs.toArray(new String[0])) .outputTo(System.out) .errorTo(System.err) .getExitValue(); if (exitValue != 0) { throw new RuntimeException("Test Failed!!"); } } } class XmgmtVerfifier { private static final Map XMANAGEMENTFLAS = Collections.unmodifiableMap(new LinkedHashMap<>() { { put("config_file", "com.sun.management.config.file"); put("local", "com.sun.management.jmxremote"); put("port", "com.sun.management.jmxremote.port"); put("host", "com.sun.management.jmxremote.host"); put("rmiserver_port", "com.sun.management.jmxremote.rmi.port"); put("rmi_registry_ssl", "com.sun.management.jmxremote.registry.ssl"); put("ssl", "com.sun.management.jmxremote.ssl"); put("ssl_config_file", "com.sun.management.jmxremote.ssl.config.file"); put("ssl_client_auth", "com.sun.management.jmxremote.ssl.need.client.auth"); put("password_file", "com.sun.management.jmxremote.password.file"); put("authenticate", "com.sun.management.jmxremote.authenticate"); put("access_file", "com.sun.management.jmxremote.access.file"); } }); public static void main(String[] args) { XMANAGEMENTFLAS.values().forEach(a -> System.out.println(a + " -> " + System.getProperty(a))); } }