From 19e70055a5dfc72e7da21a9490b6ef79ee095d55 Mon Sep 17 00:00:00 2001 From: Mirko Sobeck Date: Tue, 10 Jan 2023 17:41:14 +0100 Subject: [PATCH 1/2] Test Micrometer config to property exposure See gh-33743 --- .../TestConfigsToPropertiesExposure.java | 110 ++++++++++++++++++ ...AppOpticsPropertiesConfigAdapterTests.java | 10 +- .../AtlasPropertiesConfigAdapterTests.java | 10 ++ .../DatadogPropertiesConfigAdapterTests.java | 8 ++ ...DynatracePropertiesConfigAdapterTests.java | 9 ++ .../ElasticPropertiesConfigAdapterTests.java | 11 +- .../GangliaPropertiesConfigAdapterTests.java | 9 ++ .../GraphitePropertiesConfigAdapterTests.java | 9 ++ .../HumioPropertiesConfigAdapterTests.java | 9 ++ .../InfluxPropertiesConfigAdapterTests.java | 9 ++ .../jmx/JmxPropertiesConfigAdapterTests.java | 9 ++ .../KairosPropertiesConfigAdapterTests.java | 8 ++ .../NewRelicPropertiesConfigAdapterTests.java | 8 ++ ...rometheusPropertiesConfigAdapterTests.java | 9 ++ .../SignalFxPropertiesConfigAdapterTests.java | 7 ++ .../SimplePropertiesConfigAdapterTests.java | 9 ++ ...ackdriverPropertiesConfigAdapterTests.java | 9 ++ .../StatsdPropertiesConfigAdapterTests.java | 9 ++ ...WavefrontPropertiesConfigAdapterTests.java | 9 ++ 19 files changed, 269 insertions(+), 2 deletions(-) create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java new file mode 100644 index 0000000000..5b3ca0b31d --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java @@ -0,0 +1,110 @@ +/* + * Copyright 2012-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export; + +import java.lang.reflect.Method; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.Assert; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PropertiesConfigAdapter; + +/** + * Utility to test that all Micrometer config values are exposed via properties and + * settable using the corresponding {@link PropertiesConfigAdapter} implementation. + * + * @author Mirko Sobeck + */ +public final class TestConfigsToPropertiesExposure { + + private TestConfigsToPropertiesExposure() { + + } + + private static final List> classesForPropertiesList = Arrays.asList(Boolean.class, Byte.class, + Character.class, Short.class, Integer.class, Long.class, Double.class, Float.class, String.class, + Duration.class); + + /** + * Assertion to test if default methods of a given config are overridden by the + * adapter which implements it. This can be an indicator for micrometer config fields, + * that have been forgotten to expose via spring properties. Not overridden default + * methods in adapters are the most common cause of forgotten field exposure, because + * they do not for force an override. + * @param config micrometer config + * @param adapter adapter for properties {@link PropertiesConfigAdapter} + * @param excludedConfigMethods config methods that should be excluded for the + * assertion + */ + public static void assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(Class config, + Class> adapter, String... excludedConfigMethods) { + List configDefaultMethodNames = Arrays.stream(config.getDeclaredMethods()) + .filter((method) -> method.isDefault() && isSettableUsingProperties(method.getReturnType())) + .map(Method::getName).collect(Collectors.toList()); + + configDefaultMethodNames.removeAll(Arrays.stream(excludedConfigMethods).collect(Collectors.toList())); + List notOverriddenDefaultMethods = new ArrayList<>(configDefaultMethodNames); + + Class currentClass = adapter; + // loop through adapter class and superclasses + // to find not overridden config methods + while (!Object.class.equals(currentClass)) { + List overriddenClassDefaultMethods = Arrays.stream(currentClass.getDeclaredMethods()) + .map(Method::getName).filter(configDefaultMethodNames::contains).collect(Collectors.toList()); + + notOverriddenDefaultMethods.removeAll(overriddenClassDefaultMethods); + currentClass = currentClass.getSuperclass(); + } + + if (notOverriddenDefaultMethods.size() >= 1) { + Assert.fail( + "Found config default methods that are not overridden by the related PropertiesConfigAdapter: \n" + + notOverriddenDefaultMethods + "\n" + + "This could be an indicator for not exposed properties fields.\n" + + "Please check if the fields are meant to be exposed and if not, " + + "exclude them from this test by providing them to the method."); + } + } + + /** + * Guess if a class can be set using properties. This will only catch the basic use + * cases regarding the micrometer configs to filter out methods that are not likely to + * be designed to be set via properties.
+	 *     isSettableUsingProperties(String.class) = true
+	 *     isSettableUsingProperties(boolean.class) = true
+	 *     isSettableUsingProperties(Object.class) = false
+	 * 
+ * @param clazz Class + * @return is likely to be settable using properties + */ + private static boolean isSettableUsingProperties(Class clazz) { + if (Void.TYPE.equals(clazz)) { + return false; + } + + if (clazz.isPrimitive()) { + return true; + } + + return classesForPropertiesList.contains(clazz); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java index 6b5de57c7f..9768c1f186 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.appoptics; +import io.micrometer.appoptics.AppOpticsConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -68,4 +70,10 @@ class AppOpticsPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).floorTimes()).isTrue(); } + @Test + void allDefaultConfigMethodsAreOverriddenByAtlasPropertiesConfigAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(AppOpticsConfig.class, + AppOpticsPropertiesConfigAdapter.class, "connectTimeout"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java index 6b72df2739..a4dab2e54f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java @@ -18,8 +18,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.atlas; import java.time.Duration; +import com.netflix.spectator.atlas.AtlasConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -130,4 +133,11 @@ class AtlasPropertiesConfigAdapterTests { assertThat(new AtlasPropertiesConfigAdapter(properties).lwcIgnorePublishStep()).isFalse(); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(AtlasConfig.class, + AtlasPropertiesConfigAdapter.class, "lwcIgnorePublishStep", "initialPollingDelay", "autoStart", + "lwcStep", "validTagCharacters"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java index b47892c439..165f7dec03 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java @@ -16,8 +16,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.datadog; +import io.micrometer.datadog.DatadogConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -76,4 +78,10 @@ class DatadogPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).uri()).isEqualTo("https://app.example.com/api/v1/series"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(DatadogConfig.class, + DatadogPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java index b677c826f4..91ac285ad1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java @@ -19,8 +19,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.dynatrace; import java.util.HashMap; import io.micrometer.dynatrace.DynatraceApiVersion; +import io.micrometer.dynatrace.DynatraceConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -161,4 +164,10 @@ class DynatracePropertiesConfigAdapterTests { assertThat(properties.getGroup()).isNull(); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(DynatraceConfig.class, + DynatracePropertiesConfigAdapter.class, "documentType"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java index 8e53133703..b9bf20876d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.elastic; +import io.micrometer.elastic.ElasticConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -97,4 +100,10 @@ class ElasticPropertiesConfigAdapterTests { assertThat(new ElasticPropertiesConfigAdapter(properties).apiKeyCredentials()).isEqualTo("secret"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(ElasticConfig.class, + ElasticPropertiesConfigAdapter.class, "documentType"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java index d837b00192..71d0f6e0cb 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java @@ -20,8 +20,11 @@ import java.time.Duration; import java.util.concurrent.TimeUnit; import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode; +import io.micrometer.ganglia.GangliaConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -81,4 +84,10 @@ class GangliaPropertiesConfigAdapterTests { assertThat(new GangliaPropertiesConfigAdapter(properties).port()).isEqualTo(4242); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(GangliaConfig.class, + GangliaPropertiesConfigAdapter.class, "protocolVersion"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java index ef2de2d69d..37306ebc94 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java @@ -19,9 +19,12 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite; import java.time.Duration; import java.util.concurrent.TimeUnit; +import io.micrometer.graphite.GraphiteConfig; import io.micrometer.graphite.GraphiteProtocol; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -94,4 +97,10 @@ class GraphitePropertiesConfigAdapterTests { assertThat(new GraphitePropertiesConfigAdapter(properties).tagsAsPrefix()).isEqualTo(new String[] { "worker" }); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(GraphiteConfig.class, + GraphitePropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java index 37b99bb9bc..81c67f03c2 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java @@ -18,8 +18,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.humio; import java.util.Collections; +import io.micrometer.humio.HumioConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -51,4 +54,10 @@ class HumioPropertiesConfigAdapterTests { assertThat(new HumioPropertiesConfigAdapter(properties).uri()).isEqualTo("https://humio.example.com"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(HumioConfig.class, + HumioPropertiesConfigAdapter.class, "connectTimeout"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java index 2d86262c66..0d0a7142fb 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java @@ -17,8 +17,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.influx; import io.micrometer.influx.InfluxApiVersion; +import io.micrometer.influx.InfluxConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -58,4 +61,10 @@ class InfluxPropertiesConfigAdapterTests { assertThat(adapter.token()).isEqualTo("token"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(InfluxConfig.class, + InfluxPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java index 6ee12bfd5a..e23a523d2d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java @@ -18,8 +18,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.jmx; import java.time.Duration; +import io.micrometer.jmx.JmxConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -43,4 +46,10 @@ class JmxPropertiesConfigAdapterTests { assertThat(new JmxPropertiesConfigAdapter(properties).domain()).isEqualTo("abc"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(JmxConfig.class, + JmxPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java index 94e6617c26..1915d0b8df 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java @@ -16,8 +16,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.kairos; +import io.micrometer.kairos.KairosConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -62,4 +64,10 @@ class KairosPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).password()).isEqualTo("secret"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(KairosConfig.class, + KairosPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java index f3e3e80df5..0d71eb7600 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java @@ -17,8 +17,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic; import io.micrometer.newrelic.ClientProviderType; +import io.micrometer.newrelic.NewRelicConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -83,4 +85,10 @@ class NewRelicPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).uri()).isEqualTo("https://example.newrelic.com"); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(NewRelicConfig.class, + NewRelicPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java index 4fa2176884..6d6abf0d77 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java @@ -19,8 +19,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus import java.time.Duration; import io.micrometer.prometheus.HistogramFlavor; +import io.micrometer.prometheus.PrometheusConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -52,4 +55,10 @@ class PrometheusPropertiesConfigAdapterTests { assertThat(new PrometheusPropertiesConfigAdapter(properties).step()).isEqualTo(Duration.ofSeconds(30)); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(PrometheusConfig.class, + PrometheusPropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java index c9b4183983..139a7d1906 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java @@ -16,8 +16,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx; +import io.micrometer.signalfx.SignalFxConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType; @@ -68,6 +70,11 @@ class SignalFxPropertiesConfigAdapterTests SignalFxProperties properties = createProperties(); properties.setPublishedHistogramType(HistogramType.CUMULATIVE); assertThat(createConfigAdapter(properties).publishCumulativeHistogram()).isTrue(); + + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(SignalFxConfig.class, + SignalFxPropertiesConfigAdapter.class, "publishDeltaHistogram", "publishCumulativeHistogram"); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java index 5b7ba9a650..70dfe64407 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java @@ -19,8 +19,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.simple; import java.time.Duration; import io.micrometer.core.instrument.simple.CountingMode; +import io.micrometer.core.instrument.simple.SimpleConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -44,4 +47,10 @@ class SimplePropertiesConfigAdapterTests { assertThat(new SimplePropertiesConfigAdapter(properties).mode()).isEqualTo(CountingMode.STEP); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(SimpleConfig.class, + SimplePropertiesConfigAdapter.class); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java index 9b2f2fe964..3af228cd04 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java @@ -19,8 +19,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.stackdrive import java.util.HashMap; import java.util.Map; +import io.micrometer.stackdriver.StackdriverConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -62,4 +65,10 @@ class StackdriverPropertiesConfigAdapterTests { assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isTrue(); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(StackdriverConfig.class, + StackdriverPropertiesConfigAdapter.class, "metricTypePrefix"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java index 9eae3d00dc..24af397bd1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java @@ -18,10 +18,13 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.statsd; import java.time.Duration; +import io.micrometer.statsd.StatsdConfig; import io.micrometer.statsd.StatsdFlavor; import io.micrometer.statsd.StatsdProtocol; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -104,4 +107,10 @@ class StatsdPropertiesConfigAdapterTests { assertThat(new StatsdPropertiesConfigAdapter(properties).buffered()).isEqualTo(properties.isBuffered()); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(StatsdConfig.class, + StatsdPropertiesConfigAdapter.class, "queueSize"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java index f596956de1..e49197c9e0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java @@ -18,8 +18,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront; import java.net.URI; +import io.micrometer.wavefront.WavefrontConfig; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -91,4 +93,11 @@ class WavefrontPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).reportDayDistribution()).isTrue(); } + @Test + void allConfigDefaultMethodsAreOverriddenByAdapter() { + TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(WavefrontConfig.class, + WavefrontPropertiesConfigAdapter.class, "distributionPort", "reportMinuteDistribution", + "reportHourDistribution", "reportDayDistribution"); + } + } From 5c6a9122cbe72dfd944eabe154b145ee8cba26a0 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 15 Feb 2023 18:55:31 +0000 Subject: [PATCH 2/2] Polish "Test Micrometer config to property exposure" See gh-33743 --- .../TestConfigsToPropertiesExposure.java | 110 ------------------ ...AppOpticsPropertiesConfigAdapterTests.java | 12 +- .../AtlasPropertiesConfigAdapterTests.java | 18 +-- .../DatadogPropertiesConfigAdapterTests.java | 12 +- ...DynatracePropertiesConfigAdapterTests.java | 16 ++- .../ElasticPropertiesConfigAdapterTests.java | 16 ++- .../GangliaPropertiesConfigAdapterTests.java | 16 ++- .../GraphitePropertiesConfigAdapterTests.java | 16 ++- .../HumioPropertiesConfigAdapterTests.java | 16 ++- .../InfluxPropertiesConfigAdapterTests.java | 18 ++- .../jmx/JmxPropertiesConfigAdapterTests.java | 16 ++- .../KairosPropertiesConfigAdapterTests.java | 12 +- .../NewRelicPropertiesConfigAdapterTests.java | 12 +- ...rometheusPropertiesConfigAdapterTests.java | 16 ++- .../AbstractPropertiesConfigAdapterTests.java | 95 +++++++++++++++ ...hRegistryPropertiesConfigAdapterTests.java | 9 +- ...pRegistryPropertiesConfigAdapterTests.java | 6 +- .../SignalFxPropertiesConfigAdapterTests.java | 11 +- .../SimplePropertiesConfigAdapterTests.java | 16 ++- ...ackdriverPropertiesConfigAdapterTests.java | 16 ++- .../StatsdPropertiesConfigAdapterTests.java | 16 ++- ...WavefrontPropertiesConfigAdapterTests.java | 13 +-- 22 files changed, 223 insertions(+), 265 deletions(-) delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/AbstractPropertiesConfigAdapterTests.java diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java deleted file mode 100644 index 5b3ca0b31d..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/TestConfigsToPropertiesExposure.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2012-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.metrics.export; - -import java.lang.reflect.Method; -import java.time.Duration; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.junit.Assert; - -import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PropertiesConfigAdapter; - -/** - * Utility to test that all Micrometer config values are exposed via properties and - * settable using the corresponding {@link PropertiesConfigAdapter} implementation. - * - * @author Mirko Sobeck - */ -public final class TestConfigsToPropertiesExposure { - - private TestConfigsToPropertiesExposure() { - - } - - private static final List> classesForPropertiesList = Arrays.asList(Boolean.class, Byte.class, - Character.class, Short.class, Integer.class, Long.class, Double.class, Float.class, String.class, - Duration.class); - - /** - * Assertion to test if default methods of a given config are overridden by the - * adapter which implements it. This can be an indicator for micrometer config fields, - * that have been forgotten to expose via spring properties. Not overridden default - * methods in adapters are the most common cause of forgotten field exposure, because - * they do not for force an override. - * @param config micrometer config - * @param adapter adapter for properties {@link PropertiesConfigAdapter} - * @param excludedConfigMethods config methods that should be excluded for the - * assertion - */ - public static void assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(Class config, - Class> adapter, String... excludedConfigMethods) { - List configDefaultMethodNames = Arrays.stream(config.getDeclaredMethods()) - .filter((method) -> method.isDefault() && isSettableUsingProperties(method.getReturnType())) - .map(Method::getName).collect(Collectors.toList()); - - configDefaultMethodNames.removeAll(Arrays.stream(excludedConfigMethods).collect(Collectors.toList())); - List notOverriddenDefaultMethods = new ArrayList<>(configDefaultMethodNames); - - Class currentClass = adapter; - // loop through adapter class and superclasses - // to find not overridden config methods - while (!Object.class.equals(currentClass)) { - List overriddenClassDefaultMethods = Arrays.stream(currentClass.getDeclaredMethods()) - .map(Method::getName).filter(configDefaultMethodNames::contains).collect(Collectors.toList()); - - notOverriddenDefaultMethods.removeAll(overriddenClassDefaultMethods); - currentClass = currentClass.getSuperclass(); - } - - if (notOverriddenDefaultMethods.size() >= 1) { - Assert.fail( - "Found config default methods that are not overridden by the related PropertiesConfigAdapter: \n" - + notOverriddenDefaultMethods + "\n" - + "This could be an indicator for not exposed properties fields.\n" - + "Please check if the fields are meant to be exposed and if not, " - + "exclude them from this test by providing them to the method."); - } - } - - /** - * Guess if a class can be set using properties. This will only catch the basic use - * cases regarding the micrometer configs to filter out methods that are not likely to - * be designed to be set via properties.
-	 *     isSettableUsingProperties(String.class) = true
-	 *     isSettableUsingProperties(boolean.class) = true
-	 *     isSettableUsingProperties(Object.class) = false
-	 * 
- * @param clazz Class - * @return is likely to be settable using properties - */ - private static boolean isSettableUsingProperties(Class clazz) { - if (Void.TYPE.equals(clazz)) { - return false; - } - - if (clazz.isPrimitive()) { - return true; - } - - return classesForPropertiesList.contains(clazz); - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java index 9768c1f186..54ab9c2aba 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java @@ -16,10 +16,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.appoptics; -import io.micrometer.appoptics.AppOpticsConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -32,6 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat; class AppOpticsPropertiesConfigAdapterTests extends StepRegistryPropertiesConfigAdapterTests { + AppOpticsPropertiesConfigAdapterTests() { + super(AppOpticsPropertiesConfigAdapter.class); + } + @Override protected AppOpticsProperties createProperties() { return new AppOpticsProperties(); @@ -70,10 +72,4 @@ class AppOpticsPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).floorTimes()).isTrue(); } - @Test - void allDefaultConfigMethodsAreOverriddenByAtlasPropertiesConfigAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(AppOpticsConfig.class, - AppOpticsPropertiesConfigAdapter.class, "connectTimeout"); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java index a4dab2e54f..418f85609e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java @@ -18,10 +18,9 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.atlas; import java.time.Duration; -import com.netflix.spectator.atlas.AtlasConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -30,7 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class AtlasPropertiesConfigAdapterTests { +class AtlasPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + AtlasPropertiesConfigAdapterTests() { + super(AtlasPropertiesConfigAdapter.class); + } @Test void whenPropertiesStepIsSetAdapterStepReturnsIt() { @@ -134,10 +138,10 @@ class AtlasPropertiesConfigAdapterTests { } @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(AtlasConfig.class, - AtlasPropertiesConfigAdapter.class, "lwcIgnorePublishStep", "initialPollingDelay", "autoStart", - "lwcStep", "validTagCharacters"); + @Override + protected void adapterOverridesAllConfigMethods() { + adapterOverridesAllConfigMethodsExcept("autoStart", "commonTags", "debugRegistry", "publisher", "rollupPolicy", + "validTagCharacters"); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java index 165f7dec03..c95c74b465 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogPropertiesConfigAdapterTests.java @@ -16,10 +16,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.datadog; -import io.micrometer.datadog.DatadogConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -33,6 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; class DatadogPropertiesConfigAdapterTests extends StepRegistryPropertiesConfigAdapterTests { + DatadogPropertiesConfigAdapterTests() { + super(DatadogPropertiesConfigAdapter.class); + } + @Override protected DatadogProperties createProperties() { return new DatadogProperties(); @@ -78,10 +80,4 @@ class DatadogPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).uri()).isEqualTo("https://app.example.com/api/v1/series"); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(DatadogConfig.class, - DatadogPropertiesConfigAdapter.class); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java index 91ac285ad1..3b317c1775 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesConfigAdapterTests.java @@ -19,10 +19,9 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.dynatrace; import java.util.HashMap; import io.micrometer.dynatrace.DynatraceApiVersion; -import io.micrometer.dynatrace.DynatraceConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson * @author Georg Pirklbauer */ -class DynatracePropertiesConfigAdapterTests { +class DynatracePropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + DynatracePropertiesConfigAdapterTests() { + super(DynatracePropertiesConfigAdapter.class); + } @Test void whenPropertiesUriIsSetAdapterUriReturnsIt() { @@ -164,10 +168,4 @@ class DynatracePropertiesConfigAdapterTests { assertThat(properties.getGroup()).isNull(); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(DynatraceConfig.class, - DynatracePropertiesConfigAdapter.class, "documentType"); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java index b9bf20876d..0738af1280 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java @@ -16,10 +16,9 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.elastic; -import io.micrometer.elastic.ElasticConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -28,7 +27,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Andy Wilkinson */ -class ElasticPropertiesConfigAdapterTests { +class ElasticPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + ElasticPropertiesConfigAdapterTests() { + super(ElasticPropertiesConfigAdapter.class); + } @Test void whenPropertiesHostsIsSetAdapterHostsReturnsIt() { @@ -100,10 +104,4 @@ class ElasticPropertiesConfigAdapterTests { assertThat(new ElasticPropertiesConfigAdapter(properties).apiKeyCredentials()).isEqualTo("secret"); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(ElasticConfig.class, - ElasticPropertiesConfigAdapter.class, "documentType"); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java index 71d0f6e0cb..b808f1b7c6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java @@ -20,10 +20,9 @@ import java.time.Duration; import java.util.concurrent.TimeUnit; import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode; -import io.micrometer.ganglia.GangliaConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class GangliaPropertiesConfigAdapterTests { +class GangliaPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + GangliaPropertiesConfigAdapterTests() { + super(GangliaPropertiesConfigAdapter.class); + } @Test void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { @@ -84,10 +88,4 @@ class GangliaPropertiesConfigAdapterTests { assertThat(new GangliaPropertiesConfigAdapter(properties).port()).isEqualTo(4242); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(GangliaConfig.class, - GangliaPropertiesConfigAdapter.class, "protocolVersion"); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java index 37306ebc94..fe27c3cb27 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java @@ -19,11 +19,10 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite; import java.time.Duration; import java.util.concurrent.TimeUnit; -import io.micrometer.graphite.GraphiteConfig; import io.micrometer.graphite.GraphiteProtocol; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class GraphitePropertiesConfigAdapterTests { +class GraphitePropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + GraphitePropertiesConfigAdapterTests() { + super(GraphitePropertiesConfigAdapter.class); + } @Test void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { @@ -97,10 +101,4 @@ class GraphitePropertiesConfigAdapterTests { assertThat(new GraphitePropertiesConfigAdapter(properties).tagsAsPrefix()).isEqualTo(new String[] { "worker" }); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(GraphiteConfig.class, - GraphitePropertiesConfigAdapter.class); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java index 81c67f03c2..9eb31796ac 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/humio/HumioPropertiesConfigAdapterTests.java @@ -18,10 +18,9 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.humio; import java.util.Collections; -import io.micrometer.humio.HumioConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -30,7 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Andy Wilkinson */ -class HumioPropertiesConfigAdapterTests { +class HumioPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + HumioPropertiesConfigAdapterTests() { + super(HumioPropertiesConfigAdapter.class); + } @Test void whenApiTokenIsSetAdapterApiTokenReturnsIt() { @@ -54,10 +58,4 @@ class HumioPropertiesConfigAdapterTests { assertThat(new HumioPropertiesConfigAdapter(properties).uri()).isEqualTo("https://humio.example.com"); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(HumioConfig.class, - HumioPropertiesConfigAdapter.class, "connectTimeout"); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java index 0d0a7142fb..b545bb3e1a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/influx/InfluxPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,9 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.influx; import io.micrometer.influx.InfluxApiVersion; -import io.micrometer.influx.InfluxConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -29,7 +28,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Stephane Nicoll */ -class InfluxPropertiesConfigAdapterTests { +class InfluxPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + InfluxPropertiesConfigAdapterTests() { + super(InfluxPropertiesConfigAdapter.class); + } @Test void adaptInfluxV1BasicConfig() { @@ -61,10 +65,4 @@ class InfluxPropertiesConfigAdapterTests { assertThat(adapter.token()).isEqualTo("token"); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(InfluxConfig.class, - InfluxPropertiesConfigAdapter.class); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java index e23a523d2d..87ef86171e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java @@ -18,10 +18,9 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.jmx; import java.time.Duration; -import io.micrometer.jmx.JmxConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -30,7 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class JmxPropertiesConfigAdapterTests { +class JmxPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + JmxPropertiesConfigAdapterTests() { + super(JmxPropertiesConfigAdapter.class); + } @Test void whenPropertiesStepIsSetAdapterStepReturnsIt() { @@ -46,10 +50,4 @@ class JmxPropertiesConfigAdapterTests { assertThat(new JmxPropertiesConfigAdapter(properties).domain()).isEqualTo("abc"); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(JmxConfig.class, - JmxPropertiesConfigAdapter.class); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java index 1915d0b8df..02c4e7019c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/kairos/KairosPropertiesConfigAdapterTests.java @@ -16,10 +16,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.kairos; -import io.micrometer.kairos.KairosConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -32,6 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat; class KairosPropertiesConfigAdapterTests extends StepRegistryPropertiesConfigAdapterTests { + KairosPropertiesConfigAdapterTests() { + super(KairosPropertiesConfigAdapter.class); + } + @Override protected KairosProperties createProperties() { return new KairosProperties(); @@ -64,10 +66,4 @@ class KairosPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).password()).isEqualTo("secret"); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(KairosConfig.class, - KairosPropertiesConfigAdapter.class); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java index 0d71eb7600..1b3dd086dd 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java @@ -17,10 +17,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic; import io.micrometer.newrelic.ClientProviderType; -import io.micrometer.newrelic.NewRelicConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -33,6 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; class NewRelicPropertiesConfigAdapterTests extends StepRegistryPropertiesConfigAdapterTests { + NewRelicPropertiesConfigAdapterTests() { + super(NewRelicPropertiesConfigAdapter.class); + } + @Override protected NewRelicProperties createProperties() { return new NewRelicProperties(); @@ -85,10 +87,4 @@ class NewRelicPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).uri()).isEqualTo("https://example.newrelic.com"); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(NewRelicConfig.class, - NewRelicPropertiesConfigAdapter.class); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java index 6d6abf0d77..68929bf7b6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java @@ -19,10 +19,9 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus import java.time.Duration; import io.micrometer.prometheus.HistogramFlavor; -import io.micrometer.prometheus.PrometheusConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -31,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class PrometheusPropertiesConfigAdapterTests { +class PrometheusPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + PrometheusPropertiesConfigAdapterTests() { + super(PrometheusPropertiesConfigAdapter.class); + } @Test void whenPropertiesDescriptionsIsSetAdapterDescriptionsReturnsIt() { @@ -55,10 +59,4 @@ class PrometheusPropertiesConfigAdapterTests { assertThat(new PrometheusPropertiesConfigAdapter(properties).step()).isEqualTo(Duration.ofSeconds(30)); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(PrometheusConfig.class, - PrometheusPropertiesConfigAdapter.class); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/AbstractPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/AbstractPropertiesConfigAdapterTests.java new file mode 100644 index 0000000000..edcd9736a4 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/AbstractPropertiesConfigAdapterTests.java @@ -0,0 +1,95 @@ +/* + * Copyright 2012-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.metrics.export.properties; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import io.micrometer.core.instrument.config.validate.Validated; +import org.junit.jupiter.api.Test; + +import org.springframework.core.annotation.AnnotatedElementUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Base class for testing properties config adapters. + * + * @param

the properties used by the adapter + * @param the adapter under test + * @author Andy Wilkinson + * @author Mirko Sobeck + */ +public abstract class AbstractPropertiesConfigAdapterTests> { + + private final Class adapter; + + protected AbstractPropertiesConfigAdapterTests(Class adapter) { + this.adapter = adapter; + } + + @Test + protected void adapterOverridesAllConfigMethods() { + adapterOverridesAllConfigMethodsExcept(); + } + + protected final void adapterOverridesAllConfigMethodsExcept(String... nonConfigMethods) { + Class config = findImplementedConfig(); + Set expectedConfigMethodNames = Arrays.stream(config.getDeclaredMethods()) + .filter(Method::isDefault) + .filter(this::hasNoParameters) + .filter(this::isNotValidationMethod) + .filter(this::isNotDeprecated) + .map(Method::getName) + .collect(Collectors.toCollection(TreeSet::new)); + expectedConfigMethodNames.removeAll(Arrays.asList(nonConfigMethods)); + Set actualConfigMethodNames = new TreeSet<>(); + Class currentClass = this.adapter; + while (!Object.class.equals(currentClass)) { + actualConfigMethodNames.addAll(Arrays.stream(currentClass.getDeclaredMethods()) + .map(Method::getName) + .filter(expectedConfigMethodNames::contains) + .collect(Collectors.toList())); + currentClass = currentClass.getSuperclass(); + } + assertThat(actualConfigMethodNames).containsExactlyInAnyOrderElementsOf(expectedConfigMethodNames); + } + + private Class findImplementedConfig() { + Class[] interfaces = this.adapter.getInterfaces(); + if (interfaces.length == 1) { + return interfaces[0]; + } + throw new IllegalStateException(this.adapter + " is not a config implementation"); + } + + private boolean isNotDeprecated(Method method) { + return !AnnotatedElementUtils.hasAnnotation(method, Deprecated.class); + } + + private boolean hasNoParameters(Method method) { + return method.getParameterCount() == 0; + } + + private boolean isNotValidationMethod(Method method) { + return !Validated.class.equals(method.getReturnType()); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/PushRegistryPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/PushRegistryPropertiesConfigAdapterTests.java index 29b2a1ec5c..f1023d398a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/PushRegistryPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/PushRegistryPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Stephane Nicoll * @author Artsiom Yudovin */ -public abstract class PushRegistryPropertiesConfigAdapterTests

> { +public abstract class PushRegistryPropertiesConfigAdapterTests

> + extends AbstractPropertiesConfigAdapterTests> { + + protected PushRegistryPropertiesConfigAdapterTests(Class adapter) { + super(adapter); + } protected abstract P createProperties(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/StepRegistryPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/StepRegistryPropertiesConfigAdapterTests.java index a0a9754b03..5124af840e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/StepRegistryPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/StepRegistryPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,4 +27,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.properties public abstract class StepRegistryPropertiesConfigAdapterTests

> extends PushRegistryPropertiesConfigAdapterTests { + protected StepRegistryPropertiesConfigAdapterTests(Class adapter) { + super(adapter); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java index 139a7d1906..d9f2b556c0 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxPropertiesConfigAdapterTests.java @@ -16,10 +16,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx; -import io.micrometer.signalfx.SignalFxConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType; @@ -33,6 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; class SignalFxPropertiesConfigAdapterTests extends StepRegistryPropertiesConfigAdapterTests { + protected SignalFxPropertiesConfigAdapterTests() { + super(SignalFxPropertiesConfigAdapter.class); + } + @Override protected SignalFxProperties createProperties() { SignalFxProperties signalFxProperties = new SignalFxProperties(); @@ -70,11 +72,6 @@ class SignalFxPropertiesConfigAdapterTests SignalFxProperties properties = createProperties(); properties.setPublishedHistogramType(HistogramType.CUMULATIVE); assertThat(createConfigAdapter(properties).publishCumulativeHistogram()).isTrue(); - - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(SignalFxConfig.class, - SignalFxPropertiesConfigAdapter.class, "publishDeltaHistogram", "publishCumulativeHistogram"); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java index 70dfe64407..5f977dc51c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java @@ -19,10 +19,9 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.simple; import java.time.Duration; import io.micrometer.core.instrument.simple.CountingMode; -import io.micrometer.core.instrument.simple.SimpleConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -31,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mirko Sobeck */ -class SimplePropertiesConfigAdapterTests { +class SimplePropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + SimplePropertiesConfigAdapterTests() { + super(SimplePropertiesConfigAdapter.class); + } @Test void whenPropertiesStepIsSetAdapterStepReturnsIt() { @@ -47,10 +51,4 @@ class SimplePropertiesConfigAdapterTests { assertThat(new SimplePropertiesConfigAdapter(properties).mode()).isEqualTo(CountingMode.STEP); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(SimpleConfig.class, - SimplePropertiesConfigAdapter.class); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java index 3af228cd04..b8cf09275e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java @@ -19,10 +19,9 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.stackdrive import java.util.HashMap; import java.util.Map; -import io.micrometer.stackdriver.StackdriverConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -31,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Johannes Graf */ -class StackdriverPropertiesConfigAdapterTests { +class StackdriverPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + StackdriverPropertiesConfigAdapterTests() { + super(StackdriverPropertiesConfigAdapter.class); + } @Test void whenPropertiesProjectIdIsSetAdapterProjectIdReturnsIt() { @@ -66,9 +70,9 @@ class StackdriverPropertiesConfigAdapterTests { } @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(StackdriverConfig.class, - StackdriverPropertiesConfigAdapter.class, "metricTypePrefix"); + @Override + protected void adapterOverridesAllConfigMethods() { + adapterOverridesAllConfigMethodsExcept("credentials"); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java index 24af397bd1..4fdfddfa90 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdPropertiesConfigAdapterTests.java @@ -18,12 +18,11 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.statsd; import java.time.Duration; -import io.micrometer.statsd.StatsdConfig; import io.micrometer.statsd.StatsdFlavor; import io.micrometer.statsd.StatsdProtocol; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Johnny Lim */ -class StatsdPropertiesConfigAdapterTests { +class StatsdPropertiesConfigAdapterTests + extends AbstractPropertiesConfigAdapterTests { + + protected StatsdPropertiesConfigAdapterTests() { + super(StatsdPropertiesConfigAdapter.class); + } @Test void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { @@ -107,10 +111,4 @@ class StatsdPropertiesConfigAdapterTests { assertThat(new StatsdPropertiesConfigAdapter(properties).buffered()).isEqualTo(properties.isBuffered()); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(StatsdConfig.class, - StatsdPropertiesConfigAdapter.class, "queueSize"); - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java index e49197c9e0..a8a82e8098 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontPropertiesConfigAdapterTests.java @@ -18,10 +18,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront; import java.net.URI; -import io.micrometer.wavefront.WavefrontConfig; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.metrics.export.TestConfigsToPropertiesExposure; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.PushRegistryPropertiesConfigAdapterTests; import static org.assertj.core.api.Assertions.assertThat; @@ -34,6 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat; class WavefrontPropertiesConfigAdapterTests extends PushRegistryPropertiesConfigAdapterTests { + protected WavefrontPropertiesConfigAdapterTests() { + super(WavefrontPropertiesConfigAdapter.class); + } + @Override protected WavefrontProperties createProperties() { return new WavefrontProperties(); @@ -93,11 +95,4 @@ class WavefrontPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).reportDayDistribution()).isTrue(); } - @Test - void allConfigDefaultMethodsAreOverriddenByAdapter() { - TestConfigsToPropertiesExposure.assertThatAllConfigDefaultMethodsAreOverriddenByAdapter(WavefrontConfig.class, - WavefrontPropertiesConfigAdapter.class, "distributionPort", "reportMinuteDistribution", - "reportHourDistribution", "reportDayDistribution"); - } - }