From 10988e89bf710106ceb6102053f9e2fff6f601fc Mon Sep 17 00:00:00 2001 From: Georg Pirklbauer Date: Fri, 11 Mar 2022 13:51:17 +0100 Subject: [PATCH] simplify tests after Dynatrace Metric Utils 1.5.0 release (#3065) --- .../FileBasedConfigurationTestHelper.java | 29 ------------------- .../dynatrace/DynatraceConfigTest.java | 14 +++++---- .../dynatrace/v2/DynatraceExporterV2Test.java | 8 ++--- 3 files changed, 12 insertions(+), 39 deletions(-) delete mode 100644 implementations/micrometer-registry-dynatrace/src/test/java/com/dynatrace/file/util/FileBasedConfigurationTestHelper.java diff --git a/implementations/micrometer-registry-dynatrace/src/test/java/com/dynatrace/file/util/FileBasedConfigurationTestHelper.java b/implementations/micrometer-registry-dynatrace/src/test/java/com/dynatrace/file/util/FileBasedConfigurationTestHelper.java deleted file mode 100644 index f1860a5695..0000000000 --- a/implementations/micrometer-registry-dynatrace/src/test/java/com/dynatrace/file/util/FileBasedConfigurationTestHelper.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright 2022 VMware, Inc. - * - * 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 com.dynatrace.file.util; - -/** - * This is needed because {@link DynatraceFileBasedConfigurationProvider#forceOverwriteConfig(String)} is not public. - * - * @author Georg Pirklbauer - */ -public class FileBasedConfigurationTestHelper { - // This allows overwriting the file location of the file-based configuration for testing. - public static void forceOverwriteConfig(String filename) { - DynatraceFileBasedConfigurationProvider.getInstance().forceOverwriteConfig(filename); - } -} diff --git a/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceConfigTest.java b/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceConfigTest.java index 07226ca653..6c095024b4 100644 --- a/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceConfigTest.java +++ b/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceConfigTest.java @@ -15,7 +15,7 @@ */ package io.micrometer.dynatrace; -import com.dynatrace.file.util.FileBasedConfigurationTestHelper; +import com.dynatrace.file.util.DynatraceFileBasedConfigurationProvider; import com.dynatrace.metric.util.DynatraceMetricApiConstants; import io.micrometer.core.instrument.config.validate.InvalidReason; import io.micrometer.core.instrument.config.validate.Validated; @@ -25,6 +25,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.time.Duration; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,7 +41,7 @@ class DynatraceConfigTest { @BeforeEach void setUp() { // Make sure that all tests use the default configuration, even if there's an `endpoint.properties` file in place - FileBasedConfigurationTestHelper.forceOverwriteConfig(nonExistentConfigFileName); + DynatraceFileBasedConfigurationProvider.getInstance().forceOverwriteConfig(nonExistentConfigFileName, Duration.ofMillis(50)); } @Test @@ -58,7 +59,7 @@ public DynatraceApiVersion apiVersion() { }; List> failures = config.validate().failures(); - assertThat(failures.size()).isEqualTo(3); + assertThat(failures).hasSize(3); assertThat(failures.stream().map(Validated::toString)).containsExactlyInAnyOrder( "Invalid{property='dynatrace.apiToken', value='null', message='is required'}", "Invalid{property='dynatrace.uri', value='null', message='is required'}", @@ -85,7 +86,7 @@ public DynatraceApiVersion apiVersion() { } }.validate(); - assertThat(validate.failures().size()).isEqualTo(4); + assertThat(validate.failures()).hasSize(4); assertThat(validate.failures().stream().map(Validated::toString)).containsExactlyInAnyOrder( "Invalid{property='dynatrace.apiToken', value='null', message='is required'}", "Invalid{property='dynatrace.uri', value='null', message='is required'}", @@ -113,7 +114,7 @@ public String uri() { } }.validate(); - assertThat(validate.failures().size()).isEqualTo(1); + assertThat(validate.failures()).hasSize(1); assertThat(validate.failures().stream().map(Validated::toString)).containsExactlyInAnyOrder( "Invalid{property='dynatrace.uri', value='null', message='is required'}" ); @@ -287,7 +288,8 @@ void testFileBasedConfig() throws IOException { ("DT_METRICS_INGEST_URL = https://your-dynatrace-ingest-url/api/v2/metrics/ingest\n" + "DT_METRICS_INGEST_API_TOKEN = YOUR.DYNATRACE.TOKEN").getBytes()); - FileBasedConfigurationTestHelper.forceOverwriteConfig(tempFile.toString()); + DynatraceFileBasedConfigurationProvider.getInstance().forceOverwriteConfig(tempFile.toString(), Duration.ofMillis(50)); + DynatraceConfig config = new DynatraceConfig() { @Override public String get(String key) { diff --git a/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/v2/DynatraceExporterV2Test.java b/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/v2/DynatraceExporterV2Test.java index 9eb586c84d..63a5910edf 100644 --- a/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/v2/DynatraceExporterV2Test.java +++ b/implementations/micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/v2/DynatraceExporterV2Test.java @@ -15,7 +15,7 @@ */ package io.micrometer.dynatrace.v2; -import com.dynatrace.file.util.FileBasedConfigurationTestHelper; +import com.dynatrace.file.util.DynatraceFileBasedConfigurationProvider; import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.*; import io.micrometer.core.ipc.http.HttpSender; @@ -538,7 +538,7 @@ public String get(String key) { ("DT_METRICS_INGEST_URL = " + firstUri + "\n" + "DT_METRICS_INGEST_API_TOKEN = YOUR.DYNATRACE.TOKEN.FIRST").getBytes()); - FileBasedConfigurationTestHelper.forceOverwriteConfig(tempFile.toString()); + DynatraceFileBasedConfigurationProvider.getInstance().forceOverwriteConfig(tempFile.toString(), Duration.ofMillis(50)); await().atMost(1, SECONDS).until(() -> config.uri().equals(firstUri)); Counter counter = meterRegistry.counter("test.counter"); counter.increment(10); @@ -549,7 +549,7 @@ public String get(String key) { verify(httpSender, times(1)).send(firstRequestCaptor.capture()); HttpSender.Request firstRequest = firstRequestCaptor.getValue(); - assertThat(firstRequest.getUrl().toString()).isEqualTo(firstUri); + assertThat(firstRequest.getUrl()).hasToString(firstUri); assertThat(firstRequest.getRequestHeaders()).containsOnly( entry("Content-Type", "text/plain"), entry("User-Agent", "micrometer"), @@ -573,7 +573,7 @@ public String get(String key) { verify(httpSender, times(2)).send(secondRequestCaptor.capture()); HttpSender.Request secondRequest = secondRequestCaptor.getValue(); - assertThat(secondRequest.getUrl().toString()).isEqualTo(secondUri); + assertThat(secondRequest.getUrl()).hasToString(secondUri); assertThat(secondRequest.getRequestHeaders()).containsOnly( entry("Content-Type", "text/plain"), entry("User-Agent", "micrometer"),