1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 import static jdk.testlibrary.Asserts.assertNotEquals; 27 import static jdk.testlibrary.Asserts.assertTrue; 28 import static jdk.testlibrary.Asserts.assertFalse; 29 import jdk.testlibrary.OutputAnalyzer; 30 31 /** 32 * @test 33 * @summary The test sanity checks functionality of 'jinfo -h', 'jinfo -help', 34 * and verifies jinfo exits abnormally if started with invalid options. 35 * @library /lib/testlibrary 36 * @build jdk.testlibrary.* JInfoHelper 37 * @run main JInfoSanityTest 38 */ 39 public class JInfoSanityTest { 40 41 public static void main(String[] args) throws Exception { 42 test_h(); 43 test_help(); 44 testVersion(); 45 testUnknownHost(); 46 } 47 48 private static void test_h() throws Exception { 49 OutputAnalyzer output = JInfoHelper.jinfoNoPid("-h"); 50 output.shouldHaveExitValue(0); 51 assertFalse(output.getStderr().isEmpty(), "'jinfo -h' stderr should not be empty"); 52 assertTrue(output.getStdout().isEmpty(), "'jinfo -h' stdout should be empty"); 53 } 54 55 private static void test_help() throws Exception { 56 OutputAnalyzer output = JInfoHelper.jinfoNoPid("-help"); 57 output.shouldHaveExitValue(0); 58 assertFalse(output.getStderr().isEmpty(), "'jinfo -help' stderr should not be empty"); 59 assertTrue(output.getStdout().isEmpty(), "'jinfo -help' stdout should be empty"); 60 } 61 62 private static void testVersion() throws Exception { 63 OutputAnalyzer output = JInfoHelper.jinfoNoPid("-version"); 64 output.shouldHaveExitValue(1); 65 assertFalse(output.getStderr().isEmpty(), "'jinfo -version' stderr should not be empty"); 66 assertTrue(output.getStdout().isEmpty(), "'jinfo -version' stdout should be empty"); 67 } 68 69 private static void testUnknownHost() throws Exception { 70 String unknownHost = "Oja781nh2ev7vcvbajdg-Sda1-C"; 71 OutputAnalyzer output = JInfoHelper.jinfoNoPid("med@" + unknownHost); 72 assertNotEquals(output.getExitValue(), 0, "A non-zero exit code should be returned for invalid operation"); 73 output.shouldContain("UnknownHostException: " + unknownHost); 74 } 75 76 }