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