1 /* 2 * Copyright (c) 2018, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @summary jpackager create image missing arguments test 27 * @build JPackagerHelper 28 * @modules jdk.jpackager 29 * @run main/othervm -Xmx512m JPackagerCreateImageMissingArgumentsTest 30 */ 31 32 public class JPackagerCreateImageMissingArgumentsTest { 33 private static final String [] RESULT_1 = {"--output" }; 34 private static final String [] CMD_1 = { 35 "create-image", 36 "--input", "input", 37 "--name", "test", 38 "--main-jar", "hello.jar", 39 "--class", "Hello", 40 "--force", 41 "--files", "hello.jar"}; 42 43 private static final String [] RESULT_2 = {"--input"}; 44 private static final String [] CMD_2 = { 45 "create-image", 46 "--output", "output", 47 "--name", "test", 48 "--main-jar", "hello.jar", 49 "--class", "Hello", 50 "--force", 51 "--files", "hello.jar"}; 52 53 private static final String [] RESULT_3 = {"--input", "--app-image"}; 54 private static final String [] CMD_3 = { 55 "create-installer", 56 "--output", "output", 57 "--name", "test", 58 "--main-jar", "hello.jar", 59 "--class", "Hello", 60 "--force", 61 "--files", "hello.jar"}; 62 63 private static void validate(String output, String [] expected) 64 throws Exception { 65 String[] result = output.split("\n"); 66 if (result.length != 1) { 67 System.err.println(output); 68 throw new AssertionError("Invalid number of lines in output: " 69 + result.length); 70 } 71 72 for (String s : expected) { 73 if (!result[0].contains(s)) { 74 System.err.println("Expected to contain: " + s); 75 System.err.println("Actual: " + result[0]); 76 throw new AssertionError("Unexpected error message"); 77 } 78 } 79 } 80 81 private static void testMissingArg() throws Exception { 82 String output = JPackagerHelper.executeCLI(false, CMD_1); 83 validate(output, RESULT_1); 84 85 output = JPackagerHelper.executeCLI(false, CMD_2); 86 validate(output, RESULT_2); 87 88 output = JPackagerHelper.executeCLI(false, CMD_3); 89 validate(output, RESULT_3); 90 } 91 92 private static void testMissingArgToolProvider() throws Exception { 93 String output = JPackagerHelper.executeToolProvider(false, CMD_1); 94 validate(output, RESULT_1); 95 96 output = JPackagerHelper.executeToolProvider(false, CMD_2); 97 validate(output, RESULT_2); 98 99 output = JPackagerHelper.executeToolProvider(false, CMD_3); 100 validate(output, RESULT_3); 101 } 102 103 public static void main(String[] args) throws Exception { 104 JPackagerHelper.createHelloJar(); 105 testMissingArg(); 106 testMissingArgToolProvider(); 107 } 108 109 }