Skip to content

Commit

Permalink
Add coverage to inject maps using the @ConfigProperty annotation (#241)
Browse files Browse the repository at this point in the history
This use case is now possible thanks to quarkusio/quarkus#17269.
  • Loading branch information
Sgitario authored Jul 20, 2021
1 parent b9f6cbf commit e171e2c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
2 changes: 2 additions & 0 deletions 022-quarkus-properties-config-all/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ supported classes (e.x. String, Boolean, Double, etc.)

7. Injecting properties using the `@ConfigMapping` annotation. More info in: https://smallrye.io/docs/smallrye-config/mapping/mapping.html

8. Injecting a map using the `@ConfigProperty` annotation. More info in: https://github.com/quarkusio/quarkus/issues/17269

___
#### Wiki:
**Protagonist**: the leading character in the story, whose purpose is to move story to its final
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.quarkus.qe.bulk;

import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import org.eclipse.microprofile.config.inject.ConfigProperty;

@Path("/bind-maps-using-config-value")
public class BindMapsUsingConfigValueResource {

@ConfigProperty(name = "maps.labels")
Map<String, String> labels;

@ConfigProperty(name = "maps.numbers")
Map<Integer, Integer> numbers;

@GET
@Path("/labels/{label}")
public String getLabel(@PathParam("label") String label) {
return labels.get(label);
}

@GET
@Path("/numbers/{number}")
public Integer getNumber(@PathParam("number") Integer number) {
return numbers.get(number);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ person.labels.B=Label 2

# Overridden Person
overrides.person.name=Karen
overrides.person.age=23
overrides.person.age=23

# Maps
maps.labels.A=X
maps.labels.B=Y

maps.numbers.1=1
maps.numbers.2=2
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkus.qe.bulk;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

import org.apache.http.HttpStatus;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class BindMapsUsingConfigValueTest {

@Test
public void shouldInjectMapsWithStringAsKeyIntoConfigValue() {
assertResponseIs("/labels/A", "X");
assertResponseIs("/labels/B", "Y");
}

@Test
public void shouldInjectMapsWithIntegerAsKeyIntoConfigValue() {
assertResponseIs("/numbers/1", "1");
assertResponseIs("/numbers/2", "2");
}

private <T> void assertResponseIs(String path, T expected) {
assertResponse(path, is(expected.toString()));
}

private void assertResponse(String path, Matcher<String> matcher) {
given().when().get("/bind-maps-using-config-value" + path)
.then().statusCode(HttpStatus.SC_OK)
.body(matcher);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.qe.bulk;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeBindMapsUsingConfigValueIT extends BindMapsUsingConfigValueTest {
}

0 comments on commit e171e2c

Please sign in to comment.