< prev index next >

test/jdk/tools/jimage/JImageExtractTest.java

Print this page




   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 /*
  25  * @test
  26  * @summary Tests to verify jimage 'extract' action
  27  * @library /test/lib
  28  * @modules jdk.jlink/jdk.tools.jimage
  29  * @build jdk.test.lib.Asserts
  30  * @run main/othervm JImageExtractTest
  31  */
  32 

  33 import java.io.IOException;
  34 import java.nio.file.Files;
  35 import java.nio.file.Path;
  36 import java.nio.file.Paths;
  37 import java.nio.file.attribute.FileAttribute;
  38 import java.nio.file.attribute.PosixFilePermission;
  39 import java.nio.file.attribute.PosixFilePermissions;
  40 import java.util.Arrays;
  41 import java.util.HashSet;
  42 import java.util.Set;
  43 import java.util.stream.Collectors;
  44 
  45 import static jdk.test.lib.Asserts.assertEquals;
  46 import static jdk.test.lib.Asserts.assertTrue;
  47 
  48 public class JImageExtractTest extends JImageCliTest {












  49     public void testExtract() throws IOException {
  50         jimage("extract", getImagePath())
  51                 .assertSuccess()
  52                 .resultChecker(r -> {
  53                     assertTrue(r.output.isEmpty(), "Output is not expected");
  54                 });
  55         verifyExplodedImage(Paths.get("."));
  56     }
  57 










  58     public void testExtractHelp() {
  59         for (String opt : Arrays.asList("-h", "--help")) {
  60             jimage("extract", "--help")
  61                     .assertSuccess()
  62                     .resultChecker(r -> {
  63                         // extract  -  descriptive text
  64                         assertMatches("\\s+extract\\s+-\\s+.*", r.output);
  65                     });
  66         }
  67     }
  68 
  69     public void testExtractToDir() throws IOException {
  70         Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());
  71         jimage("extract", "--dir", tmp.toString(), getImagePath())
  72                 .assertSuccess()
  73                 .resultChecker(r -> {
  74                     assertTrue(r.output.isEmpty(), "Output is not expected");
  75                 });
  76         verifyExplodedImage(tmp);
  77     }
  78 
  79     public void testExtractNoImageSpecified() {
  80         jimage("extract", "")
  81                 .assertFailure()
  82                 .assertShowsError();
  83     }
  84 







  85     public void testExtractNotAnImage() throws IOException {
  86         Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "not_an_image");
  87         jimage("extract", tmp.toString())

  88                 .assertFailure()
  89                 .assertShowsError();
  90     }
  91 
  92     public void testExtractNotExistingImage() throws IOException {
  93         Path tmp = Paths.get(".", "not_existing_image");
  94         Files.deleteIfExists(tmp);
  95         jimage("extract", tmp.toString())
  96                 .assertFailure()
  97                 .assertShowsError();
  98     }
  99 
 100     public void testExtractToUnspecifiedDir() {
 101         jimage("extract", "--dir", "--", getImagePath())
 102                 .assertFailure()
 103                 .assertShowsError();
 104     }
 105 
 106     public void testExtractToNotExistingDir() throws IOException {
 107         Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());




   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 /*
  25  * @test
  26  * @summary Tests to verify jimage 'extract' action
  27  * @library /test/lib
  28  * @modules jdk.jlink/jdk.tools.jimage
  29  * @build jdk.test.lib.Asserts JImageCliTest
  30  * @run main/othervm JImageExtractTest
  31  */
  32 
  33 import java.io.File;
  34 import java.io.IOException;
  35 import java.nio.file.Files;
  36 import java.nio.file.Path;
  37 import java.nio.file.Paths;
  38 import java.nio.file.attribute.FileAttribute;
  39 import java.nio.file.attribute.PosixFilePermission;
  40 import java.nio.file.attribute.PosixFilePermissions;
  41 import java.util.Arrays;
  42 import java.util.HashSet;
  43 import java.util.Set;
  44 import java.util.stream.Collectors;
  45 
  46 import static jdk.test.lib.Asserts.assertEquals;
  47 import static jdk.test.lib.Asserts.assertTrue;
  48 
  49 public class JImageExtractTest extends JImageCliTest {
  50     public void beforeTest() throws IOException {
  51         Path cwd = new File(".").toPath();
  52         System.out.printf("cleaning working dir [%s]... \n", cwd.toAbsolutePath());
  53         for (File f : new File(".").listFiles()) {
  54             if (f.isDirectory()) {
  55                 jdk.test.lib.util.FileUtils.deleteFileTreeWithRetry(f.toPath());
  56             } else {
  57                 f.delete();
  58             }
  59         }
  60     }
  61 
  62     public void testExtract() throws IOException {
  63         jimage("extract", getImagePath())
  64                 .assertSuccess()
  65                 .resultChecker(r -> {
  66                     assertTrue(r.output.isEmpty(), "Output is not expected");
  67                 });
  68         verifyExplodedImage(Paths.get("."));
  69     }
  70 
  71     // do a second round to check that workspace initialization works ok
  72     public void testExtractSecondRound() throws IOException {
  73         jimage("extract", getImagePath())
  74                 .assertSuccess()
  75                 .resultChecker(r -> {
  76                     assertTrue(r.output.isEmpty(), "Output is not expected");
  77                 });
  78         verifyExplodedImage(Paths.get("."));
  79     }
  80 
  81     public void testExtractHelp() {
  82         for (String opt : Arrays.asList("-h", "--help")) {
  83             jimage("extract", "--help")
  84                     .assertSuccess()
  85                     .resultChecker(r -> {
  86                         // extract  -  descriptive text
  87                         assertMatches("\\s+extract\\s+-\\s+.*", r.output);
  88                     });
  89         }
  90     }
  91 
  92     public void testExtractToDir() throws IOException {
  93         Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());
  94         jimage("extract", "--dir", tmp.toString(), getImagePath())
  95                 .assertSuccess()
  96                 .resultChecker(r -> {
  97                     assertTrue(r.output.isEmpty(), "Output is not expected");
  98                 });
  99         verifyExplodedImage(tmp);
 100     }
 101 
 102     public void testExtractNoImageSpecified() {
 103         jimage("extract", "")
 104                 .assertFailure()
 105                 .assertShowsError();
 106     }
 107 
 108     public void testExtractEmptyFile() throws IOException {
 109         Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "empty_file");
 110         jimage("extract", "--dir", "some_directory", tmp.toString())
 111                 .assertFailure()
 112                 .assertShowsError();
 113     }
 114 
 115     public void testExtractNotAnImage() throws IOException {
 116         Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "not_an_image");
 117         Files.write(tmp, "This is not an image".getBytes());
 118         jimage("extract", "--dir", "some_directory", tmp.toString())
 119                 .assertFailure()
 120                 .assertShowsError();
 121     }
 122 
 123     public void testExtractNotExistingImage() throws IOException {
 124         Path tmp = Paths.get(".", "not_existing_image");
 125         Files.deleteIfExists(tmp);
 126         jimage("extract", tmp.toString())
 127                 .assertFailure()
 128                 .assertShowsError();
 129     }
 130 
 131     public void testExtractToUnspecifiedDir() {
 132         jimage("extract", "--dir", "--", getImagePath())
 133                 .assertFailure()
 134                 .assertShowsError();
 135     }
 136 
 137     public void testExtractToNotExistingDir() throws IOException {
 138         Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());


< prev index next >