pull/8534/merge
Phillip Webb 8 years ago
parent 6c629369d3
commit 05111a17b8

@ -94,7 +94,8 @@ public class CachePublicMetrics implements PublicMetrics {
} }
private Cache unwrapIfNecessary(Cache cache) { private Cache unwrapIfNecessary(Cache cache) {
if (ClassUtils.isPresent("org.springframework.cache.transaction.TransactionAwareCacheDecorator", if (ClassUtils.isPresent(
"org.springframework.cache.transaction.TransactionAwareCacheDecorator",
getClass().getClassLoader())) { getClass().getClassLoader())) {
return TransactionAwareCacheDecoratorHandler.unwrapIfNecessary(cache); return TransactionAwareCacheDecoratorHandler.unwrapIfNecessary(cache);
} }
@ -154,6 +155,7 @@ public class CachePublicMetrics implements PublicMetrics {
} }
return cache; return cache;
} }
} }
} }

@ -341,7 +341,8 @@ public class ConfigurationPropertiesReportEndpoint
// that's what the metadata generator does. This filter is not used if there // that's what the metadata generator does. This filter is not used if there
// is JSON metadata for the property, so it's mainly for user-defined beans. // is JSON metadata for the property, so it's mainly for user-defined beans.
return (setter != null) return (setter != null)
|| ClassUtils.getPackageName(parentType).equals(ClassUtils.getPackageName(type)) || ClassUtils.getPackageName(parentType)
.equals(ClassUtils.getPackageName(type))
|| Map.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)
|| Collection.class.isAssignableFrom(type); || Collection.class.isAssignableFrom(type);
} }

@ -217,11 +217,9 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> propertiesMap = (Map<String, Object>) nestedProperties Map<String, Object> propertiesMap = (Map<String, Object>) nestedProperties
.get("properties"); .get("properties");
assertThat(propertiesMap).containsOnlyKeys("bar", "name", "map", "list"); assertThat(propertiesMap).containsOnlyKeys("bar", "name", "map", "list");
Map<String, Object> map = (Map<String, Object>) propertiesMap Map<String, Object> map = (Map<String, Object>) propertiesMap.get("map");
.get("map");
assertThat(map).containsOnly(entry("entryOne", true)); assertThat(map).containsOnly(entry("entryOne", true));
List<String> list = (List<String>) propertiesMap List<String> list = (List<String>) propertiesMap.get("list");
.get("list");
assertThat(list).containsExactly("abc"); assertThat(list).containsExactly("abc");
} }

@ -150,7 +150,8 @@ public class LoggersMvcEndpointTests {
@Test @Test
public void setLoggerUsingApplicationJsonShouldSetLogLevel() throws Exception { public void setLoggerUsingApplicationJsonShouldSetLogLevel() throws Exception {
this.mvc.perform(post(PATH + "/ROOT").contentType(MediaType.APPLICATION_JSON) this.mvc.perform(post(PATH + "/ROOT").contentType(MediaType.APPLICATION_JSON)
.content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isNoContent()); .content("{\"configuredLevel\":\"debug\"}"))
.andExpect(status().isNoContent());
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG); verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
} }
@ -158,7 +159,8 @@ public class LoggersMvcEndpointTests {
public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception { public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
this.mvc.perform(post(PATH + "/ROOT") this.mvc.perform(post(PATH + "/ROOT")
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON) .contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON)
.content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isNoContent()); .content("{\"configuredLevel\":\"debug\"}"))
.andExpect(status().isNoContent());
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG); verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
} }

