Skip to content

Commit

Permalink
Allow empty configuration values for String injection points
Browse files Browse the repository at this point in the history
Fixes #2765
  • Loading branch information
geoand committed Jun 9, 2019
1 parent 66f9b36 commit 33c3485
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.quarkus.arc.runtime;

import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
Expand All @@ -39,6 +40,7 @@ public void validateConfigProperties(Map<String, Set<String>> properties) {
if (cl == null) {
ConfigDeploymentTemplate.class.getClassLoader();
}
Set<String> allPropertyNames = new HashSet<>();
for (Entry<String, Set<String>> entry : properties.entrySet()) {
Set<String> propertyTypes = entry.getValue();
for (String propertyType : propertyTypes) {
Expand All @@ -49,8 +51,21 @@ public void validateConfigProperties(Map<String, Set<String>> properties) {
}
try {
if (!config.getOptionalValue(entry.getKey(), propertyClass).isPresent()) {
throw new DeploymentException(
"No config value of type " + entry.getValue() + " exists for: " + entry.getKey());

if (allPropertyNames.isEmpty()) {
final Iterable<String> propertyNamesIter = config.getPropertyNames();
for (String propertyName : propertyNamesIter) {
allPropertyNames.add(propertyName);
}
}

// getOptionalValue returns an empty Optional when the string value is an empty string
// this should not be considered an error
if (!(String.class.equals(propertyClass) && allPropertyNames.contains(entry.getKey()))) {
throw new DeploymentException(
"No config value of type " + entry.getValue() + " exists for: " + entry.getKey());
}

}
} catch (IllegalArgumentException e) {
throw new DeploymentException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.List;
import java.util.Map;

import javax.servlet.Servlet;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
Expand Down Expand Up @@ -82,4 +80,4 @@ public String getEffectiveServletName(final String key) {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class MicroProfileConfigResource {
@Inject
Config config;

@ConfigProperty(name = "greeting.empty")
String empty;

@GET
@Path("/get-property-names")
public String getPropertyNames() throws Exception {
Expand All @@ -52,4 +55,10 @@ public String getPropertyNames() throws Exception {
public String getCustomValue() {
return Integer.toString(value.getNumber());
}

@GET
@Path("/empty")
public String empty() {
return empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ quarkus.log.category.\"org.apache.zookeeper\".level=WARN

microprofile.custom.value = 456

quarkus.swagger-ui.always-include=true
quarkus.swagger-ui.always-include=true

greeting.empty=
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ public void testMicroprofileConfigGetCustomValue() {
.when().get("/microprofile-config/get-custom-value")
.then().body(is("456"));
}

@Test
public void testEmptyStringValue() {
RestAssured
.when().get("/microprofile-config/empty")
.then().body(is(""));
}
}

0 comments on commit 33c3485

Please sign in to comment.