Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/tools/jps/TestJpsSanity.java
38841 views
/*1* Copyright (c) 2014, 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.testlibrary.Asserts;24import jdk.testlibrary.OutputAnalyzer;2526/*27* @test28* @summary This test verifies jps usage and checks that appropriate error message is shown29* when running jps with illegal arguments.30* @library /lib/testlibrary31* @build jdk.testlibrary.* JpsHelper32* @run driver TestJpsSanity33*/34public class TestJpsSanity {3536public static void main(String[] args) throws Throwable {37testJpsUsage();38testJpsVersion();39testJpsUnknownHost();40}4142private static void testJpsUsage() throws Exception {43OutputAnalyzer output = JpsHelper.jps("-?");44JpsHelper.verifyOutputAgainstFile(output);4546output = JpsHelper.jps("-help");47JpsHelper.verifyOutputAgainstFile(output);48}4950private static void testJpsVersion() throws Exception {51OutputAnalyzer output = JpsHelper.jps("-version");52Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");53Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");54output.shouldContain("illegal argument: -version");55}5657private static void testJpsUnknownHost() throws Exception {58String invalidHostName = "Oja781nh2ev7vcvbajdg-Sda1-C";59OutputAnalyzer output = JpsHelper.jps(invalidHostName);60Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0");61Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty");62output.shouldContain("Unknown host: " + invalidHostName);63}6465}666768