-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
CliProjectMavenTest.java
358 lines (281 loc) · 17.5 KB
/
CliProjectMavenTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
package io.quarkus.cli;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import io.quarkus.devtools.commands.CreateProjectHelper;
import io.quarkus.devtools.testing.RegistryClientTestHelper;
import picocli.CommandLine;
/**
* Similar to CliProjectGradleTest ..
*/
public class CliProjectMavenTest {
static Path workspaceRoot = Paths.get(System.getProperty("user.dir")).toAbsolutePath()
.resolve("target/test-project/CliProjectMavenTest");
Path project;
@BeforeAll
public static void setupTestRegistry() {
RegistryClientTestHelper.enableRegistryClientTestConfig();
}
@AfterAll
public static void cleanupTestRegistry() {
RegistryClientTestHelper.disableRegistryClientTestConfig();
}
@BeforeEach
public void setupTestDirectories() throws Exception {
CliDriver.deleteDir(workspaceRoot);
project = workspaceRoot.resolve("code-with-quarkus");
}
@Test
public void testCreateAppDefaults() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "-e", "-B", "--verbose");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
Assertions.assertTrue(result.stdout.contains("SUCCESS"),
"Expected confirmation that the project has been created." + result);
Assertions.assertTrue(project.resolve("mvnw").toFile().exists(),
"Wrapper should exist by default");
String pomContent = validateBasicIdentifiers(CreateProjectHelper.DEFAULT_GROUP_ID,
CreateProjectHelper.DEFAULT_ARTIFACT_ID,
CreateProjectHelper.DEFAULT_VERSION);
Assertions.assertTrue(pomContent.contains("<artifactId>quarkus-resteasy-reactive</artifactId>"),
"pom.xml should contain quarkus-resteasy-reactive:\n" + pomContent);
CliDriver.valdiateGeneratedSourcePackage(project, "org/acme");
result = CliDriver.invokeValidateDryRunBuild(project);
CliDriver.invokeValidateBuild(project);
// Test create project that already exists
result = CliDriver.execute(workspaceRoot, "create", "app", "-e", "-B", "--verbose");
Assertions.assertTrue(result.stdout.contains("quarkus create app --help"),
"Response should reference --help:\n" + result);
}
@Test
public void testCreateAppOverrides() throws Exception {
Path nested = workspaceRoot.resolve("cli-nested");
project = nested.resolve("my-project");
List<String> configs = Arrays.asList("custom.app.config1=val1",
"custom.app.config2=val2", "lib.config=val3");
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "--verbose", "-e", "-B",
"--no-wrapper", "--package-name=custom.pkg",
"--output-directory=" + nested,
"--app-config=" + String.join(",", configs),
"-x resteasy-reactive,micrometer-registry-prometheus",
"silly:my-project:0.1.0");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
Assertions.assertTrue(result.stdout.contains("SUCCESS"),
"Expected confirmation that the project has been created." + result);
Assertions.assertFalse(project.resolve("mvnw").toFile().exists(),
"Wrapper should not exist when specifying --no-wrapper");
String pomContent = validateBasicIdentifiers("silly", "my-project", "0.1.0");
Assertions.assertTrue(pomContent.contains("<artifactId>quarkus-resteasy-reactive</artifactId>"),
"pom.xml should contain quarkus-resteasy-reactive:\n" + pomContent);
CliDriver.valdiateGeneratedSourcePackage(project, "custom/pkg");
CliDriver.validateApplicationProperties(project, configs);
result = CliDriver.invokeValidateDryRunBuild(project);
Assertions.assertTrue(result.stdout.contains("-Dproperty=value1 -Dproperty2=value2"),
"result should contain '-Dproperty=value1 -Dproperty2=value2':\n" + result.stdout);
CliDriver.invokeValidateBuild(project);
result = CliDriver.execute(workspaceRoot, "create", "app", "--dry-run", "--verbose", "-e", "-B",
"--output-directory=" + nested,
"silly:my-project:0.1.0");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code. " + result);
Assertions.assertTrue(result.stdout.contains("WARN"),
"Expected a warning that the directory already exists. " + result);
}
@Test
public void testExtensionList() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "-e", "-B", "--verbose");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
Path pom = project.resolve("pom.xml");
String pomContent = CliDriver.readFileAsString(project, pom);
Assertions.assertFalse(pomContent.contains("quarkus-qute"),
"Dependencies should not contain qute extension by default. Found:\n" + pomContent);
CliDriver.invokeExtensionAddQute(project, pom);
CliDriver.invokeExtensionAddRedundantQute(project);
CliDriver.invokeExtensionListInstallable(project);
CliDriver.invokeExtensionAddMultiple(project, pom);
CliDriver.invokeExtensionRemoveQute(project, pom);
CliDriver.invokeExtensionRemoveMultiple(project, pom);
CliDriver.invokeExtensionListInstallableSearch(project);
CliDriver.invokeExtensionListFormatting(project);
// TODO: Maven and Gradle give different return codes
result = CliDriver.invokeExtensionRemoveNonexistent(project);
Assertions.assertEquals(CommandLine.ExitCode.SOFTWARE, result.exitCode,
"Expected error return code. Result:\n" + result);
}
@Test
public void testBuildOptions() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "-e", "-B", "--verbose");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
// 1 --clean --tests --native --offline
result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
"--clean", "--tests", "--native", "--offline");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);
Assertions.assertTrue(result.stdout.contains(" clean"),
"mvn command should specify 'clean'\n" + result);
Assertions.assertFalse(result.stdout.contains("-DskipTests"),
"mvn command should not specify -DskipTests\n" + result);
Assertions.assertFalse(result.stdout.contains("-Dmaven.test.skip=true"),
"mvn command should not specify -Dmaven.test.skip=true\n" + result);
Assertions.assertTrue(result.stdout.contains("-Dnative"),
"mvn command should specify -Dnative\n" + result);
Assertions.assertTrue(result.stdout.contains("--offline"),
"mvn command should specify --offline\n" + result);
// 2 --no-clean --no-tests
result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
"--no-clean", "--no-tests");
Assertions.assertFalse(result.stdout.contains(" clean"),
"mvn command should not specify 'clean'\n" + result);
Assertions.assertTrue(result.stdout.contains("-DskipTests"),
"mvn command should specify -DskipTests\n" + result);
Assertions.assertTrue(result.stdout.contains("-Dmaven.test.skip=true"),
"mvn command should specify -Dmaven.test.skip=true\n" + result);
Assertions.assertFalse(result.stdout.contains("-Dnative"),
"mvn command should not specify -Dnative\n" + result);
Assertions.assertFalse(result.stdout.contains("--offline"),
"mvn command should not specify --offline\n" + result);
}
@Test
public void testDevOptions() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "-e", "-B", "--verbose");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
// 1 --clean --tests --suspend --offline
result = CliDriver.execute(project, "dev", "-e", "--dry-run",
"--clean", "--tests", "--debug", "--suspend", "--debug-mode=listen", "--offline");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);
Assertions.assertTrue(result.stdout.contains("MAVEN"),
"quarkus command should specify 'MAVEN'\n" + result);
Assertions.assertTrue(result.stdout.contains(" clean"),
"mvn command should specify 'clean'\n" + result);
Assertions.assertFalse(result.stdout.contains("-DskipTests"),
"mvn command should not specify -DskipTests\n" + result);
Assertions.assertFalse(result.stdout.contains("-Dmaven.test.skip=true"),
"mvn command should not specify -Dmaven.test.skip=true\n" + result);
Assertions.assertFalse(result.stdout.contains("-Ddebug"),
"mvn command should not specify '-Ddebug'\n" + result);
Assertions.assertTrue(result.stdout.contains("-Dsuspend"),
"mvn command should specify '-Dsuspend'\n" + result);
Assertions.assertTrue(result.stdout.contains("--offline"),
"mvn command should specify --offline\n" + result);
// 2 --no-clean --no-tests --no-debug
result = CliDriver.execute(project, "dev", "-e", "--dry-run",
"--no-clean", "--no-tests", "--no-debug");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);
Assertions.assertTrue(result.stdout.contains("MAVEN"),
"quarkus command should specify 'MAVEN'\n" + result);
Assertions.assertFalse(result.stdout.contains(" clean"),
"mvn command should not specify 'clean'\n" + result);
Assertions.assertTrue(result.stdout.contains("-DskipTests"),
"mvn command should specify -DskipTests\n" + result);
Assertions.assertTrue(result.stdout.contains("-Dmaven.test.skip=true"),
"mvn command should specify -Dmaven.test.skip=true\n" + result);
Assertions.assertTrue(result.stdout.contains("-Ddebug=false"),
"mvn command should specify '-Ddebug=false'\n" + result);
Assertions.assertFalse(result.stdout.contains("-Dsuspend"),
"mvn command should not specify '-Dsuspend'\n" + result);
// 3 --no-suspend --debug-host=0.0.0.0 --debug-port=8008 --debug-mode=connect -- arg1 arg2
result = CliDriver.execute(project, "dev", "-e", "--dry-run",
"--no-suspend", "--debug-host=0.0.0.0", "--debug-port=8008", "--debug-mode=connect", "--", "arg1", "arg2");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);
Assertions.assertTrue(result.stdout.contains("MAVEN"),
"quarkus command should specify 'MAVEN'\n" + result);
Assertions.assertTrue(
result.stdout.contains("-DdebugHost=0.0.0.0 -Ddebug=client -DdebugPort=8008"),
"mvn command should specify -DdebugHost=0.0.0.0 -Ddebug=client -DdebugPort=8008\n" + result);
Assertions.assertFalse(result.stdout.contains("-Dsuspend"),
"mvn command should not specify '-Dsuspend'\n" + result);
Assertions.assertTrue(result.stdout.contains("-Dquarkus.args='arg1 arg2'"),
"mvn command should not specify -Dquarkus.args='arg1 arg2'\n" + result);
}
@Test
public void testCreateCliDefaults() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "cli", "-e", "-B", "--verbose");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
Assertions.assertTrue(result.stdout.contains("SUCCESS"),
"Expected confirmation that the project has been created." + result);
Assertions.assertTrue(project.resolve("mvnw").toFile().exists(),
"Wrapper should exist by default");
String pomContent = validateBasicIdentifiers(CreateProjectHelper.DEFAULT_GROUP_ID,
CreateProjectHelper.DEFAULT_ARTIFACT_ID,
CreateProjectHelper.DEFAULT_VERSION);
Assertions.assertFalse(pomContent.contains("<artifactId>quarkus-resteasy</artifactId>"),
"pom.xml should not contain quarkus-resteasy:\n" + pomContent);
Assertions.assertTrue(pomContent.contains("<artifactId>quarkus-picocli</artifactId>"),
"pom.xml should contain quarkus-picocli:\n" + pomContent);
CliDriver.valdiateGeneratedSourcePackage(project, "org/acme");
result = CliDriver.invokeValidateDryRunBuild(project);
CliDriver.invokeValidateBuild(project);
}
@Test
public void testCreateArgPassthrough() throws Exception {
Path nested = workspaceRoot.resolve("cli-nested");
project = nested.resolve("my-project");
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create",
"--verbose", "-e", "-B",
"--dryrun", "--no-wrapper", "--package-name=custom.pkg",
"-x resteasy-reactive",
"-x micrometer",
"--output-directory=" + nested,
"silly:my-project:0.1.0");
// We don't need to retest this, just need to make sure all the arguments were passed through
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
Assertions.assertTrue(result.stdout.contains("Creating an app"),
"Should contain 'Creating an app', found: " + result.stdout);
Assertions.assertTrue(result.stdout.contains("MAVEN"),
"Should contain MAVEN, found: " + result.stdout);
// strip spaces to avoid fighting with column whitespace
String noSpaces = result.stdout.replaceAll("[\\s\\p{Z}]", "");
Assertions.assertTrue(noSpaces.contains("Omitbuildtoolwrappertrue"),
"Should contain 'Omit build tool wrapper true', found: " + result.stdout);
Assertions.assertTrue(noSpaces.contains("PackageNamecustom.pkg"),
"Should contain 'Package Name custom.pkg', found: " + result.stdout);
Assertions.assertTrue(noSpaces.contains("ProjectArtifactIdmy-project"),
"Output should contain 'Project ArtifactId my-project', found: " + result.stdout);
Assertions.assertTrue(noSpaces.contains("ProjectGroupIdsilly"),
"Output should contain 'Project GroupId silly', found: " + result.stdout);
}
@Test
public void testCreateArgJava11() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app",
"-e", "-B", "--verbose",
"--java", "11");
// We don't need to retest this, just need to make sure all the arguments were passed through
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
Path pom = project.resolve("pom.xml");
String pomContent = CliDriver.readFileAsString(project, pom);
Assertions.assertTrue(pomContent.contains("maven.compiler.release>11<"),
"Java 11 should be used when specified. Found:\n" + pomContent);
}
@Test
public void testCreateArgJava17() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app",
"-e", "-B", "--verbose",
"--java", "17");
// We don't need to retest this, just need to make sure all the arguments were passed through
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
Path pom = project.resolve("pom.xml");
String pomContent = CliDriver.readFileAsString(project, pom);
Assertions.assertTrue(pomContent.contains("maven.compiler.release>17<"),
"Java 17 should be used when specified. Found:\n" + pomContent);
}
String validateBasicIdentifiers(String group, String artifact, String version) throws Exception {
Path pom = project.resolve("pom.xml");
Assertions.assertTrue(pom.toFile().exists(),
"pom.xml should exist: " + pom.toAbsolutePath().toString());
String pomContent = CliDriver.readFileAsString(project, pom);
Assertions.assertTrue(pomContent.contains("<groupId>" + group + "</groupId>"),
"pom.xml should contain group id:\n" + pomContent);
Assertions.assertTrue(pomContent.contains("<artifactId>" + artifact + "</artifactId>"),
"pom.xml should contain artifact id:\n" + pomContent);
Assertions.assertTrue(pomContent.contains("<version>" + version + "</version>"),
"pom.xml should contain version:\n" + pomContent);
return pomContent;
}
}