-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage to inject maps using the @ConfigProperty annotation (#241)
This use case is now possible thanks to quarkusio/quarkus#17269.
- Loading branch information
Showing
5 changed files
with
84 additions
and
1 deletion.
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
31 changes: 31 additions & 0 deletions
31
...perties-config-all/src/main/java/io/quarkus/qe/bulk/BindMapsUsingConfigValueResource.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,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); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...-properties-config-all/src/test/java/io/quarkus/qe/bulk/BindMapsUsingConfigValueTest.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,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); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...perties-config-all/src/test/java/io/quarkus/qe/bulk/NativeBindMapsUsingConfigValueIT.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.qe.bulk; | ||
|
||
import io.quarkus.test.junit.NativeImageTest; | ||
|
||
@NativeImageTest | ||
public class NativeBindMapsUsingConfigValueIT extends BindMapsUsingConfigValueTest { | ||
} |