Skip to content

Commit 58f1455

Browse files
authored
Merge pull request quarkusio#47892 from holly-cummins/config-access-in-test-profiles
Dont use Facade ClassLoader as TCCL for interacting with profiles
2 parents d92f5c2 + be9e8ce commit 58f1455

File tree

11 files changed

+440
-3
lines changed

11 files changed

+440
-3
lines changed

integration-tests/maven/src/test/java/io/quarkus/maven/it/QuarkusTestIT.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,40 @@ public void testQuarkusTestGuardedByCondition()
196196

197197
}
198198

199+
/*
200+
* This should perhaps be in a different project, see https://github.com/quarkusio/quarkus/issues/46667
201+
*/
202+
@Test
203+
public void testQuarkusTestWithConfigInTestProfileContinuousTesting()
204+
throws MavenInvocationException, FileNotFoundException {
205+
//we also check continuous testing
206+
String sourceDir = "projects/test-config-in-test-profile";
207+
testDir = initProject(sourceDir, sourceDir + "-processed-devmode");
208+
209+
runAndCheck();
210+
211+
ContinuousTestingMavenTestUtils testingTestUtils = new ContinuousTestingMavenTestUtils(getPort());
212+
ContinuousTestingMavenTestUtils.TestStatus results = testingTestUtils.waitForNextCompletion();
213+
// This is a bit brittle when we add tests, but failures are often so catastrophic they're not even reported as failures,
214+
// so we need to check the pass count explicitly
215+
Assertions.assertEquals(0, results.getTestsFailed());
216+
Assertions.assertEquals(2, results.getTestsPassed());
217+
}
218+
219+
@Test
220+
public void testQuarkusTestWithConfigInTestProfile()
221+
throws MavenInvocationException, InterruptedException {
222+
String sourceDir = "projects/test-config-in-test-profile";
223+
testDir = initProject(sourceDir, sourceDir + "-processed");
224+
RunningInvoker invoker = new RunningInvoker(testDir, false);
225+
226+
// to properly surface the problem of multiple classpath entries, we need to install the project to the local m2
227+
MavenProcessInvocationResult installInvocation = invoker.execute(
228+
List.of("clean", "verify", "-Dquarkus.analytics.disabled=true"),
229+
Collections.emptyMap());
230+
assertThat(installInvocation.getProcess().waitFor(2, TimeUnit.MINUTES)).isTrue();
231+
assertThat(installInvocation.getExecutionException()).isNull();
232+
assertThat(installInvocation.getExitCode()).isEqualTo(0);
233+
234+
}
199235
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project>
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.acme</groupId>
6+
<artifactId>quarkus-test-config-in-test-profile</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<properties>
10+
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
11+
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
12+
<quarkus.platform.version>@project.version@</quarkus.platform.version>
13+
<quarkus-plugin.version>@project.version@</quarkus-plugin.version>
14+
<compiler-plugin.version>${compiler-plugin.version}</compiler-plugin.version>
15+
<surefire-plugin.version>${version.surefire.plugin}</surefire-plugin.version>
16+
<maven.compiler.source>${maven.compiler.source}</maven.compiler.source>
17+
<maven.compiler.target>${maven.compiler.target}</maven.compiler.target>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
21+
<dependencyManagement>
22+
<dependencies>
23+
<dependency>
24+
<groupId>\${quarkus.platform.group-id}</groupId>
25+
<artifactId>\${quarkus.platform.artifact-id}</artifactId>
26+
<version>\${quarkus.platform.version}</version>
27+
<type>pom</type>
28+
<scope>import</scope>
29+
</dependency>
30+
</dependencies>
31+
</dependencyManagement>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>io.quarkus</groupId>
36+
<artifactId>quarkus-resteasy</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>io.quarkus</groupId>
40+
<artifactId>quarkus-junit5</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>io.rest-assured</groupId>
45+
<artifactId>rest-assured</artifactId>
46+
<scope>test</scope>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<artifactId>maven-surefire-plugin</artifactId>
54+
<version>\${surefire-plugin.version}</version>
55+
<configuration>
56+
<systemPropertyVariables>
57+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
58+
<maven.home>\${maven.home}</maven.home>
59+
</systemPropertyVariables>
60+
</configuration>
61+
</plugin>
62+
<plugin>
63+
<groupId>io.quarkus</groupId>
64+
<artifactId>quarkus-maven-plugin</artifactId>
65+
<version>\${quarkus-plugin.version}</version>
66+
<executions>
67+
<execution>
68+
<goals>
69+
<goal>build</goal>
70+
</goals>
71+
</execution>
72+
</executions>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
77+
78+
<profiles>
79+
<profile>
80+
<id>native</id>
81+
<activation>
82+
<property>
83+
<name>native</name>
84+
</property>
85+
</activation>
86+
<properties>
87+
<quarkus.native.enabled>true</quarkus.native.enabled>
88+
</properties>
89+
<build>
90+
<plugins>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-surefire-plugin</artifactId>
94+
<configuration>
95+
<skipTests>\${native.surefire.skip}</skipTests>
96+
</configuration>
97+
</plugin>
98+
<plugin>
99+
<artifactId>maven-failsafe-plugin</artifactId>
100+
<version>\${surefire-plugin.version}</version>
101+
<executions>
102+
<execution>
103+
<goals>
104+
<goal>integration-test</goal>
105+
<goal>verify</goal>
106+
</goals>
107+
<configuration>
108+
<systemPropertyVariables>
109+
<native.image.path>\${project.build.directory}/\${project.build.finalName}-runner</native.image.path>
110+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
111+
<maven.home>\${maven.home}</maven.home>
112+
</systemPropertyVariables>
113+
</configuration>
114+
</execution>
115+
</executions>
116+
</plugin>
117+
</plugins>
118+
</build>
119+
</profile>
120+
</profiles>
121+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.acme;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
import jakarta.ws.rs.PathParam;
6+
import jakarta.ws.rs.Produces;
7+
import jakarta.ws.rs.core.MediaType;
8+
9+
@Path("/greeting")
10+
public class GreetingEndpoint {
11+
12+
@GET
13+
@Produces(MediaType.TEXT_PLAIN)
14+
@Path("{name}")
15+
public String greet(@PathParam("name") String name) {
16+
17+
return "Hello" + name;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.acme;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
import jakarta.ws.rs.Produces;
6+
import jakarta.ws.rs.core.MediaType;
7+
8+
@Path("/hello")
9+
public class HelloResource {
10+
11+
12+
@GET
13+
@Produces(MediaType.TEXT_PLAIN)
14+
public String hello() {
15+
return "hello";
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.acme;
2+
3+
import jakarta.ws.rs.ApplicationPath;
4+
import jakarta.ws.rs.core.Application;
5+
6+
@ApplicationPath("/app")
7+
public class MyApplication extends Application {
8+
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>acme - 1.0-SNAPSHOT</title>
6+
<style>
7+
h1, h2, h3, h4, h5, h6 {
8+
margin-bottom: 0.5rem;
9+
font-weight: 400;
10+
line-height: 1.5;
11+
}
12+
13+
h1 {
14+
font-size: 2.5rem;
15+
}
16+
17+
h2 {
18+
font-size: 2rem
19+
}
20+
21+
h3 {
22+
font-size: 1.75rem
23+
}
24+
25+
h4 {
26+
font-size: 1.5rem
27+
}
28+
29+
h5 {
30+
font-size: 1.25rem
31+
}
32+
33+
h6 {
34+
font-size: 1rem
35+
}
36+
37+
.lead {
38+
font-weight: 300;
39+
font-size: 2rem;
40+
}
41+
42+
.banner {
43+
font-size: 2.7rem;
44+
margin: 0;
45+
padding: 2rem 1rem;
46+
background-color: #00A1E2;
47+
color: white;
48+
}
49+
50+
body {
51+
margin: 0;
52+
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
53+
}
54+
55+
code {
56+
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
57+
font-size: 87.5%;
58+
color: #e83e8c;
59+
word-break: break-word;
60+
}
61+
62+
.left-column {
63+
padding: .75rem;
64+
max-width: 75%;
65+
min-width: 55%;
66+
}
67+
68+
.right-column {
69+
padding: .75rem;
70+
max-width: 25%;
71+
}
72+
73+
.container {
74+
display: flex;
75+
width: 100%;
76+
}
77+
78+
li {
79+
margin: 0.75rem;
80+
}
81+
82+
.right-section {
83+
margin-left: 1rem;
84+
padding-left: 0.5rem;
85+
}
86+
87+
.right-section h3 {
88+
padding-top: 0;
89+
font-weight: 200;
90+
}
91+
92+
.right-section ul {
93+
border-left: 0.3rem solid #00A1E2;
94+
list-style-type: none;
95+
padding-left: 0;
96+
}
97+
98+
</style>
99+
</head>
100+
<body>
101+
102+
<div class="banner lead">
103+
Your new Cloud-Native application is ready!
104+
</div>
105+
106+
<div class="container">
107+
<div class="left-column">
108+
<p class="lead"> Congratulations, you have created a new Quarkus application.</p>
109+
110+
<h2>Why do you see this?</h2>
111+
112+
<p>This page is served by Quarkus. The source is in
113+
<code>src/main/resources/META-INF/resources/index.html</code>.</p>
114+
115+
<h2>What can I do from here?</h2>
116+
117+
<p>If not already done, run the application in <em>dev mode</em> using: <code>mvn quarkus:dev</code>.
118+
</p>
119+
<ul>
120+
<li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li>
121+
<li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
122+
<li>Configure your application in <code>src/main/resources/application.properties</code>.
123+
</li>
124+
</ul>
125+
126+
<h2>Do you like Quarkus?</h2>
127+
<p>Go give it a star on <a href="https://github.com/quarkusio/quarkus">GitHub</a>.</p>
128+
129+
<h2>How do I get rid of this page?</h2>
130+
<p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
131+
</div>
132+
<div class="right-column">
133+
<div class="right-section">
134+
<h3>Application</h3>
135+
<ul>
136+
<li>GroupId: org.acme</li>
137+
<li>ArtifactId: acme</li>
138+
<li>Version: 1.0-SNAPSHOT</li>
139+
<li>Quarkus Version: 999-SNAPSHOT</li>
140+
</ul>
141+
</div>
142+
<div class="right-section">
143+
<h3>Next steps</h3>
144+
<ul>
145+
<!-- the url have been erased on purpose -->
146+
<li><a href="#">Setup your IDE</a></li>
147+
<li><a href="#">Getting started</a></li>
148+
<li><a href="#">Documentation</a></li>
149+
</ul>
150+
</div>
151+
</div>
152+
</div>
153+
154+
155+
</body>
156+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
quarkus.test.continuous-testing=enabled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.acme;
2+
3+
import static io.restassured.RestAssured.given;
4+
import static org.hamcrest.CoreMatchers.is;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import io.quarkus.test.junit.QuarkusTest;
9+
10+
@QuarkusTest
11+
public class HelloResourceTest {
12+
13+
@Test
14+
public void testHelloEndpoint() {
15+
given()
16+
.when().get("/app/hello")
17+
.then()
18+
.statusCode(200)
19+
.body(is("hello"));
20+
}
21+
}

0 commit comments

Comments
 (0)