-
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.
- Loading branch information
Showing
22 changed files
with
472 additions
and
88 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
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> |
7 changes: 7 additions & 0 deletions
7
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,7 @@ | ||
package io.quarkus.locales.it; | ||
|
||
import jakarta.ws.rs.Path; | ||
|
||
@Path("") | ||
public class AllLocalesResource extends LocalesResource { | ||
} |
114 changes: 114 additions & 0 deletions
114
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,114 @@ | ||
package io.quarkus.locales.it; | ||
|
||
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.ValueSource; | ||
|
||
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 | ||
@ValueSource(strings = { | ||
"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" | ||
}) | ||
public void testCorrectLocales(String countryLanguageTranslation) { | ||
final String[] lct = countryLanguageTranslation.split("\\|"); | ||
LOG.infof("Triggering test: Country: %s, Language: %s, Translation: %s", lct[0], lct[1], lct[2]); | ||
RestAssured.given().when() | ||
.get(String.format("/locale/%s/%s", lct[0], lct[1])) | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is(lct[2])) | ||
.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 | ||
|
||
@ValueSource(strings = { | ||
"0,666|en-US|666.0", | ||
"0,666|cs-CZ|0.666", | ||
"0,666|fr-FR|0.666", | ||
"0.666|fr-FR|0.0" | ||
}) | ||
public void testNumbers(String zoneLanguageName) { | ||
final String[] nlr = zoneLanguageName.split("\\|"); | ||
LOG.infof("Triggering test: Number: %s, Locale: %s, Expected result: %s", nlr[0], nlr[1], nlr[2]); | ||
RestAssured.given().when() | ||
.param("number", nlr[0]) | ||
.param("locale", nlr[1]) | ||
.get("/numbers") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(equalTo(nlr[2])) | ||
.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(); | ||
} | ||
|
||
@Test | ||
public void message() { | ||
// Ukrainian language preference is higher than Czech. | ||
RestAssured.given().when() | ||
.header("Accept-Language", "cs;q=0.7,uk;q=0.9") | ||
.get("/message") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is("Привіт Світ!")) | ||
.log().all(); | ||
// Czech language preference is higher than Ukrainian. | ||
RestAssured.given().when() | ||
.header("Accept-Language", "cs;q=1.0,uk;q=0.9") | ||
.get("/message") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is("Ahoj světe!")) | ||
.log().all(); | ||
// An unknown language preference, silent fallback to lingua franca. | ||
RestAssured.given().when() | ||
.header("Accept-Language", "jp;q=1.0") | ||
.get("/message") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.body(is("Hello world!")) | ||
.log().all(); | ||
} | ||
} |
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=Привіт Світ! |
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 |
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,52 @@ | ||
<?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-app</artifactId> | ||
<name>Quarkus - Integration Tests - Locales - App</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive</artifactId> | ||
</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> | ||
</project> |
Oops, something went wrong.