Skip to content

Commit

Permalink
Get correct map key for config maps of maps, with tests.
Browse files Browse the repository at this point in the history
Fixes #5982
  • Loading branch information
dmlloyd authored and gsmet committed Dec 7, 2019
1 parent 02d5dd3 commit f3d0e8d
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ private Map<String, Object> getMap(MapContainer matched, NameIterator ni) {
ni.previous();
// now the cursor is before our map key and after the enclosing map key
Map<String, Object> map = getMap((MapContainer) parent, ni);
String key = ni.getPreviousSegment();
ni.next();
// cursor restored
String key = ni.getPreviousSegment();
Map<String, Object> instance = getAsMap(map, key);
if (instance == null) {
instance = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.BooleanSupplier;

Expand Down Expand Up @@ -458,6 +459,16 @@ void registerFinalFieldReflectionObject(BuildProducer<ReflectiveClassBuildItem>
classes.produce(finalField);
}

@BuildStep
void checkMapMap(TestBuildAndRunTimeConfig btrt, TestBuildTimeConfig bt, BuildProducer<ReflectiveClassBuildItem> unused) {
if (!Objects.equals("1234", btrt.mapMap.get("outer-key").get("inner-key"))) {
throw new AssertionError("BTRT map map failed");
}
if (!Objects.equals("1234", bt.mapMap.get("outer-key").get("inner-key"))) {
throw new AssertionError("BT map map failed");
}
}

@BuildStep(onlyIf = Never.class)
void neverRunThisOne() {
throw new IllegalStateException("Not supposed to run!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@ quarkus.btrt.my-enums=optional,enum-one,enum-two

### anonymous root property
quarkus.test-property=foo

### map of map of strings
quarkus.rt.map-map.outer-key.inner-key=1234
quarkus.btrt.map-map.outer-key.inner-key=1234
quarkus.bt.map-map.outer-key.inner-key=1234
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,26 @@ public void testConversionUsingConvertWith() {
List<Integer> actualMapValues = new ArrayList<>(configuredBean.getRunTimeConfig().mapOfNumbers.values());
Assertions.assertEquals(mapValues, actualMapValues);
}

@Test
public void testBtrtMapOfMap() {
Map<String, Map<String, String>> mapMap = configuredBean.getBuildTimeConfig().mapMap;
Assertions.assertFalse(mapMap.containsKey("inner-key"));
Assertions.assertTrue(mapMap.containsKey("outer-key"));
Map<String, String> map = mapMap.get("outer-key");
Assertions.assertTrue(map.containsKey("inner-key"));
Assertions.assertFalse(map.containsKey("outer-key"));
Assertions.assertEquals("1234", map.get("inner-key"));
}

@Test
public void testRtMapOfMap() {
Map<String, Map<String, String>> mapMap = configuredBean.getRunTimeConfig().mapMap;
Assertions.assertFalse(mapMap.containsKey("inner-key"));
Assertions.assertTrue(mapMap.containsKey("outer-key"));
Map<String, String> map = mapMap.get("outer-key");
Assertions.assertTrue(map.containsKey("inner-key"));
Assertions.assertFalse(map.containsKey("outer-key"));
Assertions.assertEquals("1234", map.get("inner-key"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.quarkus.extest.runtime.config;

import java.util.Map;

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

/**
*
*/
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED, name = "mm-root")
public class MapMapConfig {
//### map of map of strings
//quarkus.mm-root.map.inner-key.outer-key=1234

Map<String, Map<String, String>> map;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class TestBuildAndRunTimeConfig {
@ConvertWith(WholeNumberConverter.class)
public Map<String, Integer> mapOfNumbers;

public Map<String, Map<String, String>> mapMap;

/**
* Enum object
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.extest.runtime.config;

import java.util.Map;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
Expand All @@ -25,6 +27,8 @@ public class TestBuildTimeConfig {
@ConfigItem
public AllValuesConfig allValues;

public Map<String, Map<String, String>> mapMap;

public TestBuildTimeConfig() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public class TestRunTimeConfig {
@ConvertWith(WholeNumberConverter.class)
public Map<String, Integer> mapOfNumbers;

public Map<String, Map<String, String>> mapMap;

@Override
public String toString() {
return "TestRunTimeConfig{" +
Expand Down

0 comments on commit f3d0e8d

Please sign in to comment.