Skip to content

Commit

Permalink
Merge pull request #26781 from radcortez/srconfig-2110
Browse files Browse the repository at this point in the history
Update SmallRye Config to 2.11.0
  • Loading branch information
gsmet committed Jul 19, 2022
2 parents 173a975 + 280b478 commit 8db6af3
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<microprofile-jwt.version>1.2</microprofile-jwt.version>
<microprofile-lra.version>1.0</microprofile-lra.version>
<smallrye-common.version>1.13.0</smallrye-common.version>
<smallrye-config.version>2.10.1</smallrye-config.version>
<smallrye-config.version>2.11.0</smallrye-config.version>
<smallrye-health.version>3.2.1</smallrye-health.version>
<smallrye-metrics.version>3.0.5</smallrye-metrics.version>
<smallrye-open-api.version>2.1.22</smallrye-open-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ public interface AppConfig {

Info info();

String toString();

interface Info {
@WithDefault("alias")
String alias();

@WithDefault("10")
Integer count();

String toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ public String getName() {
public String getAlias() {
return appConfig.info().alias();
}

@GET
@Path("/toString")
public String getToString() {
return appConfig.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public Response configValue(@PathParam("name") final String name) {
return Response.ok(config.getConfigValue(name)).build();
}

@GET
@Path("/profiles")
public Response profiles() {
return Response.ok(config.getProfiles()).build();
}

@RegisterForReflection(targets = {
org.eclipse.microprofile.config.ConfigValue.class,
io.smallrye.config.ConfigValue.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ interface Info {
Optional<List<@Size(max = 3) String>> alias();

@JsonProperty
Map<String, Admin> admins();
Map<String, List<Admin>> admins();

@JsonProperty
Map<String, List<@Size(min = 8, max = 15) String>> firewall();

interface Admin {
@JsonProperty
@Size(max = 3)
@Size(max = 4)
String username();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ smallrye.config.locations=config.properties
smallrye.config.source.file.locations=src/main/smallrye-config-source-file-system

# parent profile
%prod.quarkus.config.profile.parent=common
%test.quarkus.config.profile.parent=common
%dev.quarkus.config.profile.parent=common
%prod.quarkus.config.profile.parent=parent-common,common
%test.quarkus.config.profile.parent=parent-common,common
%dev.quarkus.config.profile.parent=parent-common,common

%parent-common.parent.common.prop=parent-common

%common.profile.property.shared=common
%test.profile.property.shared=main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ cloud:
- James
admins:
root:
username: root
-
username: root
-
username: super
firewall:
accepted:
- 127.0.0.1
- 8.8.8

profile:
main:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.it.smallrye.config;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class AppConfigIT extends AppConfigTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.it.smallrye.config;

import static io.restassured.RestAssured.given;
import static javax.ws.rs.core.Response.Status.OK;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class AppConfigTest {
@Test
void getToString() {
given()
.get("/app-config/toString")
.then()
.statusCode(OK.getStatusCode())
.body(is("AppConfig{name=app, info=Info{count=10, alias=alias}}"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ void invalid() {
given().get("/server/validator/{prefix}", "cloud")
.then()
.statusCode(OK.getStatusCode())
.body("errors", hasSize(7))
.body("errors", hasSize(8))
.body("errors", hasItem("cloud.log.days must be less than or equal to 15"))
.body("errors", hasItem("cloud.cors.origins[1].port must be greater than or equal to 8000"))
.body("errors", hasItem("cloud.info.name size must be between 0 and 3"))
.body("errors", hasItem("cloud.info.code must be less than or equal to 3"))
.body("errors", hasItem("cloud.info.alias[0] size must be between 0 and 3"))
.body("errors", hasItem("cloud.info.admins.root.username size must be between 0 and 3"))
.body("errors", hasItem("cloud.info.admins.root[1].username size must be between 0 and 4"))
.body("errors", hasItem("cloud.info.firewall.accepted[1] size must be between 8 and 15"))
.body("errors", hasItem("cloud.proxy.timeout must be less than or equal to 10"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.restassured.RestAssured.given;
import static javax.ws.rs.core.Response.Status.OK;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -98,4 +99,19 @@ void userConfig() {
.body("value", equalTo("1234"))
.body("sourceName", equalTo("UserConfigSource"));
}

@Test
void profiles() {
given()
.get("/config/profiles")
.then()
.statusCode(OK.getStatusCode())
.body(containsString("parent-common"));

given()
.get("/config/{name}", "parent.common.prop")
.then()
.statusCode(OK.getStatusCode())
.body("value", equalTo("parent-common"));
}
}

0 comments on commit 8db6af3

Please sign in to comment.