From 3b90588c369a4c830f71dbb84fce1d7c272c4d9e Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Sun, 14 Apr 2019 18:35:36 +0300 Subject: [PATCH] Allow injection of config properties into test with @Inject Fixes: #2061 --- .../deployment/ArcTestResourceProvider.java | 4 +++- .../it/main/PropertyInjectionTestCase.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 integration-tests/main/src/test/java/io/quarkus/it/main/PropertyInjectionTestCase.java diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcTestResourceProvider.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcTestResourceProvider.java index 19dfc408a46bc..6f899598d8c94 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcTestResourceProvider.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcTestResourceProvider.java @@ -9,6 +9,8 @@ import javax.inject.Inject; import javax.inject.Qualifier; +import org.eclipse.microprofile.config.inject.ConfigProperty; + import io.quarkus.arc.Arc; import io.quarkus.arc.CurrentInjectionPointProvider.InjectionPointImpl; import io.quarkus.deployment.test.TestResourceProvider; @@ -21,7 +23,7 @@ public void inject(Object test) { BeanManager beanManager = Arc.container().beanManager(); while (c != Object.class) { for (Field field : c.getDeclaredFields()) { - if (field.isAnnotationPresent(Inject.class)) { + if (field.isAnnotationPresent(Inject.class) || field.isAnnotationPresent(ConfigProperty.class)) { try { Set qualifiers = new HashSet<>(); Set annotations = new HashSet<>(); diff --git a/integration-tests/main/src/test/java/io/quarkus/it/main/PropertyInjectionTestCase.java b/integration-tests/main/src/test/java/io/quarkus/it/main/PropertyInjectionTestCase.java new file mode 100644 index 0000000000000..ec9ef88ac6d8d --- /dev/null +++ b/integration-tests/main/src/test/java/io/quarkus/it/main/PropertyInjectionTestCase.java @@ -0,0 +1,19 @@ +package io.quarkus.it.main; + +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +class PropertyInjectionTestCase { + + @ConfigProperty(name = "web-message") + String message; + + @Test + void testConfigPropertyInjectedIntoTest() { + Assertions.assertEquals("A message", message); + } +}