test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java
branchJDK-8200758-branch
changeset 58696 61c44899b4eb
parent 58648 3bf53ffa9ae7
child 58762 0fe62353385b
equal deleted inserted replaced
58695:64adf683bc7b 58696:61c44899b4eb
    31 import java.util.function.Consumer;
    31 import java.util.function.Consumer;
    32 import java.util.function.Supplier;
    32 import java.util.function.Supplier;
    33 import java.util.stream.Collectors;
    33 import java.util.stream.Collectors;
    34 import java.util.stream.Stream;
    34 import java.util.stream.Stream;
    35 import jdk.jpackage.test.Functional.ThrowingConsumer;
    35 import jdk.jpackage.test.Functional.ThrowingConsumer;
       
    36 import jdk.jpackage.internal.AppImageFile;
    36 import static jdk.jpackage.test.PackageType.*;
    37 import static jdk.jpackage.test.PackageType.*;
    37 
    38 
    38 /**
    39 /**
    39  * Instance of PackageTest is for configuring and running a single jpackage
    40  * Instance of PackageTest is for configuring and running a single jpackage
    40  * command to produce platform specific package bundle.
    41  * command to produce platform specific package bundle.
    81     public PackageTest setExpectedExitCode(int v) {
    82     public PackageTest setExpectedExitCode(int v) {
    82         expectedJPackageExitCode = v;
    83         expectedJPackageExitCode = v;
    83         return this;
    84         return this;
    84     }
    85     }
    85 
    86 
    86     private PackageTest addInitializer(ThrowingConsumer<JPackageCommand> v, String id) {
    87     private PackageTest addInitializer(ThrowingConsumer<JPackageCommand> v,
       
    88             String id) {
    87         if (id != null) {
    89         if (id != null) {
    88             if (namedInitializers.contains(id)) {
    90             if (namedInitializers.contains(id)) {
    89                 return this;
    91                 return this;
    90             }
    92             }
    91 
    93 
   147                 type -> handlers.get(type).addUninstallVerifier(
   149                 type -> handlers.get(type).addUninstallVerifier(
   148                         ThrowingConsumer.toConsumer(v)));
   150                         ThrowingConsumer.toConsumer(v)));
   149         return this;
   151         return this;
   150     }
   152     }
   151 
   153 
   152     static void withTestFileAssociationsFile(FileAssociations fa, ThrowingConsumer<Path> consumer) {
   154     static void withTestFileAssociationsFile(FileAssociations fa,
   153         final String testFileDefaultName = String.join(".", "test", fa.getSuffix());
   155             ThrowingConsumer<Path> consumer) {
       
   156         final String testFileDefaultName = String.join(".", "test",
       
   157                 fa.getSuffix());
   154         TKit.withTempFile(testFileDefaultName, fa.getSuffix(), testFile -> {
   158         TKit.withTempFile(testFileDefaultName, fa.getSuffix(), testFile -> {
   155             if (TKit.isLinux()) {
   159             if (TKit.isLinux()) {
   156                 LinuxHelper.initFileAssociationsTestFile(testFile);
   160                 LinuxHelper.initFileAssociationsTestFile(testFile);
   157             }
   161             }
   158             consumer.accept(testFile);
   162             consumer.accept(testFile);
   344 
   348 
   345                 if (PackageType.WINDOWS.contains(cmd.packageType())) {
   349                 if (PackageType.WINDOWS.contains(cmd.packageType())) {
   346                     new WindowsHelper.AppVerifier(cmd);
   350                     new WindowsHelper.AppVerifier(cmd);
   347                 }
   351                 }
   348             }
   352             }
       
   353 
       
   354             TKit.assertPathExists(cmd.appInstallationDirectory().resolve(
       
   355                     AppImageFile.FILENAME), false);
   349 
   356 
   350             installVerifiers.stream().forEach(v -> v.accept(cmd));
   357             installVerifiers.stream().forEach(v -> v.accept(cmd));
   351         }
   358         }
   352 
   359 
   353         private void verifyPackageUninstalled(JPackageCommand cmd) {
   360         private void verifyPackageUninstalled(JPackageCommand cmd) {
   411             bundleOutputDir = null;
   418             bundleOutputDir = null;
   412         } else {
   419         } else {
   413             bundleOutputDir = new File(val).getAbsoluteFile();
   420             bundleOutputDir = new File(val).getAbsoluteFile();
   414 
   421 
   415             if (!bundleOutputDir.isDirectory()) {
   422             if (!bundleOutputDir.isDirectory()) {
   416                 throw new IllegalArgumentException(String.format("Invalid value of %s sytem property: [%s]. Should be existing directory",
   423                 throw new IllegalArgumentException(String.format(
       
   424                         "Invalid value of %s sytem property: [%s]. Should be existing directory",
   417                         TKit.getConfigPropertyName(propertyName),
   425                         TKit.getConfigPropertyName(propertyName),
   418                         bundleOutputDir));
   426                         bundleOutputDir));
   419             }
   427             }
   420         }
   428         }
   421     }
   429     }
   423     static {
   431     static {
   424         final String propertyName = "action";
   432         final String propertyName = "action";
   425         String action = Optional.ofNullable(TKit.getConfigProperty(propertyName)).orElse(
   433         String action = Optional.ofNullable(TKit.getConfigProperty(propertyName)).orElse(
   426                 Action.CREATE.toString()).toLowerCase();
   434                 Action.CREATE.toString()).toLowerCase();
   427         DEFAULT_ACTION = Stream.of(Action.values()).filter(
   435         DEFAULT_ACTION = Stream.of(Action.values()).filter(
   428                 a -> a.toString().equals(action)).findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("Unrecognized value of %s property: [%s]",
   436                 a -> a.toString().equals(action)).findFirst().orElseThrow(
       
   437                         () -> new IllegalArgumentException(String.format(
       
   438                                 "Unrecognized value of %s property: [%s]",
   429                                 TKit.getConfigPropertyName(propertyName), action)));
   439                                 TKit.getConfigPropertyName(propertyName), action)));
   430     }
   440     }
   431 }
   441 }