@ -190,7 +190,8 @@ public class WebFluxAutoConfigurationTests {
.getBeanNamesForType(javax.validation.Validator.class); .getBeanNamesForType(javax.validation.Validator.class);
String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class); String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class);
assertThat(jsrValidatorBeans).containsExactly("defaultValidator"); assertThat(jsrValidatorBeans).containsExactly("defaultValidator");
assertThat(springValidatorBeans).containsExactly("defaultValidator", "webFluxValidator"); assertThat(springValidatorBeans).containsExactly("defaultValidator",
"webFluxValidator");
Validator validator = this.context.getBean("webFluxValidator", Validator.class); Validator validator = this.context.getBean("webFluxValidator", Validator.class);
assertThat(validator).isInstanceOf(ValidatorAdapter.class); assertThat(validator).isInstanceOf(ValidatorAdapter.class);
Object defaultValidator = this.context.getBean("defaultValidator"); Object defaultValidator = this.context.getBean("defaultValidator");
@ -208,13 +209,14 @@ public class WebFluxAutoConfigurationTests {
.isEmpty(); .isEmpty();
String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class); String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class);
assertThat(springValidatorBeans).containsExactly("webFluxValidator"); assertThat(springValidatorBeans).containsExactly("webFluxValidator");
assertThat(this.context.getBean("webFluxValidator")) assertThat(this.context.getBean("webFluxValidator")).isSameAs(
.isSameAs(this.context.getBean(ValidatorWebFluxConfigurer.class).validator); this.context.getBean(ValidatorWebFluxConfigurer.class).validator);
} }
@Test @Test
public void validatorWithConfigurerDoesNotExposeJsr303() { public void validatorWithConfigurerDoesNotExposeJsr303() {
load(ValidatorJsr303WebFluxConfigurer.class, new Class<?>[] { ValidationAutoConfiguration.class }); load(ValidatorJsr303WebFluxConfigurer.class,
new Class<?>[] { ValidationAutoConfiguration.class });
assertThat(this.context.getBeansOfType(ValidatorFactory.class)).isEmpty(); assertThat(this.context.getBeansOfType(ValidatorFactory.class)).isEmpty();
assertThat(this.context.getBeansOfType(javax.validation.Validator.class)) assertThat(this.context.getBeansOfType(javax.validation.Validator.class))
.isEmpty(); .isEmpty();
@ -222,8 +224,8 @@ public class WebFluxAutoConfigurationTests {
assertThat(springValidatorBeans).containsExactly("webFluxValidator"); assertThat(springValidatorBeans).containsExactly("webFluxValidator");
Validator validator = this.context.getBean("webFluxValidator", Validator.class); Validator validator = this.context.getBean("webFluxValidator", Validator.class);
assertThat(validator).isInstanceOf(ValidatorAdapter.class); assertThat(validator).isInstanceOf(ValidatorAdapter.class);
assertThat(((ValidatorAdapter) validator).getTarget()) assertThat(((ValidatorAdapter) validator).getTarget()).isSameAs(
.isSameAs(this.context.getBean(ValidatorJsr303WebFluxConfigurer.class).validator); this.context.getBean(ValidatorJsr303WebFluxConfigurer.class).validator);
} }
@Test @Test
@ -233,10 +235,10 @@ public class WebFluxAutoConfigurationTests {
assertThat(this.context.getBeansOfType(javax.validation.Validator.class)) assertThat(this.context.getBeansOfType(javax.validation.Validator.class))
.hasSize(1); .hasSize(1);
String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class); String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class);
assertThat(springValidatorBeans) assertThat(springValidatorBeans).containsExactly("defaultValidator",
.containsExactly("defaultValidator", "webFluxValidator"); "webFluxValidator");
assertThat(this.context.getBean("webFluxValidator")) assertThat(this.context.getBean("webFluxValidator")).isSameAs(
.isSameAs(this.context.getBean(ValidatorWebFluxConfigurer.class).validator); this.context.getBean(ValidatorWebFluxConfigurer.class).validator);
// Primary Spring validator is the auto-configured one as the WebFlux one has been // Primary Spring validator is the auto-configured one as the WebFlux one has been
// customized via a WebFluxConfigurer // customized via a WebFluxConfigurer
assertThat(this.context.getBean(Validator.class)) assertThat(this.context.getBean(Validator.class))
@ -250,13 +252,12 @@ public class WebFluxAutoConfigurationTests {
.getBeanNamesForType(javax.validation.Validator.class); .getBeanNamesForType(javax.validation.Validator.class);
String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class); String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class);
assertThat(jsrValidatorBeans).containsExactly("defaultValidator"); assertThat(jsrValidatorBeans).containsExactly("defaultValidator");
assertThat(springValidatorBeans).containsExactly( assertThat(springValidatorBeans).containsExactly("customValidator",
"customValidator", "defaultValidator", "webFluxValidator"); "defaultValidator", "webFluxValidator");
Validator validator = this.context.getBean("webFluxValidator", Validator.class); Validator validator = this.context.getBean("webFluxValidator", Validator.class);
assertThat(validator).isInstanceOf(ValidatorAdapter.class); assertThat(validator).isInstanceOf(ValidatorAdapter.class);
Object defaultValidator = this.context.getBean("defaultValidator"); Object defaultValidator = this.context.getBean("defaultValidator");
assertThat(((ValidatorAdapter) validator).getTarget()) assertThat(((ValidatorAdapter) validator).getTarget()).isSameAs(defaultValidator);
.isSameAs(defaultValidator);
// Primary Spring validator is the one use by WebFlux behind the scenes // Primary Spring validator is the one use by WebFlux behind the scenes
assertThat(this.context.getBean(Validator.class)).isEqualTo(defaultValidator); assertThat(this.context.getBean(Validator.class)).isEqualTo(defaultValidator);
} }

