1 /* 2 * Copyright (c) 2018, 2019, 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 jpackage create image missing arguments test 27 * @library helpers 28 * @build JPackageHelper 29 * @build JPackagePath 30 * @modules jdk.jpackage 31 * @run main/othervm -Xmx512m JPackageMissingArgumentsTest 32 */ 33 34 public class JPackageMissingArgumentsTest { 35 private static final String [] RESULT_1 = {"--output"}; 36 private static final String [] CMD_1 = { 37 "create-image", 38 "--input", "input", 39 "--name", "test", 40 "--main-jar", "hello.jar", 41 "--main-class", "Hello", 42 "--files", "hello.jar"}; 43 44 private static final String [] RESULT_2 = {"--input"}; 45 private static final String [] CMD_2 = { 46 "create-image", 47 "--output", "output", 48 "--name", "test", 49 "--main-jar", "hello.jar", 50 "--main-class", "Hello", 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 "--main-class", "Hello", 60 "--files", "hello.jar"}; 61 62 private static final String [] RESULT_4 = {"--main-class"}; 63 private static final String [] CMD_4 = { 64 "create-image", 65 "--input", "input", 66 "--output", "output", 67 "--name", "test", 68 "--main-jar", "hello.jar", 69 "--files", "hello.jar"}; 70 71 private static final String [] RESULT_5 = {"--main-jar"}; 72 private static final String [] CMD_5 = { 73 "create-image", 74 "--input", "input", 75 "--output", "output", 76 "--name", "test", 77 "--main-class", "Hello", 78 "--files", "hello.jar"}; 79 80 private static final String [] RESULT_6 = {"--module-path", "--runtime-image"}; 81 private static final String [] CMD_6 = { 82 "create-image", 83 "--output", "output", 84 "--name", "test", 85 "--module", "com.hello/com.hello.Hello", 86 "--files", "hello.jar"}; 87 88 private static final String [] RESULT_7 = {"--module-path", "--runtime-image", 89 "--app-image"}; 90 private static final String [] CMD_7 = { 91 "create-installer", 92 "--output", "output", 93 "--name", "test", 94 "--module", "com.hello/com.hello.Hello", 95 "--files", "hello.jar"}; 96 97 private static void validate(String output, String [] expected) 98 throws Exception { 99 String[] result = output.split("\n"); 100 if (result.length != 1) { 101 System.err.println(output); 102 throw new AssertionError("Invalid number of lines in output: " 103 + result.length); 104 } 105 106 for (String s : expected) { 107 if (!result[0].contains(s)) { 108 System.err.println("Expected to contain: " + s); 109 System.err.println("Actual: " + result[0]); 110 throw new AssertionError("Unexpected error message"); 111 } 112 } 113 } 114 115 private static void testMissingArg() throws Exception { 116 String output = JPackageHelper.executeCLI(false, CMD_1); 117 validate(output, RESULT_1); 118 119 output = JPackageHelper.executeCLI(false, CMD_2); 120 validate(output, RESULT_2); 121 122 output = JPackageHelper.executeCLI(false, CMD_3); 123 validate(output, RESULT_3); 124 125 output = JPackageHelper.executeCLI(false, CMD_4); 126 validate(output, RESULT_4); 127 128 output = JPackageHelper.executeCLI(false, CMD_5); 129 validate(output, RESULT_5); 130 131 output = JPackageHelper.executeCLI(false, CMD_6); 132 validate(output, RESULT_6); 133 134 output = JPackageHelper.executeCLI(false, CMD_7); 135 validate(output, RESULT_7); 136 } 137 138 private static void testMissingArgToolProvider() throws Exception { 139 String output = JPackageHelper.executeToolProvider(false, CMD_1); 140 validate(output, RESULT_1); 141 142 output = JPackageHelper.executeToolProvider(false, CMD_2); 143 validate(output, RESULT_2); 144 145 output = JPackageHelper.executeToolProvider(false, CMD_3); 146 validate(output, RESULT_3); 147 148 output = JPackageHelper.executeToolProvider(false, CMD_4); 149 validate(output, RESULT_4); 150 151 output = JPackageHelper.executeToolProvider(false, CMD_5); 152 validate(output, RESULT_5); 153 154 output = JPackageHelper.executeToolProvider(false, CMD_6); 155 validate(output, RESULT_6); 156 157 output = JPackageHelper.executeToolProvider(false, CMD_7); 158 validate(output, RESULT_7); 159 } 160 161 public static void main(String[] args) throws Exception { 162 JPackageHelper.createHelloImageJar(); 163 testMissingArg(); 164 testMissingArgToolProvider(); 165 } 166 167 }