Path: blob/master/test/jdk/java/lang/management/RuntimeMXBean/PropertiesTest.java
41154 views
/*1* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 626013126* @summary Test for RuntimeMXBean.getSystemProperties() if the system27* properties contain another list of properties as the defaults.28* @author Mandy Chung29*30* @run build PropertiesTest31* @run main PropertiesTest32*/3334import java.util.*;35import java.io.*;36import java.lang.management.ManagementFactory;37import java.lang.management.RuntimeMXBean;3839public class PropertiesTest {40private static int NUM_MYPROPS = 3;41public static void main(String[] argv) throws Exception {42// Save a copy of the original system properties43Properties props = System.getProperties();4445try {46// replace the system Properties object for any modification47// in case jtreg caches a copy48System.setProperties(new Properties(props));49runTest(props.size());50} finally {51// restore original system properties52System.setProperties(props);53}54}5556private static void runTest(int sysPropsCount) throws Exception {57// Create a new system properties using the old one58// as the defaults59Properties myProps = new Properties( System.getProperties() );6061// add several new properties62myProps.put("good.property.1", "good.value.1");63myProps.put("good.property.2", "good.value.2");64myProps.put("good.property.3", "good.value.3");65myProps.put("good.property.4", new Integer(4));66myProps.put(new Integer(5), "good.value.5");67myProps.put(new Object(), new Object());6869System.setProperties(myProps);7071Map<String,String> props =72ManagementFactory.getRuntimeMXBean().getSystemProperties();73int i=0;74for (Map.Entry<String,String> e : props.entrySet()) {75String key = e.getKey();76String value = e.getValue();77System.out.println(i++ + ": " + key + " : " + value);78}7980if (props.size() != NUM_MYPROPS + sysPropsCount) {81throw new RuntimeException("Test Failed: " +82"Expected number of properties = " +83NUM_MYPROPS + sysPropsCount +84" but found = " + props.size());85}86}87}888990