Skip to content

Commit 2964bf4

Browse files
Merge pull request quarkusio#48129 from holly-cummins/lessen-reliance-on-junit-properties
Tolerate junit-platform.properties in user code
2 parents 55d17c1 + 6dea9ab commit 2964bf4

File tree

20 files changed

+535
-38
lines changed

20 files changed

+535
-38
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
id 'java'
3+
id 'io.quarkus'
4+
id 'application'
5+
}
6+
7+
repositories {
8+
mavenLocal {
9+
content {
10+
includeGroupByRegex 'io.quarkus.*'
11+
includeGroup 'org.hibernate.orm'
12+
}
13+
}
14+
mavenCentral()
15+
}
16+
17+
dependencies {
18+
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
19+
implementation 'io.quarkus:quarkus-resteasy'
20+
21+
testImplementation 'io.quarkus:quarkus-junit5'
22+
testImplementation 'io.rest-assured:rest-assured'
23+
}
24+
25+
compileJava {
26+
options.compilerArgs << '-parameters'
27+
}
28+
29+
30+
run {
31+
// propagate the custom local maven repo, in case it's configured
32+
if (System.properties.containsKey('maven.repo.local')) {
33+
systemProperty 'maven.repo.local', System.properties.get('maven.repo.local')
34+
}
35+
}
36+
37+
test {
38+
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
39+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
quarkusPluginVersion=${project.version}
2+
quarkusPlatformArtifactId=quarkus-bom
3+
quarkusPluginId=io.quarkus
4+
quarkusPlatformGroupId=io.quarkus
5+
quarkusPlatformVersion=${project.version}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pluginManagement {
2+
repositories {
3+
mavenCentral()
4+
gradlePluginPortal()
5+
mavenLocal()
6+
}
7+
plugins {
8+
id "${quarkusPluginId}" version "${quarkusPluginVersion}"
9+
}
10+
}
11+
rootProject.name='code-with-quarkus'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 GreetingResource {
10+
11+
@GET
12+
@Produces(MediaType.TEXT_PLAIN)
13+
public String hello() {
14+
return "Hello from Quarkus REST";
15+
}
16+
}

integration-tests/gradle/src/main/resources/with-junit-properties-file/src/main/resources/junit-platform.properties

Whitespace-only changes.
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+
class GreetingResourceTest {
12+
@Test
13+
void testHelloEndpoint() {
14+
given()
15+
.when().get("/hello")
16+
.then()
17+
.statusCode(200)
18+
.body(is("Hello from Quarkus REST"));
19+
}
20+
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.quarkus.gradle;
2+
3+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
4+
5+
import java.io.File;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
public class TestWithAppJunitPropertiesFileTest extends QuarkusGradleWrapperTestBase {
10+
11+
@Test
12+
public void shouldRunTestsSuccessfully() throws Exception {
13+
14+
final File projectDir = getProjectDir("with-junit-properties-file");
15+
16+
BuildResult buildResult = runGradleWrapper(projectDir, "test");
17+
18+
assertThat(BuildResult.isSuccessful(buildResult.getTasks().get(":test"))).isTrue();
19+
20+
}
21+
}

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
@@ -229,4 +229,40 @@ public void testQuarkusTestWithConfigInTestProfile()
229229
assertThat(installInvocation.getExitCode()).isEqualTo(0);
230230

231231
}
232+
233+
/*
234+
* This should perhaps be in a different project, see https://github.com/quarkusio/quarkus/issues/46667
235+
*/ @Test
236+
public void testQuarkusTestInProjectWithJUnitProperties()
237+
throws MavenInvocationException, InterruptedException {
238+
String sourceDir = "projects/test-tests-in-project-with-junit-properties-file";
239+
testDir = initProject(sourceDir, sourceDir + "-processed");
240+
RunningInvoker invoker = new RunningInvoker(testDir, false);
241+
242+
MavenProcessInvocationResult installInvocation = invoker.execute(
243+
List.of("clean", "verify", "-Dquarkus.analytics.disabled=true"),
244+
Collections.emptyMap());
245+
assertThat(installInvocation.getProcess().waitFor(2, TimeUnit.MINUTES)).isTrue();
246+
assertThat(installInvocation.getExecutionException()).isNull();
247+
assertThat(installInvocation.getExitCode()).isEqualTo(0);
248+
249+
}
250+
251+
@Test
252+
public void testQuarkusTestInProjectWithJUnitPropertiesContinuousTesting()
253+
throws MavenInvocationException, FileNotFoundException {
254+
// This test will fail if the test extension does not reset the TCCL properly
255+
String sourceDir = "projects/test-tests-in-project-with-junit-properties-file";
256+
testDir = initProject(sourceDir, sourceDir + "-processed-devmode");
257+
258+
runAndCheck();
259+
260+
ContinuousTestingMavenTestUtils testingTestUtils = new ContinuousTestingMavenTestUtils(getPort());
261+
ContinuousTestingMavenTestUtils.TestStatus results = testingTestUtils.waitForNextCompletion();
262+
// This is a bit brittle when we add tests, but failures are often so catastrophic they're not even reported as failures,
263+
// so we need to check the pass count explicitly
264+
Assertions.assertEquals(0, results.getTestsFailed());
265+
Assertions.assertEquals(1, results.getTestsPassed());
266+
Assertions.assertEquals(0, results.getTestsSkipped());
267+
}
232268
}
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-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-rest</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,22 @@
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+
import org.eclipse.microprofile.config.ConfigProvider;
9+
10+
@Path("/hello")
11+
public class HelloResource {
12+
13+
@GET
14+
@Produces(MediaType.TEXT_PLAIN)
15+
public String hello() {
16+
// This config access only works if the TCCL is set properly
17+
String message = ConfigProvider.getConfig().getValue("greeting.message", String.class);
18+
return message;
19+
20+
}
21+
22+
}

0 commit comments

Comments
 (0)