-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hibernate validator interprets Locale.ROOT as array of all Fixes hibernate-validator for quarkus.locales=all
- Loading branch information
Showing
31 changed files
with
649 additions
and
167 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,16 @@ | ||
Locales (i18n) | ||
============== | ||
|
||
Native-image built application does not have all [locales](https://docs.oracle.com/javase/tutorial/i18n/locale/index.html) included by default as it | ||
unnecessarily inflates the executable size. | ||
|
||
One can configure native-image to [include locales](https://www.graalvm.org/latest/reference-manual/native-image/dynamic-features/Resources/#locales). This is mirrored in Quarkus configuration. | ||
|
||
All | ||
--- | ||
"All" test uses a special string "all" that internally translates as Locale.ROOT and is | ||
interpreted as "Include all locales". | ||
|
||
Some | ||
---- | ||
"Some" test uses a list of picked locales and verifies that only those are available. |
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,100 @@ | ||
<?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</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>quarkus-integration-test-locales-all</artifactId> | ||
<name>Quarkus - Integration Tests - Locales - All</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive</artifactId> | ||
</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> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-integration-test-locales-app</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc-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-resteasy-reactive-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
integration-tests/locales/all/src/main/java/io/quarkus/locales/it/AllLocalesResource.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 AllLocalesResource extends LocalesResource { | ||
private static final Logger LOG = Logger.getLogger(AllLocalesResource.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(); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
integration-tests/locales/all/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,128 @@ | ||
package io.quarkus.locales.it; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
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.QuarkusIntegrationTest; | ||
import io.restassured.RestAssured; | ||
|
||
/** | ||
* A special case where we want to include all locales in our app. It must not matter which arbitrary locale we use, it must | ||
* work here. | ||
*/ | ||
@QuarkusIntegrationTest | ||
public class LocalesIT { | ||
|
||
private static final Logger LOG = Logger.getLogger(LocalesIT.class); | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = { | ||
"en-US|en|United States", | ||
"de-DE|de|Deutschland", | ||
"de-AT|en|Austria", | ||
"de-DE|en|Germany", | ||
"zh-cmn-Hans-CN|cs|Čína", | ||
"zh-Hant-TW|cs|Tchaj-wan", | ||
"ja-JP-JP-#u-ca-japanese|sg|Zapöon" | ||
}, delimiter = '|') | ||
public void testCorrectLocales(String country, String language, String translation) { | ||
LOG.infof("Triggering test: Country: %s, Language: %s, Translation: %s", country, language, translation); | ||
RestAssured.given().when() | ||
.get(String.format("/locale/%s/%s", country, language)) | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is(translation)) | ||
.log().all(); | ||
} | ||
|
||
@Test | ||
public void testItalyIncluded() { | ||
RestAssured.given().when() | ||
.get("/locale/it-IT/it") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is("Italia")) | ||
.log().all(); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = { | ||
"0,666|en-US|666.0", | ||
"0,666|cs-CZ|0.666", | ||
"0,666|fr-FR|0.666", | ||
"0.666|fr-FR|0.0" | ||
}, delimiter = '|') | ||
public void testNumbers(String number, String locale, String expected) { | ||
LOG.infof("Triggering test: Number: %s, Locale: %s, Expected result: %s", number, locale, expected); | ||
RestAssured.given().when() | ||
.param("number", number) | ||
.param("locale", locale) | ||
.get("/numbers") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(equalTo(expected)) | ||
.log().all(); | ||
} | ||
|
||
@Test | ||
public void languageRanges() { | ||
RestAssured.given().when() | ||
.param("range", "Accept-Language:iw,en-us;q=0.7,en;q=0.3") | ||
.get("/ranges") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is("[iw, he, en-us;q=0.7, en;q=0.3]")) | ||
.log().all(); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = { | ||
// Ukrainian language preference is higher than Czech. | ||
"cs;q=0.7,uk;q=0.9|Привіт Світ!", | ||
// Czech language preference is higher than Ukrainian. | ||
"cs;q=1.0,uk;q=0.9|Ahoj světe!", | ||
// An unknown language preference, silent fallback to lingua franca. | ||
"jp;q=1.0|Hello world!" | ||
}, delimiter = '|') | ||
public void message(String acceptLanguage, String expectedMessage) { | ||
RestAssured.given().when() | ||
.header("Accept-Language", acceptLanguage) | ||
.get("/message") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is(expectedMessage)) | ||
.log().all(); | ||
} | ||
|
||
/** | ||
* @see integration-tests/hibernate-validator/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java | ||
*/ | ||
@ParameterizedTest | ||
@CsvSource(value = { | ||
// Croatian language preference is higher than Ukrainian. | ||
"en-US;q=0.25,hr-HR;q=0.9,fr-FR;q=0.5,uk-UA;q=0.1|Vrijednost ne zadovoljava uzorak", | ||
// Ukrainian language preference is higher than Croatian. | ||
"en-US;q=0.25,hr-HR;q=0.9,fr-FR;q=0.5,uk-UA;q=1.0|Значення не відповідає зразку", | ||
// An unknown language preference, silent fallback to lingua franca. | ||
"invalid string|Value is not in line with the pattern", | ||
// Croatian language preference is the highest. | ||
"en-US;q=0.25,hr-HR;q=1,fr-FR;q=0.5|Vrijednost ne zadovoljava uzorak", | ||
// Chinese language preference is the highest. | ||
"en-US;q=0.25,hr-HR;q=0.30,zh;q=0.9,fr-FR;q=0.50|數值不符合樣品", | ||
}, 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)); | ||
} | ||
} |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/AppMessages_cs.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 @@ | ||
msg1=Ahoj světe! |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/AppMessages_en.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 @@ | ||
msg1=Hello world! |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/AppMessages_uk.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 @@ | ||
msg1=Привіт Світ! |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/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/all/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 |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/ValidationMessages_uk_UA.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=Значення не відповідає зразку |
1 change: 1 addition & 0 deletions
1
integration-tests/locales/all/src/test/resources/ValidationMessages_zh.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=數值不符合樣品 |
2 changes: 2 additions & 0 deletions
2
integration-tests/locales/all/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,2 @@ | ||
quarkus.locales=all | ||
quarkus.native.resources.includes=AppMessages_*.properties |
Oops, something went wrong.