Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class ORMReactiveCompatbilityDefaultBothUnitTest extends CompatibilityUni
.setForcedDependencies(List.of(
Dependency.of("io.quarkus", "quarkus-jdbc-postgresql-deployment", Version.getVersion()) // this triggers Agroal
))
.withConfigurationResource("application-unittest-both.properties")
.overrideConfigKey("quarkus.hibernate-orm.schema-management.strategy", SCHEMA_MANAGEMENT_STRATEGY)
.overrideConfigKey("quarkus.datasource.reactive", "true")
.overrideConfigKey("quarkus.datasource.db-kind", POSTGRES_KIND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class ORMReactiveCompatbilityDefaultOnlyBlockingUnitTest extends Compatib
.setForcedDependencies(List.of(
Dependency.of("io.quarkus", "quarkus-jdbc-postgresql-deployment", Version.getVersion()) // this triggers Agroal
))
.withConfigurationResource("application-unittest-onlyblocking.properties")
.overrideConfigKey("quarkus.hibernate-orm.schema-management.strategy", SCHEMA_MANAGEMENT_STRATEGY)
.overrideConfigKey("quarkus.datasource.reactive", "false")
.overrideConfigKey("quarkus.datasource.db-kind", POSTGRES_KIND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class ORMReactiveCompatbilityDefaultOnlyReactiveDisabledBlockingSessionUn
.addAsResource("complexMultilineImports.sql", "import.sql"))
.setForcedDependencies(List.of(
Dependency.of("io.quarkus", "quarkus-jdbc-postgresql-deployment", Version.getVersion())))
.withConfigurationResource("application-unittest-onlyreactive.properties")
.overrideConfigKey("quarkus.hibernate-orm.schema-management.strategy", SCHEMA_MANAGEMENT_STRATEGY)
.overrideConfigKey("quarkus.hibernate-orm.blocking", "false")
.overrideConfigKey("quarkus.datasource.reactive", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class ORMReactiveCompatbilityDefaultOnlyReactiveUnitTest extends Compatib
.withApplicationRoot((jar) -> jar
.addClasses(Hero.class)
.addAsResource("complexMultilineImports.sql", "import.sql"))
.withConfigurationResource("application-unittest-onlyreactive.properties")
.overrideConfigKey("quarkus.hibernate-orm.schema-management.strategy", SCHEMA_MANAGEMENT_STRATEGY)
.overrideConfigKey("quarkus.datasource.reactive", "true")
.overrideConfigKey("quarkus.datasource.db-kind", POSTGRES_KIND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class ORMReactiveCompatbilityNamedDataSourceBothUnitTest extends Compatib
.setForcedDependencies(List.of(
Dependency.of("io.quarkus", "quarkus-jdbc-postgresql-deployment", Version.getVersion()) // this triggers Agroal
))
.withConfigurationResource("application-unittest-both-named.properties")
.overrideConfigKey("quarkus.hibernate-orm.schema-management.strategy", SCHEMA_MANAGEMENT_STRATEGY)
.overrideConfigKey("quarkus.hibernate-orm.datasource", "named-datasource")
.overrideConfigKey("quarkus.datasource.\"named-datasource\".reactive", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class ORMReactiveCompatbilityNamedDataSourceNamedPersistenceUnitBothUnitT
.setForcedDependencies(List.of(
Dependency.of("io.quarkus", "quarkus-jdbc-postgresql-deployment", Version.getVersion()) // this triggers Agroal
))
.withConfigurationResource("application-unittest-both-named.properties")
.overrideConfigKey("quarkus.hibernate-orm.\"named-pu\".schema-management.strategy", SCHEMA_MANAGEMENT_STRATEGY)
.overrideConfigKey("quarkus.hibernate-orm.\"named-pu\".datasource", "named-datasource")
.overrideConfigKey("quarkus.hibernate-orm.\"named-pu\".packages", "io.quarkus.hibernate.reactive.entities")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class ORMReactiveCompatbilityNamedDataSourceReactiveUnitTest extends Comp
.withApplicationRoot((jar) -> jar
.addClasses(Hero.class)
.addAsResource("complexMultilineImports.sql", "import.sql"))
.withConfigurationResource("application-unittest-onlyreactive-named.properties")
.overrideConfigKey("quarkus.hibernate-orm.schema-management.strategy", SCHEMA_MANAGEMENT_STRATEGY)
.overrideConfigKey("quarkus.hibernate-orm.datasource", "named-datasource")
.overrideConfigKey("quarkus.datasource.\"named-datasource\".reactive", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class ORMReactiveCompatbilityOnlyReactiveJDBCDisabledUnitTest extends Com
.addAsResource("complexMultilineImports.sql", "import.sql"))
.setForcedDependencies(List.of(
Dependency.of("io.quarkus", "quarkus-jdbc-postgresql-deployment", Version.getVersion())))
.withConfigurationResource("application-unittest-onlyreactive.properties")
.overrideConfigKey("quarkus.hibernate-orm.schema-management.strategy", SCHEMA_MANAGEMENT_STRATEGY)
.overrideConfigKey("quarkus.datasource.jdbc", "false")
.overrideConfigKey("quarkus.datasource.reactive", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class ORMReactiveCompatibilityNamedReactiveDefaultBlockingUnitTest extend
.setForcedDependencies(List.of(
Dependency.of("io.quarkus", "quarkus-jdbc-postgresql-deployment", Version.getVersion()) // this triggers Agroal
))
.withConfigurationResource("application-unittest-both-named-reactive-and-default-blocking.properties")
// If we want the named PU to be reactive only we need to explicitly disable the blocking the JDBC data source
.overrideConfigKey("quarkus.datasource.\"named-datasource\".jdbc", "false")
.overrideConfigKey("quarkus.datasource.\"named-datasource\".reactive", "true")
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions test-framework/junit5-internal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-common</artifactId>
</dependency>
<dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum... I'm not sure whether we should include arc here. What is the reason?

Copy link
Author

@mathias82 mathias82 Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the question!

In this test QuarkusUnitTestWithRuntimeConfigurationTest I explicitly added the arc dependency because the class uses Quarkus Arc annotations:

import io.quarkus.arc.Unremovable;
import jakarta.inject.Singleton;

These annotations are part of the Arc CDI implementation, not part of the quarkus-test-common artifact. Without including arc, the test fails to compile because the Arc annotation types are not available on the classpath during the test scope.

In other words, Arc is required here to correctly load and process the CDI metadata used in this test. If we remove arc, the test breaks.

If you believe there is another recommended dependency that exposes these annotations without pulling the whole Arc module, I'm happy to revisit it, but currently this is the minimal dependency that makes the test compile and run.

<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,67 @@ public QuarkusUnitTest withConfigurationResource(String resourceName) {
return this;
}

/**
* Adds configuration properties using a text block with "key=value" lines.
* Blank lines and lines starting with '#' are ignored.
*
* Example:
* .withConfiguration("""
* quarkus.datasource.db-kind=postgresql
* quarkus.datasource.username=user
* quarkus.datasource.password=pass
* """)
*
* @param configBlock text block with configuration lines
* @return self
*/
public QuarkusUnitTest withConfiguration(String configBlock) {
Objects.requireNonNull(configBlock, "Configuration text block must not be null");

configBlock.lines()
.map(String::trim)
.filter(line -> !line.isEmpty() && !line.startsWith("#"))
.forEach(line -> {
int idx = line.indexOf('=');
if (idx <= 0) {
throw new IllegalArgumentException(
"Invalid configuration line: '" + line + "'. Expected format 'key=value'");
}
String key = line.substring(0, idx).trim();
String value = line.substring(idx + 1).trim();
overrideConfigKey(key, value);
});

return this;
}

/**
* Adds runtime configuration properties using a text block with "key=value" lines.
* Blank lines and lines starting with '#' are ignored.
*
* @param configBlock text block with configuration lines
* @return self
*/
public QuarkusUnitTest withRuntimeConfiguration(String configBlock) {
Objects.requireNonNull(configBlock, "Configuration text block must not be null");

configBlock.lines()
.map(String::trim)
.filter(line -> !line.isEmpty() && !line.startsWith("#"))
.forEach(line -> {
int idx = line.indexOf('=');
if (idx <= 0) {
throw new IllegalArgumentException(
"Invalid configuration line: '" + line + "'. Expected format 'key=value'");
}
String key = line.substring(0, idx).trim();
String value = line.substring(idx + 1).trim();
overrideRuntimeConfigKey(key, value);
});

return this;
}

/**
* Overriden configuration properties take precedence over an {@code application.properties} asset added in the test
* {@link JavaArchive}.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class QuarkusUnitTestWithConfigurationTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withConfiguration("""
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=quarkus
quarkus.datasource.password=quarkus
""");

@Test
public void testInlineConfigurationApplied() {
Config cfg = ConfigProvider.getConfig();

assertEquals("postgresql", cfg.getValue("quarkus.datasource.db-kind", String.class));
assertEquals("quarkus", cfg.getValue("quarkus.datasource.username", String.class));
assertEquals("quarkus", cfg.getValue("quarkus.datasource.password", String.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.quarkus.test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import jakarta.inject.Singleton;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.arc.Unremovable;

@Singleton
@Unremovable
public class QuarkusUnitTestWithRuntimeConfigurationTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withRuntimeConfiguration("""
test.inline.runtime=value
quarkus.log.category.test.category.level=DEBUG
""");

@Test
public void testInlineConfigurationApplied() {
Config cfg = ConfigProvider.getConfig();

assertEquals("value", cfg.getValue("test.inline.runtime", String.class));
assertEquals("DEBUG", cfg.getValue("quarkus.log.category.test.category.level", String.class));
}
}