forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt locales support for GraalVM >= 24.2
Starting with GraalVM for JDK 24 (24.2) native image will no longer set the locale default at build time. As a result, the default locale won't be included by default in the native image unless explicitly specified. See oracle/graal#9694
- Loading branch information
Showing
18 changed files
with
273 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-integration-test-locales-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>quarkus-integration-test-locales-default</artifactId> | ||
<name>Quarkus - Integration Tests - Locales - Default</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-validator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-integration-test-locales-app</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-validator-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/test/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<forkCount>1</forkCount> | ||
<reuseForks>false</reuseForks> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
26 changes: 26 additions & 0 deletions
26
...tion-tests/locales/default/src/main/java/io/quarkus/locales/it/DefaultLocaleResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.locales.it; | ||
|
||
import jakarta.validation.constraints.Pattern; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
@Path("") | ||
public class DefaultLocaleResource extends LocalesResource { | ||
private static final Logger LOG = Logger.getLogger(DefaultLocaleResource.class); | ||
|
||
// @Pattern validation does nothing when placed in LocalesResource. | ||
@GET | ||
@Path("/hibernate-validator-test-validation-message-locale/{id}/") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Response validationMessageLocale( | ||
@Pattern(regexp = "A.*", message = "{pattern.message}") @PathParam("id") String id) { | ||
LOG.infof("Triggering test: id: %s", id); | ||
return Response.ok(id).build(); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
integration-tests/locales/default/src/test/java/io/quarkus/locales/it/LocalesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package io.quarkus.locales.it; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.jboss.logging.Logger; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import io.quarkus.test.junit.DisableIfBuiltWithGraalVMNewerThan; | ||
import io.quarkus.test.junit.DisableIfBuiltWithGraalVMOlderThan; | ||
import io.quarkus.test.junit.GraalVMVersion; | ||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import io.restassured.RestAssured; | ||
|
||
/** | ||
* For the Native test cases to function, the operating system has to have locales support installed. A barebone system with | ||
* only C.UTF-8 default locale available won't be able to pass the tests. | ||
* <p> | ||
* For example, this package satisfies the dependency on a RHEL 9 type of OS: glibc-all-langpacks | ||
*/ | ||
@QuarkusIntegrationTest | ||
public class LocalesIT { | ||
|
||
private static final Logger LOG = Logger.getLogger(LocalesIT.class); | ||
|
||
@Test | ||
@DisableIfBuiltWithGraalVMNewerThan(value = GraalVMVersion.GRAALVM_24_1_0) | ||
public void testDefaultLocaleBefore24_2() { | ||
RestAssured.given().when() | ||
.get("/default/de-CH") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
/* | ||
* "l-Iżvizzera" is the correct name for Switzerland in Maltese language. | ||
* Maltese is the default language as per quarkus.default-locale=mt-MT. | ||
*/ | ||
.body(is("l-Iżvizzera")) | ||
.log().all(); | ||
} | ||
|
||
@Test | ||
@DisableIfBuiltWithGraalVMOlderThan(value = GraalVMVersion.GRAALVM_24_2_0) | ||
public void testDefaultLocaleAfter24_1() { | ||
RestAssured.given().when() | ||
.get("/default/de-CH") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
/* | ||
* "l-Iżvizzera" is the correct name for Switzerland in Maltese language. | ||
* Maltese is the default build-time language as per quarkus.default-locale=mt-MT, but not at run-time. | ||
* Note that this test will fail if the default run-time language is Maltese on the test machine, | ||
* this is unfortunate but also unlikely given the small population of Malta. | ||
*/ | ||
.body(not("l-Iżvizzera")) | ||
.log().all(); | ||
} | ||
|
||
/** | ||
* @see integration-tests/hibernate-validator/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java | ||
*/ | ||
@ParameterizedTest | ||
@CsvSource(value = { | ||
// French locale is included, so it's used, because Croatian locale is not included | ||
// and thus its property file ValidationMessages_hr_HR.properties is ignored. | ||
"en-US;q=0.25,hr-HR;q=0.9,fr-FR;q=0.5,uk-UA;q=0.1|La valeur ne correspond pas à l'échantillon", | ||
// Silent fallback to lingua franca. | ||
"invalid string|Value is not in line with the pattern", | ||
// French locale is available and included. | ||
"en-US;q=0.25,hr-HR;q=1,fr-FR;q=0.5|La valeur ne correspond pas à l'échantillon" | ||
}, delimiter = '|') | ||
public void testValidationMessageLocale(String acceptLanguage, String expectedMessage) { | ||
RestAssured.given() | ||
.header("Accept-Language", acceptLanguage) | ||
.when() | ||
.get("/hibernate-validator-test-validation-message-locale/1") | ||
.then() | ||
.body(containsString(expectedMessage)); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
integration-tests/locales/default/src/test/java/io/quarkus/locales/it/LocalesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.quarkus.locales.it; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class LocalesTest { | ||
} |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/default/src/test/resources/ValidationMessages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pattern.message=Value is not in line with the pattern |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/default/src/test/resources/ValidationMessages_fr_FR.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pattern.message=La valeur ne correspond pas à l'échantillon |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/default/src/test/resources/ValidationMessages_hr_HR.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pattern.message=Vrijednost ne zadovoljava uzorak |
4 changes: 4 additions & 0 deletions
4
integration-tests/locales/default/src/test/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
quarkus.locales=de,fr-FR,ja,uk-UA | ||
# Note that quarkus.native.user-language is deprecated and solely quarkus.default-locale should be | ||
# used in your application properties. This test uses it only to verify compatibility. | ||
quarkus.default-locale=mt-MT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters