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) {
if (ClassUtils.isPresent("org.springframework.cache.transaction.TransactionAwareCacheDecorator",
if (ClassUtils.isPresent(
"org.springframework.cache.transaction.TransactionAwareCacheDecorator",
getClass().getClassLoader())) {
return TransactionAwareCacheDecoratorHandler.unwrapIfNecessary(cache);
}
@ -154,6 +155,7 @@ public class CachePublicMetrics implements PublicMetrics {
}
return cache;
}
}
}

@ -341,7 +341,8 @@ public class ConfigurationPropertiesReportEndpoint
// 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.
return (setter != null)
|| ClassUtils.getPackageName(parentType).equals(ClassUtils.getPackageName(type))
|| ClassUtils.getPackageName(parentType)
.equals(ClassUtils.getPackageName(type))
|| Map.class.isAssignableFrom(type)
|| Collection.class.isAssignableFrom(type);
}

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

@ -150,7 +150,8 @@ public class LoggersMvcEndpointTests {
@Test
public void setLoggerUsingApplicationJsonShouldSetLogLevel() throws Exception {
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);
}
@ -158,7 +159,8 @@ public class LoggersMvcEndpointTests {
public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
this.mvc.perform(post(PATH + "/ROOT")
.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);
}

@ -190,7 +190,8 @@ public class WebFluxAutoConfigurationTests {
.getBeanNamesForType(javax.validation.Validator.class);
String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class);
assertThat(jsrValidatorBeans).containsExactly("defaultValidator");
assertThat(springValidatorBeans).containsExactly("defaultValidator", "webFluxValidator");
assertThat(springValidatorBeans).containsExactly("defaultValidator",
"webFluxValidator");
Validator validator = this.context.getBean("webFluxValidator", Validator.class);
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
Object defaultValidator = this.context.getBean("defaultValidator");
@ -208,13 +209,14 @@ public class WebFluxAutoConfigurationTests {
.isEmpty();
String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class);
assertThat(springValidatorBeans).containsExactly("webFluxValidator");
assertThat(this.context.getBean("webFluxValidator"))
.isSameAs(this.context.getBean(ValidatorWebFluxConfigurer.class).validator);
assertThat(this.context.getBean("webFluxValidator")).isSameAs(
this.context.getBean(ValidatorWebFluxConfigurer.class).validator);
}
@Test
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(javax.validation.Validator.class))
.isEmpty();
@ -222,8 +224,8 @@ public class WebFluxAutoConfigurationTests {
assertThat(springValidatorBeans).containsExactly("webFluxValidator");
Validator validator = this.context.getBean("webFluxValidator", Validator.class);
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
assertThat(((ValidatorAdapter) validator).getTarget())
.isSameAs(this.context.getBean(ValidatorJsr303WebFluxConfigurer.class).validator);
assertThat(((ValidatorAdapter) validator).getTarget()).isSameAs(
this.context.getBean(ValidatorJsr303WebFluxConfigurer.class).validator);
}
@Test
@ -233,10 +235,10 @@ public class WebFluxAutoConfigurationTests {
assertThat(this.context.getBeansOfType(javax.validation.Validator.class))
.hasSize(1);
String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class);
assertThat(springValidatorBeans)
.containsExactly("defaultValidator", "webFluxValidator");
assertThat(this.context.getBean("webFluxValidator"))
.isSameAs(this.context.getBean(ValidatorWebFluxConfigurer.class).validator);
assertThat(springValidatorBeans).containsExactly("defaultValidator",
"webFluxValidator");
assertThat(this.context.getBean("webFluxValidator")).isSameAs(
this.context.getBean(ValidatorWebFluxConfigurer.class).validator);
// Primary Spring validator is the auto-configured one as the WebFlux one has been
// customized via a WebFluxConfigurer
assertThat(this.context.getBean(Validator.class))
@ -250,13 +252,12 @@ public class WebFluxAutoConfigurationTests {
.getBeanNamesForType(javax.validation.Validator.class);
String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class);
assertThat(jsrValidatorBeans).containsExactly("defaultValidator");
assertThat(springValidatorBeans).containsExactly(
"customValidator", "defaultValidator", "webFluxValidator");
assertThat(springValidatorBeans).containsExactly("customValidator",
"defaultValidator", "webFluxValidator");
Validator validator = this.context.getBean("webFluxValidator", Validator.class);
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
Object defaultValidator = this.context.getBean("defaultValidator");
assertThat(((ValidatorAdapter) validator).getTarget())
.isSameAs(defaultValidator);
assertThat(((ValidatorAdapter) validator).getTarget()).isSameAs(defaultValidator);
// Primary Spring validator is the one use by WebFlux behind the scenes
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) {
try {
Collection<Object> merged = additional.getClass().newInstance();
merged.addAll(additional);
return merged;
}
catch (Exception e) {
throw new IllegalStateException("Adding bound values to collection failed.");
}
Collection<Object> merged = CollectionFactory
.createCollection(additional.getClass(), additional.size());
merged.addAll(additional);
return merged;
}
}

