< prev index next >

test/jdk/tools/jimage/JImageExtractTest.java

Print this page

        

@@ -24,14 +24,15 @@
 /*
  * @test
  * @summary Tests to verify jimage 'extract' action
  * @library /test/lib
  * @modules jdk.jlink/jdk.tools.jimage
- * @build jdk.test.lib.Asserts
+ * @build jdk.test.lib.Asserts JImageCliTest
  * @run main/othervm JImageExtractTest
  */
 
+import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.attribute.FileAttribute;

@@ -44,19 +45,41 @@
 
 import static jdk.test.lib.Asserts.assertEquals;
 import static jdk.test.lib.Asserts.assertTrue;
 
 public class JImageExtractTest extends JImageCliTest {
+    public void beforeTest() throws IOException {
+        Path cwd = new File(".").toPath();
+        System.out.printf("cleaning working dir [%s]... \n", cwd.toAbsolutePath());
+        for (File f : new File(".").listFiles()) {
+            if (f.isDirectory()) {
+                jdk.test.lib.util.FileUtils.deleteFileTreeWithRetry(f.toPath());
+            } else {
+                f.delete();
+            }
+        }
+    }
+
     public void testExtract() throws IOException {
         jimage("extract", getImagePath())
                 .assertSuccess()
                 .resultChecker(r -> {
                     assertTrue(r.output.isEmpty(), "Output is not expected");
                 });
         verifyExplodedImage(Paths.get("."));
     }
 
+    // do a second round to check that workspace initialization works ok
+    public void testExtractSecondRound() throws IOException {
+        jimage("extract", getImagePath())
+                .assertSuccess()
+                .resultChecker(r -> {
+                    assertTrue(r.output.isEmpty(), "Output is not expected");
+                });
+        verifyExplodedImage(Paths.get("."));
+    }
+
     public void testExtractHelp() {
         for (String opt : Arrays.asList("-h", "--help")) {
             jimage("extract", "--help")
                     .assertSuccess()
                     .resultChecker(r -> {

@@ -80,13 +103,21 @@
         jimage("extract", "")
                 .assertFailure()
                 .assertShowsError();
     }
 
+    public void testExtractEmptyFile() throws IOException {
+        Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "empty_file");
+        jimage("extract", "--dir", "some_directory", tmp.toString())
+                .assertFailure()
+                .assertShowsError();
+    }
+
     public void testExtractNotAnImage() throws IOException {
         Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "not_an_image");
-        jimage("extract", tmp.toString())
+        Files.write(tmp, "This is not an image".getBytes());
+        jimage("extract", "--dir", "some_directory", tmp.toString())
                 .assertFailure()
                 .assertShowsError();
     }
 
     public void testExtractNotExistingImage() throws IOException {
< prev index next >