Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get correct map key for config maps of maps, with tests #5995

Merged
merged 3 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ private boolean isBodyClaimInformationPointDefined(Map<String, Map<String, Strin
for (Map.Entry<String, Map<String, String>> entry : claims.entrySet()) {
Map<String, String> value = entry.getValue();

if (value.get(entry.getKey()).contains("request.body")) {
return true;
for (String nestedValue : value.values()) {
if (nestedValue.contains("request.body")) {
return true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,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