From ff04f009c090e8712a1937ad19a9d6830bce5746 Mon Sep 17 00:00:00 2001 From: Mirko Sobeck Date: Tue, 10 Jan 2023 17:31:40 +0100 Subject: [PATCH] Add missing Micrometer PropertiesConfigAdapterTests Closes gh-33743 --- .../AtlasPropertiesConfigAdapterTests.java | 119 ++++++++++++++++++ .../DatadogPropertiesConfigAdapterTests.java | 54 ++++++-- .../dynatrace/DynatracePropertiesTests.java | 4 +- .../GangliaPropertiesConfigAdapterTests.java | 84 +++++++++++++ .../GraphitePropertiesConfigAdapterTests.java | 97 ++++++++++++++ .../jmx/JmxPropertiesConfigAdapterTests.java | 46 +++++++ .../NewRelicPropertiesConfigAdapterTests.java | 86 +++++++++++++ ...rometheusPropertiesConfigAdapterTests.java | 55 ++++++++ .../SignalFXPropertiesConfigAdapterTests.java | 65 ++++++++++ .../SimplePropertiesConfigAdapterTests.java | 49 ++++++++ 10 files changed, 651 insertions(+), 8 deletions(-) create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFXPropertiesConfigAdapterTests.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java 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 new file mode 100644 index 0000000000..48b777c69d --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/atlas/AtlasPropertiesConfigAdapterTests.java @@ -0,0 +1,119 @@ +/* + * 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.atlas; + +import java.time.Duration; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link AtlasPropertiesConfigAdapter}. + * + * @author Mirko Sobeck + */ +class AtlasPropertiesConfigAdapterTests { + + @Test + void whenPropertiesStepIsSetAdapterStepReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setStep(Duration.ofMinutes(15)); + assertThat(new AtlasPropertiesConfigAdapter(properties).step()).isEqualTo(Duration.ofMinutes(15)); + } + + @Test + void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setEnabled(false); + assertThat(new AtlasPropertiesConfigAdapter(properties).enabled()).isFalse(); + } + + @Test + void whenPropertiesConnectTimeoutIsSetAdapterConnectTimeoutReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setConnectTimeout(Duration.ofSeconds(12)); + assertThat(new AtlasPropertiesConfigAdapter(properties).connectTimeout()).isEqualTo(Duration.ofSeconds(12)); + } + + @Test + void whenPropertiesReadTimeoutIsSetAdapterReadTimeoutReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setReadTimeout(Duration.ofSeconds(42)); + assertThat(new AtlasPropertiesConfigAdapter(properties).readTimeout()).isEqualTo(Duration.ofSeconds(42)); + } + + @Test + void whenPropertiesNumThreadsIsSetAdapterNumThreadsReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setNumThreads(8); + assertThat(new AtlasPropertiesConfigAdapter(properties).numThreads()).isEqualTo(8); + } + + @Test + void whenPropertiesBatchSizeIsSetAdapterBatchSizeReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setBatchSize(10042); + assertThat(new AtlasPropertiesConfigAdapter(properties).batchSize()).isEqualTo(10042); + } + + @Test + void whenPropertiesUriIsSetAdapterUriReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setUri("https://atlas.example.com"); + assertThat(new AtlasPropertiesConfigAdapter(properties).uri()).isEqualTo("https://atlas.example.com"); + } + + @Test + void whenPropertiesLwcEnabledIsSetAdapterLwcEnabledReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setLwcEnabled(true); + assertThat(new AtlasPropertiesConfigAdapter(properties).lwcEnabled()).isTrue(); + } + + @Test + void whenPropertiesConfigRefreshFrequencyIsSetAdapterConfigRefreshFrequencyReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setConfigRefreshFrequency(Duration.ofMinutes(5)); + assertThat(new AtlasPropertiesConfigAdapter(properties).configRefreshFrequency()) + .isEqualTo(Duration.ofMinutes(5)); + } + + @Test + void whenPropertiesConfigTimeToLiveIsSetAdapterConfigTTLReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setConfigTimeToLive(Duration.ofMinutes(6)); + assertThat(new AtlasPropertiesConfigAdapter(properties).configTTL()).isEqualTo(Duration.ofMinutes(6)); + } + + @Test + void whenPropertiesConfigUriIsSetAdapterConfigUriReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setConfigUri("https://atlas.example.com/config"); + assertThat(new AtlasPropertiesConfigAdapter(properties).configUri()) + .isEqualTo("https://atlas.example.com/config"); + } + + @Test + void whenPropertiesEvalUriIsSetAdapterEvalUriReturnsIt() { + AtlasProperties properties = new AtlasProperties(); + properties.setEvalUri("https://atlas.example.com/evaluate"); + assertThat(new AtlasPropertiesConfigAdapter(properties).evalUri()) + .isEqualTo("https://atlas.example.com/evaluate"); + } + +} 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 622e3cc4a3..b47892c439 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 @@ -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. @@ -18,22 +18,62 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.datadog; import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; + import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link DatadogPropertiesConfigAdapter}. * * @author Stephane Nicoll + * @author Mirko Sobeck */ -class DatadogPropertiesConfigAdapterTests { +class DatadogPropertiesConfigAdapterTests + extends StepRegistryPropertiesConfigAdapterTests { + + @Override + protected DatadogProperties createProperties() { + return new DatadogProperties(); + } + + @Override + protected DatadogPropertiesConfigAdapter createConfigAdapter(DatadogProperties properties) { + return new DatadogPropertiesConfigAdapter(properties); + } + + @Test + void whenPropertiesApiKeyIsSetAdapterApiKeyReturnsIt() { + DatadogProperties properties = createProperties(); + properties.setApiKey("my-api-key"); + assertThat(createConfigAdapter(properties).apiKey()).isEqualTo("my-api-key"); + } + + @Test + void whenPropertiesApplicationKeyIsSetAdapterApplicationKeyReturnsIt() { + DatadogProperties properties = createProperties(); + properties.setApplicationKey("my-application-key"); + assertThat(createConfigAdapter(properties).applicationKey()).isEqualTo("my-application-key"); + } + + @Test + void whenPropertiesDescriptionsIsSetAdapterDescriptionsReturnsIt() { + DatadogProperties properties = createProperties(); + properties.setDescriptions(false); + assertThat(createConfigAdapter(properties).descriptions()).isEqualTo(false); + } + + @Test + void whenPropertiesHostTagIsSetAdapterHostTagReturnsIt() { + DatadogProperties properties = createProperties(); + properties.setHostTag("waldo"); + assertThat(createConfigAdapter(properties).hostTag()).isEqualTo("waldo"); + } @Test - void uriCanBeSet() { - DatadogProperties properties = new DatadogProperties(); + void whenPropertiesUriIsSetAdapterUriReturnsIt() { + DatadogProperties properties = createProperties(); properties.setUri("https://app.example.com/api/v1/series"); - properties.setApiKey("my-key"); - assertThat(new DatadogPropertiesConfigAdapter(properties).uri()) - .isEqualTo("https://app.example.com/api/v1/series"); + assertThat(createConfigAdapter(properties).uri()).isEqualTo("https://app.example.com/api/v1/series"); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesTests.java index 4a73aff6e6..b99e54aa41 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/dynatrace/DynatracePropertiesTests.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. @@ -38,6 +38,8 @@ class DynatracePropertiesTests extends StepRegistryPropertiesTests { assertStepRegistryDefaultValues(properties, config); assertThat(properties.getTechnologyType()).isEqualTo(config.technologyType()); assertThat(properties.getV1().getTechnologyType()).isEqualTo(config.technologyType()); + assertThat(properties.getV2().isUseDynatraceSummaryInstruments()) + .isEqualTo(config.useDynatraceSummaryInstruments()); } } 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 new file mode 100644 index 0000000000..3afd087f8b --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/ganglia/GangliaPropertiesConfigAdapterTests.java @@ -0,0 +1,84 @@ +/* + * 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.ganglia; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link GangliaPropertiesConfigAdapter}. + * + * @author Mirko Sobeck + */ +class GangliaPropertiesConfigAdapterTests { + + @Test + void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { + GangliaProperties properties = new GangliaProperties(); + properties.setEnabled(false); + assertThat(new GangliaPropertiesConfigAdapter(properties).enabled()).isFalse(); + } + + @Test + void whenPropertiesStepIsSetAdapterStepReturnsIt() { + GangliaProperties properties = new GangliaProperties(); + properties.setStep(Duration.ofMinutes(15)); + assertThat(new GangliaPropertiesConfigAdapter(properties).step()).isEqualTo(Duration.ofMinutes(15)); + } + + @Test + void whenPropertiesDurationUnitsIsSetAdapterDurationUnitsReturnsIt() { + GangliaProperties properties = new GangliaProperties(); + properties.setDurationUnits(TimeUnit.MINUTES); + assertThat(new GangliaPropertiesConfigAdapter(properties).durationUnits()).isEqualTo(TimeUnit.MINUTES); + } + + @Test + void whenPropertiesAddressingModeIsSetAdapterAddressingModeReturnsIt() { + GangliaProperties properties = new GangliaProperties(); + properties.setAddressingMode(UDPAddressingMode.UNICAST); + assertThat(new GangliaPropertiesConfigAdapter(properties).addressingMode()) + .isEqualTo(UDPAddressingMode.UNICAST); + } + + @Test + void whenPropertiesTimeToLiveIsSetAdapterTtlReturnsIt() { + GangliaProperties properties = new GangliaProperties(); + properties.setTimeToLive(2); + assertThat(new GangliaPropertiesConfigAdapter(properties).ttl()).isEqualTo(2); + } + + @Test + void whenPropertiesHostIsSetAdapterHostReturnsIt() { + GangliaProperties properties = new GangliaProperties(); + properties.setHost("node"); + assertThat(new GangliaPropertiesConfigAdapter(properties).host()).isEqualTo("node"); + } + + @Test + void whenPropertiesPortIsSetAdapterPortReturnsIt() { + GangliaProperties properties = new GangliaProperties(); + properties.setPort(4242); + assertThat(new GangliaPropertiesConfigAdapter(properties).port()).isEqualTo(4242); + } + +} 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 new file mode 100644 index 0000000000..68e6bef9cf --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapterTests.java @@ -0,0 +1,97 @@ +/* + * 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.graphite; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +import io.micrometer.graphite.GraphiteProtocol; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link GraphitePropertiesConfigAdapter}. + * + * @author Mirko Sobeck + */ +class GraphitePropertiesConfigAdapterTests { + + @Test + void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { + GraphiteProperties properties = new GraphiteProperties(); + properties.setEnabled(false); + assertThat(new GraphitePropertiesConfigAdapter(properties).enabled()).isFalse(); + } + + @Test + void whenPropertiesStepIsSetAdapterStepReturnsIt() { + GraphiteProperties properties = new GraphiteProperties(); + properties.setStep(Duration.ofMinutes(15)); + assertThat(new GraphitePropertiesConfigAdapter(properties).step()).isEqualTo(Duration.ofMinutes(15)); + } + + @Test + void whenPropertiesRateUnitsIsSetAdapterRateUnitsReturnsIt() { + GraphiteProperties properties = new GraphiteProperties(); + properties.setRateUnits(TimeUnit.MINUTES); + assertThat(new GraphitePropertiesConfigAdapter(properties).rateUnits()).isEqualTo(TimeUnit.MINUTES); + } + + @Test + void whenPropertiesDurationUnitsIsSetAdapterDurationUnitsReturnsIt() { + GraphiteProperties properties = new GraphiteProperties(); + properties.setRateUnits(TimeUnit.MINUTES); + assertThat(new GraphitePropertiesConfigAdapter(properties).rateUnits()).isEqualTo(TimeUnit.MINUTES); + } + + @Test + void whenPropertiesHostIsSetAdapterHostReturnsIt() { + GraphiteProperties properties = new GraphiteProperties(); + properties.setHost("node"); + assertThat(new GraphitePropertiesConfigAdapter(properties).host()).isEqualTo("node"); + } + + @Test + void whenPropertiesPortIsSetAdapterPortReturnsIt() { + GraphiteProperties properties = new GraphiteProperties(); + properties.setPort(4242); + assertThat(new GraphitePropertiesConfigAdapter(properties).port()).isEqualTo(4242); + } + + @Test + void whenPropertiesProtocolIsSetAdapterProtocolReturnsIt() { + GraphiteProperties properties = new GraphiteProperties(); + properties.setProtocol(GraphiteProtocol.UDP); + assertThat(new GraphitePropertiesConfigAdapter(properties).protocol()).isEqualTo(GraphiteProtocol.UDP); + } + + @Test + void whenPropertiesGraphiteTagsEnabledIsSetAdapterGraphiteTagsEnabledReturnsIt() { + GraphiteProperties properties = new GraphiteProperties(); + properties.setGraphiteTagsEnabled(true); + assertThat(new GraphitePropertiesConfigAdapter(properties).graphiteTagsEnabled()).isTrue(); + } + + @Test + void whenPropertiesTagsAsPrefixIsSetAdapterTagsAsPrefixReturnsIt() { + GraphiteProperties properties = new GraphiteProperties(); + properties.setTagsAsPrefix(new String[] { "worker" }); + assertThat(new GraphitePropertiesConfigAdapter(properties).tagsAsPrefix()).isEqualTo(new String[] { "worker" }); + } + +} 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 new file mode 100644 index 0000000000..6ee12bfd5a --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/jmx/JmxPropertiesConfigAdapterTests.java @@ -0,0 +1,46 @@ +/* + * 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.jmx; + +import java.time.Duration; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link JmxPropertiesConfigAdapter}. + * + * @author Mirko Sobeck + */ +class JmxPropertiesConfigAdapterTests { + + @Test + void whenPropertiesStepIsSetAdapterStepReturnsIt() { + JmxProperties properties = new JmxProperties(); + properties.setStep(Duration.ofMinutes(15)); + assertThat(new JmxPropertiesConfigAdapter(properties).step()).isEqualTo(Duration.ofMinutes(15)); + } + + @Test + void whenPropertiesDomainIsSetAdapterDomainReturnsIt() { + JmxProperties properties = new JmxProperties(); + properties.setDomain("abc"); + assertThat(new JmxPropertiesConfigAdapter(properties).domain()).isEqualTo("abc"); + } + +} 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 new file mode 100644 index 0000000000..5ef2fd99e7 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicPropertiesConfigAdapterTests.java @@ -0,0 +1,86 @@ +/* + * 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.newrelic; + +import io.micrometer.newrelic.ClientProviderType; +import org.junit.jupiter.api.Test; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link NewRelicPropertiesConfigAdapter}. + * + * @author Mirko Sobeck + */ +class NewRelicPropertiesConfigAdapterTests + extends StepRegistryPropertiesConfigAdapterTests { + + @Override + protected NewRelicProperties createProperties() { + return new NewRelicProperties(); + } + + @Override + protected NewRelicPropertiesConfigAdapter createConfigAdapter(NewRelicProperties properties) { + return new NewRelicPropertiesConfigAdapter(properties); + } + + @Test + void whenPropertiesMeterNameEventTypeEnabledIsSetAdapterMeterNameEventTypeEnabledReturnsIt() { + NewRelicProperties properties = createProperties(); + properties.setMeterNameEventTypeEnabled(true); + assertThat(createConfigAdapter(properties).meterNameEventTypeEnabled()).isEqualTo(true); + } + + @Test + void whenPropertiesEventTypeIsSetAdapterEventTypeReturnsIt() { + NewRelicProperties properties = createProperties(); + properties.setEventType("foo"); + assertThat(createConfigAdapter(properties).eventType()).isEqualTo("foo"); + } + + @Test + void whenPropertiesClientProviderTypeIsSetAdapterClientProviderTypeReturnsIt() { + NewRelicProperties properties = createProperties(); + properties.setClientProviderType(ClientProviderType.INSIGHTS_AGENT); + assertThat(createConfigAdapter(properties).clientProviderType()).isEqualTo(ClientProviderType.INSIGHTS_AGENT); + } + + @Test + void whenPropertiesApikeyIsSetAdapterApikeyReturnsIt() { + NewRelicProperties properties = createProperties(); + properties.setApiKey("my-key"); + assertThat(createConfigAdapter(properties).apiKey()).isEqualTo("my-key"); + } + + @Test + void whenPropertiesAccountIdIsSetAdapterAccountIdReturnsIt() { + NewRelicProperties properties = createProperties(); + properties.setAccountId("A38"); + assertThat(createConfigAdapter(properties).accountId()).isEqualTo("A38"); + } + + @Test + void whenPropertiesUriIsSetAdapterUriReturnsIt() { + NewRelicProperties properties = createProperties(); + properties.setUri("https://example.newrelic.com"); + assertThat(createConfigAdapter(properties).uri()).isEqualTo("https://example.newrelic.com"); + } + +} 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 new file mode 100644 index 0000000000..66aa5920aa --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesConfigAdapterTests.java @@ -0,0 +1,55 @@ +/* + * 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.prometheus; + +import java.time.Duration; + +import io.micrometer.prometheus.HistogramFlavor; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link PrometheusPropertiesConfigAdapter}. + * + * @author Mirko Sobeck + */ +class PrometheusPropertiesConfigAdapterTests { + + @Test + void whenPropertiesDescriptionsIsSetAdapterDescriptionsReturnsIt() { + PrometheusProperties properties = new PrometheusProperties(); + properties.setDescriptions(false); + assertThat(new PrometheusPropertiesConfigAdapter(properties).descriptions()).isFalse(); + } + + @Test + void whenPropertiesHistogramFlavorIsSetAdapterHistogramFlavorReturnsIt() { + PrometheusProperties properties = new PrometheusProperties(); + properties.setHistogramFlavor(HistogramFlavor.VictoriaMetrics); + assertThat(new PrometheusPropertiesConfigAdapter(properties).histogramFlavor()) + .isEqualTo(HistogramFlavor.VictoriaMetrics); + } + + @Test + void whenPropertiesStepIsSetAdapterStepReturnsIt() { + PrometheusProperties properties = new PrometheusProperties(); + properties.setStep(Duration.ofSeconds(30)); + assertThat(new PrometheusPropertiesConfigAdapter(properties).step()).isEqualTo(Duration.ofSeconds(30)); + } + +} 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 new file mode 100644 index 0000000000..03ed7435b5 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFXPropertiesConfigAdapterTests.java @@ -0,0 +1,65 @@ +/* + * 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.signalfx; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SignalFxPropertiesConfigAdapter}. + * + * @author Mirko Sobeck + */ +class SignalFXPropertiesConfigAdapterTests + extends StepRegistryPropertiesConfigAdapterTests { + + @Override + protected SignalFxProperties createProperties() { + SignalFxProperties signalFxProperties = new SignalFxProperties(); + signalFxProperties.setAccessToken("ABC"); + return signalFxProperties; + } + + @Override + protected SignalFxPropertiesConfigAdapter createConfigAdapter(SignalFxProperties properties) { + return new SignalFxPropertiesConfigAdapter(properties); + } + + @Test + void whenPropertiesAccessTokenIsSetAdapterAccessTokenReturnsIt() { + SignalFxProperties properties = createProperties(); + assertThat(createConfigAdapter(properties).accessToken()).isEqualTo("ABC"); + } + + @Test + void whenPropertiesUriIsSetAdapterUriReturnsIt() { + SignalFxProperties properties = createProperties(); + properties.setUri("https://example.signalfx.com"); + assertThat(createConfigAdapter(properties).uri()).isEqualTo("https://example.signalfx.com"); + } + + @Test + void whenPropertiesSourceIsSetAdapterSourceReturnsIt() { + SignalFxProperties properties = createProperties(); + properties.setSource("DESKTOP-GA5"); + assertThat(createConfigAdapter(properties).source()).isEqualTo("DESKTOP-GA5"); + } + +} 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 new file mode 100644 index 0000000000..c62ddaeebc --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesConfigAdapterTests.java @@ -0,0 +1,49 @@ +/* + * 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.simple; + +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.signalfx.SignalFxPropertiesConfigAdapter; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SignalFxPropertiesConfigAdapter}. + * + * @author Mirko Sobeck + */ +class SimplePropertiesConfigAdapterTests { + + @Test + void whenPropertiesStepIsSetAdapterStepReturnsIt() { + SimpleProperties properties = new SimpleProperties(); + properties.setStep(Duration.ofSeconds(30)); + assertThat(new SimplePropertiesConfigAdapter(properties).step()).isEqualTo(Duration.ofSeconds(30)); + } + + @Test + void whenPropertiesAccessTokenIsSetAdapterAccessTokenReturnsIt() { + SimpleProperties properties = new SimpleProperties(); + properties.setMode(CountingMode.STEP); + assertThat(new SimplePropertiesConfigAdapter(properties).mode()).isEqualTo(CountingMode.STEP); + } + +}