< prev index next >

test/jdk/tools/jimage/JImageExtractTest.java

Print this page




  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/timeout=300 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.*;
  38 import java.util.Arrays;
  39 import java.util.HashSet;
  40 import java.util.List;
  41 import java.util.Set;
  42 import java.util.stream.Collectors;

  43 
  44 import static jdk.test.lib.Asserts.assertEquals;
  45 import static jdk.test.lib.Asserts.assertTrue;
  46 
  47 public class JImageExtractTest extends JImageCliTest {































  48     public void testExtract() throws IOException {
  49         Set<Path> notJImageModules = Files.walk(Paths.get("."),1).collect(Collectors.toSet());
  50         jimage("extract", getImagePath())
  51                 .assertSuccess()
  52                 .resultChecker(r -> {
  53                     assertTrue(r.output.isEmpty(), "Output is not expected");
  54                 });
  55         verifyExplodedImage(Paths.get("."), notJImageModules);
  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     }




  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/timeout=300 JImageExtractTest
  31  */
  32 
  33 import java.io.IOException;
  34 import java.io.UncheckedIOException;
  35 import java.nio.file.Files;
  36 import java.nio.file.Path;
  37 import java.nio.file.Paths;
  38 import java.nio.file.attribute.*;
  39 import java.util.Arrays;
  40 import java.util.HashSet;
  41 import java.util.List;
  42 import java.util.Set;
  43 import java.util.stream.Collectors;
  44 import java.util.spi.ToolProvider;
  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     private static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink")
  51         .orElseThrow(() ->
  52             new RuntimeException("jlink tool not found")
  53         );
  54 
  55 
  56     private String smallBootImagePath;
  57 
  58     public JImageExtractTest() {
  59         try {
  60             Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());
  61             tmp = tmp.toAbsolutePath();
  62             tmp.toFile().deleteOnExit();
  63             Path smalljre = tmp.resolve("smalljdk");
  64             if (JLINK_TOOL.run(System.out, System.err,
  65                     "--add-modules", "java.base",
  66                     "--add-modules", "jdk.zipfs",
  67                     "--output", smalljre.toString()) != 0) {
  68                 throw new RuntimeException("failed to create small boot image");
  69             }
  70             this.smallBootImagePath = smalljre.resolve("lib").resolve("modules").toString();
  71         } catch (IOException ioExp) {
  72             throw new UncheckedIOException(ioExp);
  73         }
  74     }
  75 
  76     @Override
  77     public String getImagePath() {
  78         return smallBootImagePath;
  79     }
  80 
  81     public void testExtract() throws IOException {
  82         Set<Path> notJImageModules = Files.walk(Paths.get("."),1).collect(Collectors.toSet());
  83         jimage("extract", getImagePath())
  84                 .assertSuccess()
  85                 .resultChecker(r -> {
  86                     assertTrue(r.output.isEmpty(), "Output is not expected");
  87                 });
  88         verifyExplodedImage(Paths.get("."), notJImageModules);
  89     }
  90 
  91     public void testExtractHelp() {
  92         for (String opt : Arrays.asList("-h", "--help")) {
  93             jimage("extract", "--help")
  94                     .assertSuccess()
  95                     .resultChecker(r -> {
  96                         // extract  -  descriptive text
  97                         assertMatches("\\s+extract\\s+-\\s+.*", r.output);
  98                     });
  99         }
 100     }


< prev index next >