Merge branch '3.1.x'

Closes gh-36568
pull/36572/head
Andy Wilkinson 1 year ago
commit df4c65e494

@ -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,6 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat;
class AppOpticsPropertiesConfigAdapterTests
extends StepRegistryPropertiesConfigAdapterTests<AppOpticsProperties, AppOpticsPropertiesConfigAdapter> {
AppOpticsPropertiesConfigAdapterTests() {
super(AppOpticsPropertiesConfigAdapter.class);
}
@Override
protected AppOpticsProperties createProperties() {
return new AppOpticsProperties();

@ -20,6 +20,8 @@ import java.time.Duration;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -27,7 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Mirko Sobeck
*/
class AtlasPropertiesConfigAdapterTests {
class AtlasPropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<AtlasProperties, AtlasPropertiesConfigAdapter> {
AtlasPropertiesConfigAdapterTests() {
super(AtlasPropertiesConfigAdapter.class);
}
@Test
void whenPropertiesStepIsSetAdapterStepReturnsIt() {
@ -130,4 +137,11 @@ class AtlasPropertiesConfigAdapterTests {
assertThat(new AtlasPropertiesConfigAdapter(properties).lwcIgnorePublishStep()).isFalse();
}
@Test
@Override
protected void adapterOverridesAllConfigMethods() {
adapterOverridesAllConfigMethodsExcept("autoStart", "commonTags", "debugRegistry", "publisher", "rollupPolicy",
"validTagCharacters");
}
}

@ -31,6 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
class DatadogPropertiesConfigAdapterTests
extends StepRegistryPropertiesConfigAdapterTests<DatadogProperties, DatadogPropertiesConfigAdapter> {
DatadogPropertiesConfigAdapterTests() {
super(DatadogPropertiesConfigAdapter.class);
}
@Override
protected DatadogProperties createProperties() {
return new DatadogProperties();

@ -21,6 +21,8 @@ import java.util.HashMap;
import io.micrometer.dynatrace.DynatraceApiVersion;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -29,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson
* @author Georg Pirklbauer
*/
class DynatracePropertiesConfigAdapterTests {
class DynatracePropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<DynatraceProperties, DynatracePropertiesConfigAdapter> {
DynatracePropertiesConfigAdapterTests() {
super(DynatracePropertiesConfigAdapter.class);
}
@Test
void whenPropertiesUriIsSetAdapterUriReturnsIt() {

@ -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.
@ -18,6 +18,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.elastic;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -25,7 +27,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
class ElasticPropertiesConfigAdapterTests {
class ElasticPropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<ElasticProperties, ElasticPropertiesConfigAdapter> {
ElasticPropertiesConfigAdapterTests() {
super(ElasticPropertiesConfigAdapter.class);
}
@Test
void whenPropertiesHostsIsSetAdapterHostsReturnsIt() {

@ -22,6 +22,8 @@ import java.util.concurrent.TimeUnit;
import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -29,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Mirko Sobeck
*/
class GangliaPropertiesConfigAdapterTests {
class GangliaPropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<GangliaProperties, GangliaPropertiesConfigAdapter> {
GangliaPropertiesConfigAdapterTests() {
super(GangliaPropertiesConfigAdapter.class);
}
@Test
void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() {

@ -22,6 +22,8 @@ import java.util.concurrent.TimeUnit;
import io.micrometer.graphite.GraphiteProtocol;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -29,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Mirko Sobeck
*/
class GraphitePropertiesConfigAdapterTests {
class GraphitePropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<GraphiteProperties, GraphitePropertiesConfigAdapter> {
GraphitePropertiesConfigAdapterTests() {
super(GraphitePropertiesConfigAdapter.class);
}
@Test
void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() {

@ -20,6 +20,8 @@ import java.util.Collections;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -27,7 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
class HumioPropertiesConfigAdapterTests {
class HumioPropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<HumioProperties, HumioPropertiesConfigAdapter> {
HumioPropertiesConfigAdapterTests() {
super(HumioPropertiesConfigAdapter.class);
}
@Test
void whenApiTokenIsSetAdapterApiTokenReturnsIt() {

@ -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.
@ -19,6 +19,8 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.influx;
import io.micrometer.influx.InfluxApiVersion;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -26,7 +28,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Stephane Nicoll
*/
class InfluxPropertiesConfigAdapterTests {
class InfluxPropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<InfluxProperties, InfluxPropertiesConfigAdapter> {
InfluxPropertiesConfigAdapterTests() {
super(InfluxPropertiesConfigAdapter.class);
}
@Test
void adaptInfluxV1BasicConfig() {

@ -20,6 +20,8 @@ import java.time.Duration;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -27,7 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Mirko Sobeck
*/
class JmxPropertiesConfigAdapterTests {
class JmxPropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<JmxProperties, JmxPropertiesConfigAdapter> {
JmxPropertiesConfigAdapterTests() {
super(JmxPropertiesConfigAdapter.class);
}
@Test
void whenPropertiesStepIsSetAdapterStepReturnsIt() {

@ -30,6 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat;
class KairosPropertiesConfigAdapterTests
extends StepRegistryPropertiesConfigAdapterTests<KairosProperties, KairosPropertiesConfigAdapter> {
KairosPropertiesConfigAdapterTests() {
super(KairosPropertiesConfigAdapter.class);
}
@Override
protected KairosProperties createProperties() {
return new KairosProperties();

@ -31,6 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
class NewRelicPropertiesConfigAdapterTests
extends StepRegistryPropertiesConfigAdapterTests<NewRelicProperties, NewRelicPropertiesConfigAdapter> {
NewRelicPropertiesConfigAdapterTests() {
super(NewRelicPropertiesConfigAdapter.class);
}
@Override
protected NewRelicProperties createProperties() {
return new NewRelicProperties();

@ -21,6 +21,8 @@ import java.time.Duration;
import io.micrometer.prometheus.HistogramFlavor;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -28,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Mirko Sobeck
*/
class PrometheusPropertiesConfigAdapterTests {
class PrometheusPropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<PrometheusProperties, PrometheusPropertiesConfigAdapter> {
PrometheusPropertiesConfigAdapterTests() {
super(PrometheusPropertiesConfigAdapter.class);
}
@Test
void whenPropertiesDescriptionsIsSetAdapterDescriptionsReturnsIt() {

@ -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 <P> the properties used by the adapter
* @param <A> the adapter under test
* @author Andy Wilkinson
* @author Mirko Sobeck
*/
public abstract class AbstractPropertiesConfigAdapterTests<P, A extends PropertiesConfigAdapter<P>> {
private final Class<? extends A> adapter;
protected AbstractPropertiesConfigAdapterTests(Class<? extends A> adapter) {
this.adapter = adapter;
}
@Test
protected void adapterOverridesAllConfigMethods() {
adapterOverridesAllConfigMethodsExcept();
}
protected final void adapterOverridesAllConfigMethodsExcept(String... nonConfigMethods) {
Class<?> config = findImplementedConfig();
Set<String> 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<String> actualConfigMethodNames = new TreeSet<>();
Class<?> currentClass = this.adapter;
while (!Object.class.equals(currentClass)) {
actualConfigMethodNames.addAll(Arrays.stream(currentClass.getDeclaredMethods())
.map(Method::getName)
.filter(expectedConfigMethodNames::contains)
.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());
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 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<P extends PushRegistryProperties, A extends PushRegistryPropertiesConfigAdapter<P>> {
public abstract class PushRegistryPropertiesConfigAdapterTests<P extends PushRegistryProperties, A extends PushRegistryPropertiesConfigAdapter<P>>
extends AbstractPropertiesConfigAdapterTests<P, PropertiesConfigAdapter<P>> {
protected PushRegistryPropertiesConfigAdapterTests(Class<A> adapter) {
super(adapter);
}
protected abstract P createProperties();

@ -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<P extends StepRegistryProperties, A extends StepRegistryPropertiesConfigAdapter<P>>
extends PushRegistryPropertiesConfigAdapterTests<P, A> {
protected StepRegistryPropertiesConfigAdapterTests(Class<A> adapter) {
super(adapter);
}
}

@ -31,6 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
class SignalFxPropertiesConfigAdapterTests
extends StepRegistryPropertiesConfigAdapterTests<SignalFxProperties, SignalFxPropertiesConfigAdapter> {
protected SignalFxPropertiesConfigAdapterTests() {
super(SignalFxPropertiesConfigAdapter.class);
}
@Override
protected SignalFxProperties createProperties() {
SignalFxProperties signalFxProperties = new SignalFxProperties();

@ -21,6 +21,8 @@ import java.time.Duration;
import io.micrometer.core.instrument.simple.CountingMode;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -28,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Mirko Sobeck
*/
class SimplePropertiesConfigAdapterTests {
class SimplePropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<SimpleProperties, SimplePropertiesConfigAdapter> {
SimplePropertiesConfigAdapterTests() {
super(SimplePropertiesConfigAdapter.class);
}
@Test
void whenPropertiesStepIsSetAdapterStepReturnsIt() {

@ -21,6 +21,8 @@ import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -28,7 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Johannes Graf
*/
class StackdriverPropertiesConfigAdapterTests {
class StackdriverPropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<StackdriverProperties, StackdriverPropertiesConfigAdapter> {
StackdriverPropertiesConfigAdapterTests() {
super(StackdriverPropertiesConfigAdapter.class);
}
@Test
void whenPropertiesProjectIdIsSetAdapterProjectIdReturnsIt() {
@ -70,4 +77,10 @@ class StackdriverPropertiesConfigAdapterTests {
.isEqualTo("external.googleapis.com/prometheus");
}
@Test
@Override
protected void adapterOverridesAllConfigMethods() {
adapterOverridesAllConfigMethodsExcept("credentials");
}
}

@ -22,6 +22,8 @@ import io.micrometer.statsd.StatsdFlavor;
import io.micrometer.statsd.StatsdProtocol;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.AbstractPropertiesConfigAdapterTests;
import static org.assertj.core.api.Assertions.assertThat;
/**
@ -29,7 +31,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Johnny Lim
*/
class StatsdPropertiesConfigAdapterTests {
class StatsdPropertiesConfigAdapterTests
extends AbstractPropertiesConfigAdapterTests<StatsdProperties, StatsdPropertiesConfigAdapter> {
protected StatsdPropertiesConfigAdapterTests() {
super(StatsdPropertiesConfigAdapter.class);
}
@Test
void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() {

@ -35,6 +35,10 @@ import static org.assertj.core.api.Assertions.assertThat;
class WavefrontPropertiesConfigAdapterTests extends
PushRegistryPropertiesConfigAdapterTests<WavefrontProperties.Metrics.Export, WavefrontPropertiesConfigAdapter> {
protected WavefrontPropertiesConfigAdapterTests() {
super(WavefrontPropertiesConfigAdapter.class);
}
@Override
protected WavefrontProperties.Metrics.Export createProperties() {
return new WavefrontProperties.Metrics.Export();

Loading…
Cancel
Save