|
24 | 24 |
|
25 | 25 | import java.util.Collection;
|
26 | 26 | import java.util.List;
|
27 |
| -import jdk.jpackage.test.Annotations.Parameters; |
| 27 | +import java.util.Optional; |
| 28 | +import java.util.stream.Stream; |
| 29 | +import jdk.jpackage.test.Annotations.ParameterSupplier; |
28 | 30 | import jdk.jpackage.test.Annotations.Test;
|
| 31 | +import jdk.jpackage.test.CannedFormattedString; |
29 | 32 | import jdk.jpackage.test.JPackageCommand;
|
| 33 | +import jdk.jpackage.test.JPackageStringBundle; |
30 | 34 | import jdk.jpackage.test.TKit;
|
31 | 35 |
|
32 | 36 | /*
|
|
53 | 57 |
|
54 | 58 | public final class ErrorTest {
|
55 | 59 |
|
56 |
| - private final String expectedError; |
57 |
| - private final JPackageCommand cmd; |
58 |
| - |
59 |
| - @Parameters |
60 | 60 | public static Collection input() {
|
61 | 61 | return List.of(new Object[][]{
|
62 | 62 | // non-existent arg
|
63 | 63 | {"Hello",
|
64 | 64 | new String[]{"--no-such-argument"},
|
65 | 65 | null,
|
66 |
| - "Invalid Option: [--no-such-argument]"}, |
| 66 | + JPackageStringBundle.MAIN.cannedFormattedString("ERR_InvalidOption", "--no-such-argument")}, |
67 | 67 | // no main jar
|
68 | 68 | {"Hello",
|
69 | 69 | null,
|
70 | 70 | new String[]{"--main-jar"},
|
71 |
| - "--main-jar or --module"}, |
| 71 | + JPackageStringBundle.MAIN.cannedFormattedString("ERR_NoEntryPoint")}, |
72 | 72 | // no main-class
|
73 | 73 | {"Hello",
|
74 | 74 | null,
|
75 | 75 | new String[]{"--main-class"},
|
76 |
| - "main class was not specified"}, |
| 76 | + JPackageStringBundle.MAIN.cannedFormattedString("error.no-main-class-with-main-jar", "hello.jar"), |
| 77 | + JPackageStringBundle.MAIN.cannedFormattedString("error.no-main-class-with-main-jar.advice", "hello.jar")}, |
77 | 78 | // non-existent main jar
|
78 | 79 | {"Hello",
|
79 | 80 | new String[]{"--main-jar", "non-existent.jar"},
|
80 | 81 | null,
|
81 |
| - "main jar does not exist"}, |
| 82 | + JPackageStringBundle.MAIN.cannedFormattedString("error.main-jar-does-not-exist", "non-existent.jar")}, |
82 | 83 | // non-existent runtime
|
83 | 84 | {"Hello",
|
84 | 85 | new String[]{"--runtime-image", "non-existent.runtime"},
|
85 | 86 | null,
|
86 |
| - "does not exist"}, |
| 87 | + JPackageStringBundle.MAIN.cannedFormattedString("message.runtime-image-dir-does-not-exist", "runtime-image", "non-existent.runtime")}, |
87 | 88 | // non-existent resource-dir
|
88 | 89 | {"Hello",
|
89 | 90 | new String[]{"--resource-dir", "non-existent.dir"},
|
90 | 91 | null,
|
91 |
| - "does not exist"}, |
| 92 | + JPackageStringBundle.MAIN.cannedFormattedString("message.resource-dir-does-not-exist", "resource-dir", "non-existent.dir")}, |
92 | 93 | // invalid type
|
93 | 94 | {"Hello",
|
94 | 95 | new String[]{"--type", "invalid-type"},
|
95 | 96 | null,
|
96 |
| - "Invalid or unsupported type: [invalid-type]"}, |
| 97 | + JPackageStringBundle.MAIN.cannedFormattedString("ERR_InvalidInstallerType", "invalid-type")}, |
97 | 98 | // no --input
|
98 | 99 | {"Hello",
|
99 | 100 | null,
|
100 | 101 | new String[]{"--input"},
|
101 |
| - "Missing argument: --input"}, |
| 102 | + JPackageStringBundle.MAIN.cannedFormattedString("ERR_MissingArgument", "--input")}, |
102 | 103 | // no --module-path
|
103 | 104 | {"com.other/com.other.Hello",
|
104 | 105 | null,
|
105 | 106 | new String[]{"--module-path"},
|
106 |
| - "Missing argument: --runtime-image or --module-path"}, |
| 107 | + JPackageStringBundle.MAIN.cannedFormattedString("ERR_MissingArgument", "--runtime-image or --module-path")}, |
107 | 108 | });
|
108 | 109 | }
|
109 | 110 |
|
110 |
| - public ErrorTest(String javaAppDesc, String[] jpackageArgs, |
111 |
| - String[] removeArgs, |
112 |
| - String expectedError) { |
113 |
| - this.expectedError = expectedError; |
| 111 | + @Test |
| 112 | + @ParameterSupplier("input") |
| 113 | + public static void test(String javaAppDesc, String[] jpackageArgs, |
| 114 | + String[] removeArgs, CannedFormattedString... expectedErrors) { |
| 115 | + // Init default jpackage test command line. |
| 116 | + var cmd = JPackageCommand.helloAppImage(javaAppDesc) |
| 117 | + // Disable default logic adding `--verbose` option |
| 118 | + // to jpackage command line. |
| 119 | + // It will affect jpackage error messages if the command line is malformed. |
| 120 | + .ignoreDefaultVerbose(true) |
| 121 | + // Ignore external runtime as it will interfer |
| 122 | + // with jpackage arguments in this test. |
| 123 | + .ignoreDefaultRuntime(true); |
114 | 124 |
|
115 |
| - cmd = JPackageCommand.helloAppImage(javaAppDesc) |
116 |
| - .saveConsoleOutput(true).dumpOutput(true); |
117 |
| - if (jpackageArgs != null) { |
118 |
| - cmd.addArguments(jpackageArgs); |
119 |
| - } if (removeArgs != null) { |
120 |
| - for (String arg : removeArgs) { |
121 |
| - cmd.removeArgumentWithValue(arg); |
122 |
| - } |
123 |
| - } |
124 |
| - } |
| 125 | + // Add arguments if requested. |
| 126 | + Optional.ofNullable(jpackageArgs).ifPresent(cmd::addArguments); |
125 | 127 |
|
126 |
| - @Test |
127 |
| - public void test() { |
128 |
| - List<String> output = cmd.execute(1).getOutput(); |
129 |
| - TKit.assertNotNull(output, "output is null"); |
130 |
| - TKit.assertTextStream(expectedError).apply(output.stream()); |
131 |
| - } |
| 128 | + // Remove arguments if requested. |
| 129 | + Optional.ofNullable(removeArgs).map(List::of).ifPresent( |
| 130 | + args -> args.forEach(cmd::removeArgumentWithValue)); |
| 131 | + |
| 132 | + // Configure jpackage output verifier to look up the list of provided |
| 133 | + // errors in the order they specified. |
| 134 | + cmd.validateOutput(Stream.of(expectedErrors) |
| 135 | + .map(CannedFormattedString::getValue) |
| 136 | + .map(TKit::assertTextStream) |
| 137 | + .reduce(TKit.TextStreamVerifier::andThen).get()); |
132 | 138 |
|
| 139 | + cmd.execute(1); |
| 140 | + } |
133 | 141 | }
|
0 commit comments