Skip to content

Commit

Permalink
simplify tests after Dynatrace Metric Utils 1.5.0 release (#3065)
Browse files Browse the repository at this point in the history
  • Loading branch information
pirgeo authored Mar 11, 2022
1 parent 0666b7c commit 10988e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 39 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -58,7 +59,7 @@ public DynatraceApiVersion apiVersion() {
};

List<Validated.Invalid<?>> 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'}",
Expand All @@ -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'}",
Expand Down Expand Up @@ -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'}"
);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down

0 comments on commit 10988e8

Please sign in to comment.