author | prr |
Wed, 29 Nov 2017 09:47:02 -0800 | |
changeset 47982 | 44371ff1ee9a |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
42167
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
1 |
/* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
4 |
* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
8 |
* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
13 |
* accompanied this code). |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
14 |
* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
18 |
* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
21 |
* questions. |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
22 |
*/ |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
23 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
24 |
/* |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
25 |
* @test |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
26 |
* @summary Tests to verify jimage 'verify' action |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
27 |
* @library /test/lib |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
28 |
* @modules jdk.jlink/jdk.tools.jimage |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
29 |
* @build jdk.test.lib.Asserts |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
30 |
* @run main JImageVerifyTest |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
31 |
*/ |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
32 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
33 |
import java.io.IOException; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
34 |
import java.nio.file.Files; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
35 |
import java.nio.file.Path; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
36 |
import java.nio.file.Paths; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
37 |
import java.util.Arrays; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
38 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
39 |
import static jdk.test.lib.Asserts.assertTrue; |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
40 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
41 |
public class JImageVerifyTest extends JImageCliTest { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
42 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
43 |
public void testVerify() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
44 |
jimage("verify", getImagePath()) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
45 |
.assertSuccess() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
46 |
.resultChecker(r -> { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
47 |
assertTrue(r.output.startsWith("jimage: " + getImagePath()), |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
48 |
"Contains verified image's path"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
49 |
}); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
50 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
51 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
52 |
public void testVerifyHelp() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
53 |
for (String opt : Arrays.asList("-h", "--help")) { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
54 |
jimage("verify", opt) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
55 |
.assertSuccess() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
56 |
.resultChecker(r -> { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
57 |
// verify - descriptive text |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
58 |
assertMatches("\\s+verify\\s+-\\s+.*", r.output); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
59 |
}); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
60 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
61 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
62 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
63 |
public void testVerifyImageNotSpecified() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
64 |
jimage("verify", "") |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
65 |
.assertFailure() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
66 |
.assertShowsError(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
67 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
68 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
69 |
public void testVerifyNotAnImage() throws IOException { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
70 |
Path tmp = Files.createTempFile(Paths.get("."), getClass().getName(), "not_an_image"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
71 |
jimage("verify", tmp.toString()) |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
72 |
.assertFailure() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
73 |
.assertShowsError(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
74 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
75 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
76 |
public void testVerifyNotExistingImage() throws IOException { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
77 |
Path tmp = Paths.get(".", "not_existing_image"); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
78 |
Files.deleteIfExists(tmp); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
79 |
jimage("verify", "") |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
80 |
.assertFailure() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
81 |
.assertShowsError(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
82 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
83 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
84 |
public void testVerifyWithUnknownOption() { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
85 |
jimage("verify", "--unknown") |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
86 |
.assertFailure() |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
87 |
.assertShowsError(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
88 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
89 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
90 |
public static void main(String[] args) throws Throwable { |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
91 |
new JImageVerifyTest().runTests(); |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
92 |
} |
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
93 |
|
312b1ca6b1df
8167240: Write new tests to cover functionality of existing 'jimage' options
dkononenko
parents:
diff
changeset
|
94 |
} |