Path: blob/master/test/jdk/tools/jimage/JImageVerifyTest.java
41144 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @summary Tests to verify jimage 'verify' action26* @library /test/lib27* @modules jdk.jlink/jdk.tools.jimage28* @build jdk.test.lib.Asserts29* @run main JImageVerifyTest30*/3132import java.io.IOException;33import java.nio.file.Files;34import java.nio.file.Path;35import java.nio.file.Paths;36import java.util.Arrays;3738import static jdk.test.lib.Asserts.assertTrue;3940public class JImageVerifyTest extends JImageCliTest {4142public void testVerify() {43jimage("verify", getImagePath())44.assertSuccess()45.resultChecker(r -> {46assertTrue(r.output.startsWith("jimage: " + getImagePath()),47"Contains verified image's path");48});49}5051public void testVerifyHelp() {52for (String opt : Arrays.asList("-h", "--help")) {53jimage("verify", opt)54.assertSuccess()55.resultChecker(r -> {56// verify - descriptive text57assertMatches("\\s+verify\\s+-\\s+.*", r.output);58});59}60}6162public void testVerifyImageNotSpecified() {63jimage("verify", "")64.assertFailure()65.assertShowsError();66}6768public void testVerifyNotAnImage() throws IOException {69Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "not_an_image");70jimage("verify", tmp.toString())71.assertFailure()72.assertShowsError();73}7475public void testVerifyNotExistingImage() throws IOException {76Path tmp = Paths.get(".", "not_existing_image");77Files.deleteIfExists(tmp);78jimage("verify", "")79.assertFailure()80.assertShowsError();81}8283public void testVerifyWithUnknownOption() {84jimage("verify", "--unknown")85.assertFailure()86.assertShowsError();87}8889public static void main(String[] args) throws Throwable {90new JImageVerifyTest().runTests();91}9293}949596