-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
CliProjectJBangTest.java
218 lines (164 loc) · 9.69 KB
/
CliProjectJBangTest.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
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;
public class CliProjectJBangTest {
static Path workspaceRoot = Paths.get(System.getProperty("user.dir")).toAbsolutePath()
.resolve("target/test-project/CliProjectJBangTest");
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", "--jbang", "--verbose", "-e", "-B");
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("jbang").toFile().exists(),
"Wrapper should exist by default");
validateBasicIdentifiers(project, CreateProjectHelper.DEFAULT_GROUP_ID,
CreateProjectHelper.DEFAULT_ARTIFACT_ID,
CreateProjectHelper.DEFAULT_VERSION);
Path javaMain = valdiateJBangSourcePackage(project, ""); // no package name
String source = CliDriver.readFileAsString(project, javaMain);
Assertions.assertTrue(source.contains("quarkus-resteasy"),
"Generated source should reference resteasy. Found:\n" + source);
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);
}
@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", "--jbang", "--verbose", "-e", "-B",
"--package-name=custom.pkg",
"--output-directory=" + nested,
"--app-config=" + String.join(",", configs),
"-x reactive-routes",
"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.assertTrue(project.resolve("jbang").toFile().exists(),
"Wrapper should exist by default");
validateBasicIdentifiers(project, "silly", "my-project", "0.1.0");
Path javaMain = valdiateJBangSourcePackage(project, "");
String source = CliDriver.readFileAsString(project, javaMain);
Assertions.assertTrue(source.contains("quarkus-reactive-routes"),
"Generated source should reference quarkus-reactive-routes. Found:\n" + source);
result = CliDriver.invokeValidateDryRunBuild(project);
CliDriver.invokeValidateBuild(project);
}
@Test
public void testCreateCliDefaults() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "cli", "--jbang", "--verbose", "-e", "-B");
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("jbang").toFile().exists(),
"Wrapper should exist by default");
validateBasicIdentifiers(project, CreateProjectHelper.DEFAULT_GROUP_ID,
CreateProjectHelper.DEFAULT_ARTIFACT_ID,
CreateProjectHelper.DEFAULT_VERSION);
Path javaMain = valdiateJBangSourcePackage(project, ""); // no package name
String source = CliDriver.readFileAsString(project, javaMain);
Assertions.assertFalse(source.contains("quarkus-resteasy"),
"Generated source should reference resteasy. Found:\n" + source);
Assertions.assertTrue(source.contains("quarkus-picocli"),
"Generated source should not reference picocli. Found:\n" + source);
result = CliDriver.invokeValidateDryRunBuild(project);
result = CliDriver.execute(project, "build", "-e", "-B", "--clean", "--verbose",
"-Dproperty=value1", "-Dproperty2=value2");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);
}
@Test
public void testBuildOptions() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "--jbang", "-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("--fresh"),
"jbang command should specify '--fresh'\n" + result);
// presently no support for --tests or --no-tests
Assertions.assertTrue(result.stdout.contains("--native"),
"jbang command should specify --native\n" + result);
Assertions.assertTrue(result.stdout.contains("--offline"),
"jbang 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("--fresh"),
"jbang command should not specify '--fresh'\n" + result);
// presently no support for --tests or --no-tests
Assertions.assertFalse(result.stdout.contains("native"),
"jbang command should not specify native\n" + result);
Assertions.assertFalse(result.stdout.contains("offline"),
"jbang command should not specify offline\n" + result);
}
@Test
public void testCreateArgJava11() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "--jbang",
"-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 javaMain = valdiateJBangSourcePackage(project, ""); // no package name
String source = CliDriver.readFileAsString(project, javaMain);
Assertions.assertTrue(source.contains("//JAVA 11"),
"Generated source should contain //JAVA 11. Found:\n" + source);
}
@Test
public void testCreateArgJava17() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "--jbang",
"-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 javaMain = valdiateJBangSourcePackage(project, ""); // no package name
String source = CliDriver.readFileAsString(project, javaMain);
Assertions.assertTrue(source.contains("//JAVA 17"),
"Generated source should contain //JAVA 17. Found:\n" + source);
}
void validateBasicIdentifiers(Path project, String group, String artifact, String version) throws Exception {
Assertions.assertTrue(project.resolve("README.md").toFile().exists(),
"README.md should exist: " + project.resolve("README.md").toAbsolutePath().toString());
// TODO: while jbang supports packages, the generation command does not
// Should the version be stored in metadata anywhere? Is that useful for script management?
}
Path valdiateJBangSourcePackage(Path project, String name) {
Path packagePath = project.resolve("src/" + name);
Assertions.assertTrue(packagePath.toFile().exists(),
"Package directory should exist: " + packagePath.toAbsolutePath().toString());
Assertions.assertTrue(packagePath.toFile().isDirectory(),
"Package directory should be a directory: " + packagePath.toAbsolutePath().toString());
return packagePath.resolve("main.java");
}
}