@ -119,8 +119,7 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
private ConfigurationPropertyName getEntryName(ConfigurationPropertySource source,
ConfigurationPropertyName name) {
Class<?> resolved = this.valueType.resolve();
if (Collection.class.isAssignableFrom(resolved)
|| this.valueType.isArray()) {
if (Collection.class.isAssignableFrom(resolved) || this.valueType.isArray()) {
return chopNameAtNumericIndex(name);
}
if (!this.root.isParentOf(name)
@ -130,7 +129,8 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
return name;
}
private ConfigurationPropertyName chopNameAtNumericIndex(ConfigurationPropertyName name) {
private ConfigurationPropertyName chopNameAtNumericIndex(
ConfigurationPropertyName name) {
int start = this.root.getNumberOfElements() + 1;
int size = name.getNumberOfElements();
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
*/
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) == ']';
}
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
* name may be used with {@link #of(CharSequence)} without throwing an exception.

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

@ -351,10 +351,10 @@ public class MapBinderTests {
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
Bindable<Map<String, Integer>> target = STRING_INTEGER_MAP;
this.binder.bind("foo", target, handler);
InOrder inOrder = inOrder(handler);
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")),
InOrder ordered = inOrder(handler);
ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo.bar")),
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));
}
@ -366,27 +366,28 @@ public class MapBinderTests {
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
Bindable<Map<String, String[]>> target = STRING_ARRAY_MAP;
this.binder.bind("foo", target, handler);
InOrder inOrder = inOrder(handler);
InOrder ordered = inOrder(handler);
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());
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));
}
@Test
public void bindToMapNonScalarCollectionShouldPopulateMap() throws Exception {
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();
source.put("foo.bar[0].value", "a");
source.put("foo.bar[1].value", "b");
source.put("foo.bar[2].value", "c");
this.sources
.add(source);
this.sources.add(source);
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");
}
@ -401,9 +402,10 @@ public class MapBinderTests {
}
@Test
public void bindToMapShouldNotTreatClassWithStringConstructorAsScalar() throws Exception {
this.sources
.add(new MockConfigurationPropertySource("foo.bar.pattern", "1", "line1"));
public void bindToMapShouldNotTreatClassWithStringConstructorAsScalar()
throws Exception {
this.sources.add(
new MockConfigurationPropertySource("foo.bar.pattern", "1", "line1"));
Bindable<Map<String, Foo>> target = Bindable.mapOf(String.class, Foo.class);
Map<String, Foo> map = this.binder.bind("foo", target).get();
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[1]", "b");
mockSource.put("foo.bar.baz[2]", "c");
this.sources
.add(mockSource);
this.sources.add(mockSource);
Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get();
assertThat(map.get("bar.baz")).containsExactly("a", "b", "c");
}
@Test
public void bindToMapStringArrayWithDotKeysAndCommaSeparatedShouldPreserveDot() throws Exception {
public void bindToMapStringArrayWithDotKeysAndCommaSeparatedShouldPreserveDot()
throws Exception {
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo.bar.baz", "a,b,c");
this.sources
.add(mockSource);
this.sources.add(mockSource);
Map<String, String[]> map = this.binder.bind("foo", STRING_ARRAY_MAP).get();
assertThat(map.get("bar.baz")).containsExactly("a", "b", "c");
}
@ -434,13 +435,13 @@ public class MapBinderTests {
@Test
public void bindToMapStringCollectionWithDotKeysShouldPreserveDot() throws Exception {
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();
mockSource.put("foo.bar.baz[0]", "a");
mockSource.put("foo.bar.baz[1]", "b");
mockSource.put("foo.bar.baz[2]", "c");
this.sources
.add(mockSource);
this.sources.add(mockSource);
Map<String, List<String>> map = this.binder.bind("foo", target).get();
List<String> values = map.get("bar.baz");
assertThat(values).containsExactly("a", "b", "c");
@ -449,28 +450,30 @@ public class MapBinderTests {
@Test
public void bindToMapNonScalarCollectionWithDotKeysShouldBind() throws Exception {
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();
mockSource.put("foo.bar.baz[0].value", "a");
mockSource.put("foo.bar.baz[1].value", "b");
mockSource.put("foo.bar.baz[2].value", "c");
this.sources
.add(mockSource);
this.sources.add(mockSource);
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");
}
@Test
public void bindToListOfMaps() throws Exception {
Bindable<List<Integer>> listBindable = Bindable.listOf(Integer.class);
Bindable<Map<String, List<Integer>>> mapBindable = getMapBindable(String.class, listBindable.getType());
Bindable<List<Map<String, List<Integer>>>> target = getListBindable(mapBindable.getType());
Bindable<Map<String, List<Integer>>> mapBindable = getMapBindable(String.class,
listBindable.getType());
Bindable<List<Map<String, List<Integer>>>> target = getListBindable(
mapBindable.getType());
MockConfigurationPropertySource mockSource = new MockConfigurationPropertySource();
mockSource.put("foo[0].a", "1,2,3");
mockSource.put("foo[1].b", "4,5,6");
this.sources
.add(mockSource);
this.sources.add(mockSource);
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(1).get("b")).containsExactly(4, 5, 6);
@ -479,12 +482,12 @@ public class MapBinderTests {
@Test
public void bindToMapWithNumberKeyAndCommaSeparated() throws Exception {
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();
mockSource.put("foo[0]", "a,b,c");
mockSource.put("foo[1]", "e,f,g");
this.sources
.add(mockSource);
this.sources.add(mockSource);
Map<Integer, List<String>> map = this.binder.bind("foo", target).get();
assertThat(map.get(0)).containsExactly("a", "b", "c");
assertThat(map.get(1)).containsExactly("e", "f", "g");
@ -493,12 +496,12 @@ public class MapBinderTests {
@Test
public void bindToMapWithNumberKeyAndIndexed() throws Exception {
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();
mockSource.put("foo[0][0]", "8");
mockSource.put("foo[0][1]", "9");
this.sources
.add(mockSource);
this.sources.add(mockSource);
Map<Integer, List<Integer>> map = this.binder.bind("foo", target).get();
assertThat(map.get(0)).containsExactly(8, 9);
}
@ -512,9 +515,11 @@ public class MapBinderTests {
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);
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) {
@ -522,6 +527,7 @@ public class MapBinderTests {
}
public static class Foo {
private String pattern;
public Foo() {

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

Loading…
Cancel
Save