test/jdk/tools/jpackage/share/RuntimePackageTest.java
branchJDK-8200758-branch
changeset 58762 0fe62353385b
parent 58761 88e2753a2334
child 58994 b09ba68c6a19
--- a/test/jdk/tools/jpackage/share/RuntimePackageTest.java	Wed Oct 23 10:10:34 2019 -0400
+++ b/test/jdk/tools/jpackage/share/RuntimePackageTest.java	Wed Oct 23 10:37:54 2019 -0400
@@ -21,11 +21,15 @@
  * questions.
  */
 
+import java.io.IOException;
+import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.HashSet;
 import java.util.Optional;
-import jdk.jpackage.test.TKit;
-import jdk.jpackage.test.PackageTest;
-import jdk.jpackage.test.JPackageCommand;
+import java.util.Set;
+import java.util.stream.Collectors;
+import jdk.jpackage.test.*;
+import jdk.jpackage.test.Annotations.Test;
 
 /**
  * Test --runtime-image parameter.
@@ -49,23 +53,55 @@
  * @comment Temporary disable for Linux and OSX until functionality implemented
  * @requires (os.family != "mac")
  * @modules jdk.jpackage/jdk.jpackage.internal
- * @run main/othervm/timeout=720 -Xmx512m RuntimePackageTest
+ * @compile RuntimePackageTest.java
+ * @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main
+ *  --jpt-run=RuntimePackageTest
  */
 public class RuntimePackageTest {
 
-    public static void main(String[] args) {
-        TKit.run(args, () -> {
-            new PackageTest()
-            .addInitializer(cmd -> {
-                cmd.addArguments("--runtime-image", Optional.ofNullable(
-                        JPackageCommand.DEFAULT_RUNTIME_IMAGE).orElse(Path.of(
-                                System.getProperty("java.home"))));
-                // Remove --input parameter from jpackage command line as we don't
-                // create input directory in the test and jpackage fails
-                // if --input references non existant directory.
-                cmd.removeArgumentWithValue("--input");
-            })
-            .run();
+    @Test
+    public static void test() {
+        new PackageTest()
+        .addInitializer(cmd -> {
+            cmd.addArguments("--runtime-image", Optional.ofNullable(
+                    JPackageCommand.DEFAULT_RUNTIME_IMAGE).orElse(Path.of(
+                            System.getProperty("java.home"))));
+            // Remove --input parameter from jpackage command line as we don't
+            // create input directory in the test and jpackage fails
+            // if --input references non existant directory.
+            cmd.removeArgumentWithValue("--input");
+        })
+        .addInstallVerifier(cmd -> {
+            Set<Path> srcRuntime = listFiles(Path.of(cmd.getArgumentValue("--runtime-image")));
+            Set<Path> dstRuntime = listFiles(cmd.appRuntimeDirectory());
+
+            Set<Path> intersection = new HashSet<>(srcRuntime);
+            intersection.retainAll(dstRuntime);
+
+            srcRuntime.removeAll(intersection);
+            dstRuntime.removeAll(intersection);
+
+            assertFileListEmpty(srcRuntime, "Missing");
+            assertFileListEmpty(dstRuntime, "Unexpected");
+        })
+        .run();
+    }
+
+    private static Set<Path> listFiles(Path root) throws IOException {
+        try (var files = Files.walk(root)) {
+            return files.map(root::relativize).collect(Collectors.toSet());
+        }
+    }
+
+    private static void assertFileListEmpty(Set<Path> paths, String msg) {
+        TKit.assertTrue(paths.isEmpty(), String.format(
+                "Check there are no %s files in installed image",
+                msg.toLowerCase()), () -> {
+            String msg2 = String.format("%s %d files", msg, paths.size());
+            TKit.trace(msg2 + ":");
+            paths.stream().map(Path::toString).sorted().forEachOrdered(
+                    TKit::trace);
+            TKit.trace("Done");
         });
     }
 }