@ -61,16 +61,11 @@ class CollectionBinder extends IndexedElementsBinder<Collection<Object>> {
} }
} }
@SuppressWarnings("unchecked")
private Collection<Object> createNewCollection(Collection<Object> additional) { private Collection<Object> createNewCollection(Collection<Object> additional) {
try { Collection<Object> merged = CollectionFactory
Collection<Object> merged = additional.getClass().newInstance(); .createCollection(additional.getClass(), additional.size());
merged.addAll(additional); merged.addAll(additional);
return merged; return merged;
}
catch (Exception e) {
throw new IllegalStateException("Adding bound values to collection failed.");
}
} }
} }

@ -119,8 +119,7 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
private ConfigurationPropertyName getEntryName(ConfigurationPropertySource source, private ConfigurationPropertyName getEntryName(ConfigurationPropertySource source,
ConfigurationPropertyName name) { ConfigurationPropertyName name) {
Class<?> resolved = this.valueType.resolve(); Class<?> resolved = this.valueType.resolve();
if (Collection.class.isAssignableFrom(resolved) if (Collection.class.isAssignableFrom(resolved) || this.valueType.isArray()) {
|| this.valueType.isArray()) {
return chopNameAtNumericIndex(name); return chopNameAtNumericIndex(name);
} }
if (!this.root.isParentOf(name) if (!this.root.isParentOf(name)
@ -130,7 +129,8 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
return name; return name;
} }
private ConfigurationPropertyName chopNameAtNumericIndex(ConfigurationPropertyName name) { private ConfigurationPropertyName chopNameAtNumericIndex(
ConfigurationPropertyName name) {
int start = this.root.getNumberOfElements() + 1; int start = this.root.getNumberOfElements() + 1;
int size = name.getNumberOfElements(); int size = name.getNumberOfElements();
for (int i = start; i < size; i++) { for (int i = start; i < size; i++) {

@ -109,7 +109,17 @@ public final class ConfigurationPropertyName
* @return {@code true} if the element is indexed and numeric * @return {@code true} if the element is indexed and numeric
*/ */
public boolean IsNumericIndex(int elementIndex) { public boolean IsNumericIndex(int elementIndex) {
return isIndexed(elementIndex) && isNumeric(getElement(elementIndex, Form.ORIGINAL)); return isIndexed(elementIndex)
&& isNumeric(getElement(elementIndex, Form.ORIGINAL));
}
private boolean isNumeric(CharSequence element) {
for (int i = 0; i < element.length(); i++) {
if (!Character.isDigit(element.charAt(i))) {
return false;
}
}
return true;
} }
/** /**
@ -401,16 +411,6 @@ public final class ConfigurationPropertyName
&& element.charAt(length - 1) == ']'; && element.charAt(length - 1) == ']';
} }
private static boolean isNumeric(CharSequence element) {
int length = element.length();
for (int i = 0; i < length; i++) {
if (!Character.isDigit(element.charAt(i))) {
return false;
}
}
return true;
}
/** /**
* Returns if the given name is valid. If this method returns {@code true} then the * Returns if the given name is valid. If this method returns {@code true} then the
* name may be used with {@link #of(CharSequence)} without throwing an exception. * name may be used with {@link #of(CharSequence)} without throwing an exception.

@ -278,7 +278,8 @@ public class CollectionBinderTests {
} }
@Test @Test
public void bindToNonScalarCollectionShouldReturnPopulatedCollection() throws Exception { public void bindToNonScalarCollectionShouldReturnPopulatedCollection()
throws Exception {
MockConfigurationPropertySource source = new MockConfigurationPropertySource(); MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0].value", "a"); source.put("foo[0].value", "a");
source.put("foo[1].value", "b"); source.put("foo[1].value", "b");
@ -287,17 +288,20 @@ public class CollectionBinderTests {
Bindable<List<JavaBean>> target = Bindable.listOf(JavaBean.class); Bindable<List<JavaBean>> target = Bindable.listOf(JavaBean.class);
List<JavaBean> result = this.binder.bind("foo", target).get(); List<JavaBean> result = this.binder.bind("foo", target).get();
assertThat(result).hasSize(3); assertThat(result).hasSize(3);
List<String> values = result.stream().map(JavaBean::getValue).collect(Collectors.toList()); List<String> values = result.stream().map(JavaBean::getValue)
.collect(Collectors.toList());
assertThat(values).containsExactly("a", "b", "c"); assertThat(values).containsExactly("a", "b", "c");
} }
@Test @Test
public void bindToImmutableCollectionShouldReturnPopulatedCollection() throws Exception { public void bindToImmutableCollectionShouldReturnPopulatedCollection()
throws Exception {
MockConfigurationPropertySource source = new MockConfigurationPropertySource(); MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.values", "a,b,c"); source.put("foo.values", "a,b,c");
this.sources.add(source); this.sources.add(source);
Set<String> result = this.binder.bind("foo.values", Set<String> result = this.binder
STRING_SET.withExistingValue(Collections.emptySet())).get(); .bind("foo.values", STRING_SET.withExistingValue(Collections.emptySet()))
.get();
assertThat(result).hasSize(3); assertThat(result).hasSize(3);
} }

@ -351,10 +351,10 @@ public class MapBinderTests {
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
Bindable<Map<String, Integer>> target = STRING_INTEGER_MAP; Bindable<Map<String, Integer>> target = STRING_INTEGER_MAP;
this.binder.bind("foo", target, handler); this.binder.bind("foo", target, handler);
InOrder inOrder = inOrder(handler); InOrder ordered = inOrder(handler);
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")), ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")),
eq(Bindable.of(Integer.class)), any(), eq(1)); eq(Bindable.of(Integer.class)), any(), eq(1));
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")), ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")),
eq(target), any(), isA(Map.class)); eq(target), any(), isA(Map.class));
} }
@ -366,27 +366,28 @@ public class MapBinderTests {
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
Bindable<Map<String, String[]>> target = STRING_ARRAY_MAP; Bindable<Map<String, String[]>> target = STRING_ARRAY_MAP;
this.binder.bind("foo", target, handler); this.binder.bind("foo", target, handler);
InOrder inOrder = inOrder(handler); InOrder ordered = inOrder(handler);
ArgumentCaptor<String[]> array = ArgumentCaptor.forClass(String[].class); ArgumentCaptor<String[]> array = ArgumentCaptor.forClass(String[].class);
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")), ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")),
eq(Bindable.of(String[].class)), any(), array.capture()); eq(Bindable.of(String[].class)), any(), array.capture());
assertThat(array.getValue()).containsExactly("a", "b", "c"); assertThat(array.getValue()).containsExactly("a", "b", "c");
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")), ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")),
eq(target), any(), isA(Map.class)); eq(target), any(), isA(Map.class));
} }
@Test @Test
public void bindToMapNonScalarCollectionShouldPopulateMap() throws Exception { public void bindToMapNonScalarCollectionShouldPopulateMap() throws Exception {
Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class); Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class);
Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class, valueType.getType()); Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class,
valueType.getType());
MockConfigurationPropertySource source = new MockConfigurationPropertySource(); MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar[0].value", "a"); source.put("foo.bar[0].value", "a");
source.put("foo.bar[1].value", "b"); source.put("foo.bar[1].value", "b");
source.put("foo.bar[2].value", "c"); source.put("foo.bar[2].value", "c");
this.sources this.sources.add(source);
.add(source);
Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get(); Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get();
List<String> values = map.get("bar").stream().map(JavaBean::getValue).collect(Collectors.toList()); List<String> values = map.get("bar").stream().map(JavaBean::getValue)
.collect(Collectors.toList());
assertThat(values).containsExactly("a", "b", "c"); assertThat(values).containsExactly("a", "b", "c");
} }
@ -401,9 +402,10 @@ public class MapBinderTests {
} }
@Test @Test
public void bindToMapShouldNotTreatClassWithStringConstructorAsScalar() throws Exception { public void bindToMapShouldNotTreatClassWithStringConstructorAsScalar()
this.sources throws Exception {
.add(new MockConfigurationPropertySource("foo.bar.pattern", "1", "line1")); this.sources.add(
new MockConfigurationPropertySource("foo.bar.pattern", "1", "line1"));
Bindable<Map<String, Foo>> target = Bindable.mapOf(String.class, Foo.class); Bindable<Map<String, Foo>> target = Bindable.mapOf(String.class, Foo.class);
Map<String, Foo> map = this.binder.bind("foo", target).get(); Map<String, Foo> map = this.binder.bind("foo", target).get();
assertThat(map.get("bar").getPattern()).isEqualTo("1"); assertThat(map.get("bar").getPattern()).isEqualTo("1");
@ -415,18 +417,17 @@ public class MapBinderTests {
mockSource.put("foo.bar.baz[0]", "a"); mockSource.put("foo.bar.baz[0]", "a");
mockSource.put("foo.bar.baz[1]", "b"); mockSource.put("foo.bar.baz[1]", "b");
mockSource.put("foo.bar.baz[2]", "c"); mockSource.put("foo.bar.baz[2]", "c");
this.sources this.sources.add(mockSource);
.add(mockSource);
Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get(); Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get();
assertThat(map.get("bar.baz")).containsExactly("a", "b", "c"); assertThat(map.get("bar.baz")).containsExactly("a", "b", "c");
} }
@Test @Test
public void bindToMapStringArrayWithDotKeysAndCommaSeparatedShouldPreserveDot() throws Exception { public void bindToMapStringArrayWithDotKeysAndCommaSeparatedShouldPreserveDot()
throws Exception {
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource(); MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo.bar.baz", "a,b,c"); mockSource.put("foo.bar.baz", "a,b,c");
this.sources this.sources.add(mockSource);
.add(mockSource);
Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get(); Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get();
assertThat(map.get("bar.baz")).containsExactly("a", "b", "c"); assertThat(map.get("bar.baz")).containsExactly("a", "b", "c");
} }
@ -434,13 +435,13 @@ public class MapBinderTests {
@Test @Test
public void bindToMapStringCollectionWithDotKeysShouldPreserveDot() throws Exception { public void bindToMapStringCollectionWithDotKeysShouldPreserveDot() throws Exception {
Bindable<List<String>> valueType = Bindable.listOf(String.class); Bindable<List<String>> valueType = Bindable.listOf(String.class);
Bindable<Map<String, List<String>>> target = getMapBindable(String.class, valueType.getType()); Bindable<Map<String, List<String>>> target = getMapBindable(String.class,
valueType.getType());
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource(); MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo.bar.baz[0]", "a"); mockSource.put("foo.bar.baz[0]", "a");
mockSource.put("foo.bar.baz[1]", "b"); mockSource.put("foo.bar.baz[1]", "b");
mockSource.put("foo.bar.baz[2]", "c"); mockSource.put("foo.bar.baz[2]", "c");
this.sources this.sources.add(mockSource);
.add(mockSource);
Map<String, List<String>> map = this.binder.bind("foo", target).get(); Map<String, List<String>> map = this.binder.bind("foo", target).get();
List<String> values = map.get("bar.baz"); List<String> values = map.get("bar.baz");
assertThat(values).containsExactly("a", "b", "c"); assertThat(values).containsExactly("a", "b", "c");
@ -449,28 +450,30 @@ public class MapBinderTests {
@Test @Test
public void bindToMapNonScalarCollectionWithDotKeysShouldBind() throws Exception { public void bindToMapNonScalarCollectionWithDotKeysShouldBind() throws Exception {
Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class); Bindable<List<JavaBean>> valueType = Bindable.listOf(JavaBean.class);
Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class, valueType.getType()); Bindable<Map<String, List<JavaBean>>> target = getMapBindable(String.class,
valueType.getType());
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource(); MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo.bar.baz[0].value", "a"); mockSource.put("foo.bar.baz[0].value", "a");
mockSource.put("foo.bar.baz[1].value", "b"); mockSource.put("foo.bar.baz[1].value", "b");
mockSource.put("foo.bar.baz[2].value", "c"); mockSource.put("foo.bar.baz[2].value", "c");
this.sources this.sources.add(mockSource);
.add(mockSource);
Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get(); Map<String, List<JavaBean>> map = this.binder.bind("foo", target).get();
List<String> values = map.get("bar.baz").stream().map(JavaBean::getValue).collect(Collectors.toList()); List<String> values = map.get("bar.baz").stream().map(JavaBean::getValue)
.collect(Collectors.toList());
assertThat(values).containsExactly("a", "b", "c"); assertThat(values).containsExactly("a", "b", "c");
} }
@Test @Test
public void bindToListOfMaps() throws Exception { public void bindToListOfMaps() throws Exception {
Bindable<List<Integer>> listBindable = Bindable.listOf(Integer.class); Bindable<List<Integer>> listBindable = Bindable.listOf(Integer.class);
Bindable<Map<String, List<Integer>>> mapBindable = getMapBindable(String.class, listBindable.getType()); Bindable<Map<String, List<Integer>>> mapBindable = getMapBindable(String.class,
Bindable<List<Map<String, List<Integer>>>> target = getListBindable(mapBindable.getType()); listBindable.getType());
Bindable<List<Map<String, List<Integer>>>> target = getListBindable(
mapBindable.getType());
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource(); MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo[0].a", "1,2,3"); mockSource.put("foo[0].a", "1,2,3");
mockSource.put("foo[1].b", "4,5,6"); mockSource.put("foo[1].b", "4,5,6");
this.sources this.sources.add(mockSource);
.add(mockSource);
List<Map<String, List<Integer>>> list = this.binder.bind("foo", target).get(); List<Map<String, List<Integer>>> list = this.binder.bind("foo", target).get();
assertThat(list.get(0).get("a")).containsExactly(1, 2, 3); assertThat(list.get(0).get("a")).containsExactly(1, 2, 3);
assertThat(list.get(1).get("b")).containsExactly(4, 5, 6); assertThat(list.get(1).get("b")).containsExactly(4, 5, 6);
@ -479,12 +482,12 @@ public class MapBinderTests {
@Test @Test
public void bindToMapWithNumberKeyAndCommaSeparated() throws Exception { public void bindToMapWithNumberKeyAndCommaSeparated() throws Exception {
Bindable<List<String>> listBindable = Bindable.listOf(String.class); Bindable<List<String>> listBindable = Bindable.listOf(String.class);
Bindable<Map<Integer, List<String>>> target = getMapBindable(Integer.class, listBindable.getType()); Bindable<Map<Integer, List<String>>> target = getMapBindable(Integer.class,
listBindable.getType());
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource(); MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo[0]", "a,b,c"); mockSource.put("foo[0]", "a,b,c");
mockSource.put("foo[1]", "e,f,g"); mockSource.put("foo[1]", "e,f,g");
this.sources this.sources.add(mockSource);
.add(mockSource);
Map<Integer, List<String>> map = this.binder.bind("foo", target).get(); Map<Integer, List<String>> map = this.binder.bind("foo", target).get();
assertThat(map.get(0)).containsExactly("a", "b", "c"); assertThat(map.get(0)).containsExactly("a", "b", "c");
assertThat(map.get(1)).containsExactly("e", "f", "g"); assertThat(map.get(1)).containsExactly("e", "f", "g");
@ -493,12 +496,12 @@ public class MapBinderTests {
@Test @Test
public void bindToMapWithNumberKeyAndIndexed() throws Exception { public void bindToMapWithNumberKeyAndIndexed() throws Exception {
Bindable<List<Integer>> listBindable = Bindable.listOf(Integer.class); Bindable<List<Integer>> listBindable = Bindable.listOf(Integer.class);
Bindable<Map<Integer, List<Integer>>> target = getMapBindable(Integer.class, listBindable.getType()); Bindable<Map<Integer, List<Integer>>> target = getMapBindable(Integer.class,
listBindable.getType());
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource(); MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo[0][0]", "8"); mockSource.put("foo[0][0]", "8");
mockSource.put("foo[0][1]", "9"); mockSource.put("foo[0][1]", "9");
this.sources this.sources.add(mockSource);
.add(mockSource);
Map<Integer, List<Integer>> map = this.binder.bind("foo", target).get(); Map<Integer, List<Integer>> map = this.binder.bind("foo", target).get();
assertThat(map.get(0)).containsExactly(8, 9); assertThat(map.get(0)).containsExactly(8, 9);
} }
@ -512,9 +515,11 @@ public class MapBinderTests {
assertThat(map).containsEntry("x [B] y", "[ball]"); assertThat(map).containsEntry("x [B] y", "[ball]");
} }
private <K, V> Bindable<Map<K, V>> getMapBindable(Class<K> keyGeneric, ResolvableType valueType) { private <K, V> Bindable<Map<K, V>> getMapBindable(Class<K> keyGeneric,
ResolvableType valueType) {
ResolvableType keyType = ResolvableType.forClass(keyGeneric); ResolvableType keyType = ResolvableType.forClass(keyGeneric);
return Bindable.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType)); return Bindable
.of(ResolvableType.forClassWithGenerics(Map.class, keyType, valueType));
} }
private <T> Bindable<List<T>> getListBindable(ResolvableType type) { private <T> Bindable<List<T>> getListBindable(ResolvableType type) {
@ -522,6 +527,7 @@ public class MapBinderTests {
} }
public static class Foo { public static class Foo {
private String pattern; private String pattern;
public Foo() { public Foo() {

@ -85,8 +85,7 @@ public class AtomikosPropertiesTests {
assertThat(properties).contains(defaultOf(defaultSettings, assertThat(properties).contains(defaultOf(defaultSettings,
"com.atomikos.icatch.max_timeout", "com.atomikos.icatch.max_timeout",
"com.atomikos.icatch.default_jta_timeout", "com.atomikos.icatch.default_jta_timeout",
"com.atomikos.icatch.max_actives", "com.atomikos.icatch.max_actives", "com.atomikos.icatch.enable_logging",
"com.atomikos.icatch.enable_logging",
"com.atomikos.icatch.serial_jta_transactions", "com.atomikos.icatch.serial_jta_transactions",
"com.atomikos.icatch.force_shutdown_on_vm_exit", "com.atomikos.icatch.force_shutdown_on_vm_exit",
"com.atomikos.icatch.log_base_name", "com.atomikos.icatch.log_base_name",
@ -111,7 +110,8 @@ public class AtomikosPropertiesTests {
private Properties loadDefaultSettings() { private Properties loadDefaultSettings() {
try { try {
Class<?> target = ClassUtils.forName("com.atomikos.icatch.standalone.UserTransactionServiceImp", Class<?> target = ClassUtils.forName(
"com.atomikos.icatch.standalone.UserTransactionServiceImp",
getClass().getClassLoader()); getClass().getClassLoader());
Method m = target.getMethod("getDefaultProperties"); Method m = target.getMethod("getDefaultProperties");
m.setAccessible(true); m.setAccessible(true);

Loading…
Cancel
Save