Path: blob/master/test/jdk/sun/tools/jps/TestJpsSanity.java
41149 views
/*1* Copyright (c) 2014, 2018, 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*/2223import jdk.test.lib.Asserts;24import jdk.test.lib.process.OutputAnalyzer;25import jdk.test.lib.apps.LingeredApp;2627/*28* @test29* @summary This test verifies jps usage and checks that appropriate error message is shown30* when running jps with illegal arguments.31* @library /test/lib32* @modules jdk.jartool/sun.tools.jar33* java.management34* java.base/jdk.internal.misc35* @build jdk.test.lib.apps.* JpsHelper36* @run driver TestJpsSanity37*/38public class TestJpsSanity {3940public static void main(String[] args) throws Throwable {41testJpsUsage();42testJpsVersion();43testJpsUnknownHost();44testJpsShort();45testJpsLong();46testJpsShortPkg();47testJpsLongPkg();48}4950private static void testJpsShort() throws Exception {51OutputAnalyzer output = JpsHelper.jps();52output.shouldMatch("^[0-9]+ Jps$");53}5455private static void testJpsLong() throws Exception {56OutputAnalyzer output = JpsHelper.jps("-l");57output.shouldMatch("^[0-9]+ jdk\\.jcmd/sun\\.tools\\.jps\\.Jps$");58}5960private static void testJpsShortPkg() throws Exception {61LingeredApp app = null;62try {63app = LingeredApp.startApp();64OutputAnalyzer output = JpsHelper.jps();65output.shouldMatch("^[0-9]+ LingeredApp$");66} finally {67LingeredApp.stopApp(app);68}69}7071private static void testJpsLongPkg() throws Exception {72LingeredApp app = null;73try {74app = LingeredApp.startApp();75OutputAnalyzer output = JpsHelper.jps("-l");76output.shouldMatch("^[0-9]+ jdk\\.test\\.lib\\.apps\\.LingeredApp$");77} finally {78LingeredApp.stopApp(app);79}80}8182private static void testJpsUsage() throws Exception {83OutputAnalyzer output = JpsHelper.jps("-?");84JpsHelper.verifyOutputAgainstFile(output);8586output = JpsHelper.jps("-h");87JpsHelper.verifyOutputAgainstFile(output);8889output = JpsHelper.jps("--help");90JpsHelper.verifyOutputAgainstFile(output);91}9293private static void testJpsVersion() throws Exception {94OutputAnalyzer output = JpsHelper.jps("-version");95Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");96Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");97output.shouldContain("illegal argument: -version");98}99100private static void testJpsUnknownHost() throws Exception {101String invalidHostName = "Oja781nh2ev7vcvbajdg-Sda1-C.invalid";102OutputAnalyzer output = JpsHelper.jps(invalidHostName);103Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");104Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");105output.shouldMatch(".*(RMI Registry not available at|Unknown host\\:) " + invalidHostName + ".*");106}107108}109110111