Path: blob/master/test/jdk/tools/jpackage/windows/WinResourceTest.java
41149 views
/*1* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.IOException;24import java.nio.file.Path;25import jdk.jpackage.test.TKit;26import jdk.jpackage.test.PackageTest;27import jdk.jpackage.test.PackageType;28import jdk.jpackage.test.JPackageCommand;29import jdk.jpackage.test.Annotations.Test;30import jdk.jpackage.test.Annotations.Parameters;31import java.util.List;3233/**34* Test --resource-dir option. The test should set --resource-dir to point to35* a dir with an empty "main.wxs" file. As a result, jpackage should try to36* use the customized resource and fail.37*/3839/*40* @test41* @summary jpackage with --resource-dir42* @library ../helpers43* @build jdk.jpackage.test.*44* @requires (os.family == "windows")45* @modules jdk.jpackage/jdk.jpackage.internal46* @compile WinResourceTest.java47* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main48* --jpt-run=WinResourceTest49*/5051public class WinResourceTest {5253public WinResourceTest(String wixSource, String expectedLogMessage) {54this.wixSource = wixSource;55this.expectedLogMessage = expectedLogMessage;56}5758@Parameters59public static List<Object[]> data() {60return List.of(new Object[][]{61{"main.wxs", "Using custom package resource [Main WiX project file]"},62{"overrides.wxi", "Using custom package resource [Overrides WiX project file]"},63});64}6566@Test67public void test() throws IOException {68new PackageTest()69.forTypes(PackageType.WINDOWS)70.configureHelloApp()71.addInitializer(cmd -> {72Path resourceDir = TKit.createTempDirectory("resources");7374// 1. Set fake run time to save time by skipping jlink step of jpackage.75// 2. Instruct test to save jpackage output.76cmd.setFakeRuntime().saveConsoleOutput(true);7778cmd.addArguments("--resource-dir", resourceDir);79// Create invalid WiX source file in a resource dir.80TKit.createTextFile(resourceDir.resolve(wixSource), List.of(81"any string that is an invalid WiX source file"));82})83.addBundleVerifier((cmd, result) -> {84// Assert jpackage picked custom main.wxs and failed as expected by85// examining its output86TKit.assertTextStream(expectedLogMessage)87.predicate(String::startsWith)88.apply(JPackageCommand.stripTimestamps(89result.getOutput().stream()));90TKit.assertTextStream("error CNDL0104 : Not a valid source file")91.apply(result.getOutput().stream());92})93.setExpectedExitCode(1)94.run();95}9697final String wixSource;98final String expectedLogMessage;99}100101102