test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java
branchJDK-8200758-branch
changeset 58671 3b578a5976df
parent 58648 3bf53ffa9ae7
child 58762 0fe62353385b
equal deleted inserted replaced
58670:6fb9e12d5595 58671:3b578a5976df
    32 import java.util.function.Predicate;
    32 import java.util.function.Predicate;
    33 import java.util.regex.Pattern;
    33 import java.util.regex.Pattern;
    34 import java.util.stream.Collectors;
    34 import java.util.stream.Collectors;
    35 import java.util.stream.Stream;
    35 import java.util.stream.Stream;
    36 import jdk.jpackage.test.*;
    36 import jdk.jpackage.test.*;
       
    37 import jdk.jpackage.test.Functional.ThrowingConsumer;
    37 import jdk.jpackage.test.Annotations.*;
    38 import jdk.jpackage.test.Annotations.*;
    38 
    39 
    39 /*
    40 /*
    40  * @test
    41  * @test
    41  * @summary jpackage basic testing
    42  * @summary jpackage basic testing
   216      * directory is used only on Windows. Test it in packaging mode.
   217      * directory is used only on Windows. Test it in packaging mode.
   217      * @throws IOException
   218      * @throws IOException
   218      */
   219      */
   219     @Test
   220     @Test
   220     public void testTemp() throws IOException {
   221     public void testTemp() throws IOException {
   221         JPackageCommand cmd = JPackageCommand.helloAppImage()
   222         TKit.withTempDirectory("temp-root", tempRoot -> {
   222                 .removeArgumentWithValue("--package-type")
   223             Function<JPackageCommand, Path> getTempDir = cmd -> {
   223                 .addArguments("--verbose")
   224                 return tempRoot.resolve(cmd.outputBundle().getFileName());
   224                 .setFakeRuntime();
   225             };
   225 
   226 
   226         TKit.withTempDirectory("temp-root", tempDir -> {
   227             ThrowingConsumer<JPackageCommand> addTempDir = cmd -> {
   227             cmd.addArguments("--temp", tempDir);
   228                 Path tempDir = getTempDir.apply(cmd);
   228 
   229                 Files.createDirectories(tempDir);
   229             cmd.execute().assertExitCodeIsZero();
   230                 cmd.addArguments("--temp", tempDir);
   230 
   231             };
   231             // Check jpackage actually used the supplied directory.
   232 
   232             TKit.assertNotEquals(0, tempDir.toFile().list().length,
   233             new PackageTest().configureHelloApp().addInitializer(addTempDir)
   233                     String.format(
   234             .addBundleVerifier(cmd -> {
   234                             "Check jpackage wrote some data in the supplied temporary directory [%s]",
   235                 // Check jpackage actually used the supplied directory.
   235                             tempDir));
   236                 Path tempDir = getTempDir.apply(cmd);
   236 
   237                 TKit.assertNotEquals(0, tempDir.toFile().list().length,
       
   238                         String.format(
       
   239                                 "Check jpackage wrote some data in the supplied temporary directory [%s]",
       
   240                                 tempDir));
       
   241             })
       
   242             .run();
       
   243 
       
   244             new PackageTest().configureHelloApp().addInitializer(addTempDir)
       
   245             .addInitializer(cmd -> {
       
   246                 // Clean output from the previus jpackage run.
       
   247                 Files.delete(cmd.outputBundle());
       
   248             })
   237             // Temporary directory should not be empty,
   249             // Temporary directory should not be empty,
   238             // jpackage should exit with error.
   250             // jpackage should exit with error.
   239             cmd.execute().assertExitCodeIs(1);
   251             .setExpectedExitCode(1)
       
   252             .run();
   240         });
   253         });
   241     }
   254     }
   242 
   255 
   243     @Test
   256     @Test
   244     public void testAtFile() throws IOException {
   257     public void testAtFile() throws IOException {