Path: blob/master/test/jdk/javax/management/remote/mandatory/version/ImplVersionTest.java
41159 views
/*1* Copyright (c) 2004, 2016, 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 504681526* @summary Test that RMIServer.getVersion() reflects the JDK version when27* the Java platform and the application is run with a security manager and the28* test codebase has the java permission to read the "java.runtime.version"29* system property.30* @author Luis-Miguel Alventosa, Joel Feraud31*32* @run clean ImplVersionTest ImplVersionCommand33* @run build ImplVersionTest ImplVersionCommand ImplVersionReader34* @run main ImplVersionTest35*/3637import java.io.File;3839public class ImplVersionTest {4041public static void main(String[] args) {42try {43// Get OS name44//45String osName = System.getProperty("os.name");46System.out.println("osName = " + osName);47if ("Windows 98".equals(osName)) {48// Disable this test on Win98 due to parsing49// errors (bad handling of white spaces) when50// J2SE is installed under "Program Files".51//52System.out.println("This test is disabled on Windows 98.");53System.out.println("Bye! Bye!");54return;55}5657// Get Java Home58String javaHome = System.getProperty("java.home");5960// Get test src61//62String testSrc = System.getProperty("test.src");6364// Get test classes65String testClasses = System.getProperty("test.classes");6667// Build command string68String command =69javaHome + File.separator + "bin" + File.separator + "java " +70" -classpath " + testClasses +71" -Djava.security.manager -Djava.security.policy==" + testSrc +72File.separator + "policy -Dtest.classes=" + testClasses +73" ImplVersionCommand " + System.getProperty("java.runtime.version");74System.out.println("ImplVersionCommand Exec Command = " + command);7576// Exec command77Process proc = Runtime.getRuntime().exec(command);78new ImplVersionReader(proc, proc.getInputStream()).start();79new ImplVersionReader(proc, proc.getErrorStream()).start();80int exitValue = proc.waitFor();8182System.out.println("ImplVersionCommand Exit Value = " +83exitValue);84if (exitValue != 0) {85System.out.println("TEST FAILED: Incorrect exit value " +86"from ImplVersionCommand");87System.exit(exitValue);88}89// Test OK!90System.out.println("Bye! Bye!");91} catch (Exception e) {92System.out.println("Unexpected exception caught = " + e);93e.printStackTrace();94System.exit(1);95}96}97}9899100