test/jdk/tools/jpackage/windows/WinResourceTest.java
branchJDK-8200758-branch
changeset 58763 bc43733cd5cf
child 58922 fbaf2e6402ad
equal deleted inserted replaced
58762:0fe62353385b 58763:bc43733cd5cf
       
     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 import java.io.IOException;
       
    25 import java.nio.file.Path;
       
    26 import jdk.jpackage.test.TKit;
       
    27 import jdk.jpackage.test.PackageTest;
       
    28 import jdk.jpackage.test.PackageType;
       
    29 import jdk.jpackage.test.Annotations.Test;
       
    30 import java.util.List;
       
    31 
       
    32 /**
       
    33  * Test --resource-dir option. The test should set --resource-dir to point to
       
    34  * a dir with an empty "main.wxs" file.  As a result, jpackage should try to
       
    35  * use the customized resource and fail.
       
    36  */
       
    37 
       
    38 /*
       
    39  * @test
       
    40  * @summary jpackage with --resource-dir
       
    41  * @library ../helpers
       
    42  * @build jdk.jpackage.test.*
       
    43  * @requires (os.family == "windows")
       
    44  * @modules jdk.jpackage/jdk.jpackage.internal
       
    45  * @compile WinResourceTest.java
       
    46  * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
       
    47  *  --jpt-run=WinResourceTest
       
    48  */
       
    49 
       
    50 public class WinResourceTest {
       
    51     @Test
       
    52     public static void test() throws IOException {
       
    53         new PackageTest()
       
    54         .forTypes(PackageType.WINDOWS)
       
    55         .configureHelloApp()
       
    56         .addInitializer(cmd -> {
       
    57             Path resourceDir = TKit.createTempDirectory("resources");
       
    58 
       
    59             // 1. Set fake run time to save time by skipping jlink step of jpackage.
       
    60             // 2. Instruct test to save jpackage output.
       
    61             cmd.setFakeRuntime().saveConsoleOutput(true);
       
    62 
       
    63             cmd.addArguments("--resource-dir", resourceDir);
       
    64             // Create invalid main wxs file in a resource dir.
       
    65             TKit.createTextFile(resourceDir.resolve("main.wxs"), List.of(
       
    66                     "any string that is an invalid wxs file"));
       
    67         })
       
    68         .addBundleVerifier((cmd, result) -> {
       
    69             // Assert jpackage picked custom main.wxs and failed as expected by
       
    70             // examining its output
       
    71             TKit.assertTextStream("Using custom package resource [Main wxs project file]")
       
    72                     .predicate(String::startsWith)
       
    73                     .apply(result.getOutput().stream());
       
    74             TKit.assertTextStream("error CNDL0104 : Not a valid source file")
       
    75                     .apply(result.getOutput().stream());
       
    76         })
       
    77         .setExpectedExitCode(1)
       
    78         .run();
       
    79     }
       
    80 }