1 /* 2 * Copyright (c) 2018, 2020, 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 package jdk.jpackage.tests; 25 26 import java.util.Collection; 27 import java.util.List; 28 import jdk.jpackage.test.Annotations.Parameters; 29 import jdk.jpackage.test.Annotations.Test; 30 import jdk.jpackage.test.JPackageCommand; 31 import jdk.jpackage.test.HelloApp; 32 import jdk.jpackage.test.Executor; 33 import jdk.jpackage.test.TKit; 34 35 /* 36 * @test 37 * @summary jpackage create image with --java-options test 38 * @library ../../../../helpers 39 * @build jdk.jpackage.test.* 40 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal 41 * @compile JavaOptionsTest.java 42 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main 43 * --jpt-run=jdk.jpackage.tests.JavaOptionsTest 44 */ 45 46 public class JavaOptionsTest { 47 private static final String PARAM1 = "Some Param 1"; 48 private static final String PARAM2 = "Some \"Param\" 2"; 49 private static final String PARAM3 = "Some \"Param\" with \" 3"; 50 private static final String ARG1 = "-Dparam1=" + "\'" + PARAM1 + "\'"; 51 private static final String ARG2 = "-Dparam2=" + "\'" + PARAM2 + "\'"; 52 private static final String ARG3 = "-Dparam3=" + "\'" + PARAM3 + "\'"; 53 private static final String EXPECT1 = "-Dparam1=" + PARAM1; 54 private static final String EXPECT2 = "-Dparam2=" + PARAM2; 55 private static final String EXPECT3 = "-Dparam3=" + PARAM3; 56 57 58 private final JPackageCommand cmd; 59 private final String[] expected; 60 61 @Parameters 62 public static Collection input() { 63 return List.of(new Object[][]{ 64 {"Hello", 65 new String[]{"--java-options", ARG1}, 66 new String[]{EXPECT1}, 67 }, 68 {"Hello", 69 new String[]{"--java-options", ARG2}, 70 new String[]{EXPECT2}, 71 }, 72 {"Hello", 73 new String[]{"--java-options", ARG3}, 74 new String[]{EXPECT3}, 75 }, 76 {"Hello", 77 new String[]{"--java-options", ARG1, 78 "--java-options", ARG2, "--java-options", ARG3}, 79 new String[]{EXPECT1, EXPECT2, EXPECT3}, 80 }, 81 }); 82 } 83 84 public JavaOptionsTest(String javaAppDesc, String[] jpackageArgs, 85 String[] expectedParams) { 86 cmd = JPackageCommand.helloAppImage(javaAppDesc); 87 if (jpackageArgs != null) { 88 cmd.addArguments(jpackageArgs); 89 } 90 expected = expectedParams; 91 } 92 93 private void verifyResult(Executor.Result result) { 94 // launcher should not fail 95 result.assertExitCodeIs(0); 96 97 List<String> output = result.getOutput(); 98 99 for (String expect : expected) { 100 boolean found = false; 101 for (String s : output) { 102 found |= expect.equals(s); 103 } 104 TKit.assertTrue(found, 105 "Expected to find [" + expect + "] in output: " + output); 106 } 107 } 108 109 @Test 110 public void test() { 111 cmd.useToolProvider(true).executeAndAssertImageCreated(); 112 113 // we can't use executeLauncherAndVerifyOutput because when the vm-arg 114 // is -Dparam='foo bar' the value of the system property param is 115 // [foo bar] not ['foo bar'] as executeLauncherAndVerifyOutput expects 116 verifyResult(HelloApp.executeLauncher(cmd)); 117 } 118 119 }