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 app image error test 27 * @library ../helpers 28 * @build JPackageHelper 29 * @build JPackagePath 30 * @build JPackageCreateAppImageBase 31 * @modules jdk.jpackage 32 * @run main/othervm -Xmx512m JPackageCreateAppImageErrorTest 33 */ 34 import java.util.*; 35 import java.io.*; 36 import java.nio.*; 37 import java.nio.file.*; 38 import java.nio.file.attribute.*; 39 40 public class JPackageCreateAppImageErrorTest { 41 42 private static final String OUTPUT = "output"; 43 44 private static final String ARG1 = "--no-such-argument"; 45 private static final String EXPECTED1 = 46 "Invalid Option: [--no-such-argument]"; 47 private static final String ARG2 = "--output"; 48 private static final String EXPECTED2 = "Mode is not specified"; 49 50 private static final String [] CMD1 = { 51 "create-app-image", 52 "--input", "input", 53 "--output", OUTPUT, 54 "--name", "test", 55 "--main-jar", "non-existant.jar", 56 }; 57 private static final String EXP1 = "main jar does not exist"; 58 59 private static final String [] CMD2 = { 60 "create-app-image", 61 "--input", "input", 62 "--output", OUTPUT, 63 "--name", "test", 64 "--main-jar", "hello.jar", 65 }; 66 private static final String EXP2 = "class was not specified nor was"; 67 68 private static void validate(String output, String expected, boolean single) 69 throws Exception { 70 String[] result = output.split("\n"); 71 if (single && result.length != 1) { 72 System.err.println(output); 73 throw new AssertionError("Unexpected multiple lines of output: " 74 + output); 75 } 76 77 if (!result[0].trim().contains(expected)) { 78 throw new AssertionError("Unexpected output: " + result[0] 79 + " - expected output to contain: " + expected); 80 } 81 } 82 83 84 public static void main(String[] args) throws Exception { 85 JPackageHelper.createHelloImageJar(); 86 87 validate(JPackageHelper.executeToolProvider(false, ARG1), EXPECTED1, true); 88 validate(JPackageHelper.executeToolProvider(false, ARG2), EXPECTED2, true); 89 90 JPackageHelper.deleteOutputFolder(OUTPUT); 91 validate(JPackageHelper.executeToolProvider(false, CMD1), EXP1, false); 92 93 JPackageHelper.deleteOutputFolder(OUTPUT); 94 validate(JPackageHelper.executeToolProvider(false, CMD2), EXP2, false); 95 96 } 97 98 }