Polish "Disable metrics export in integration tests"
See gh-21658
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -14,12 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.metrics;
|
||||
package org.springframework.boot.test.autoconfigure.actuate.metrics;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -33,13 +37,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@SpringBootTest
|
||||
class AutoConfigureMetricsMissingIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
@Test
|
||||
void customizerRunsAndOnlyEnablesSimpleMeterRegistryWhenNoAnnotationPresent(
|
||||
@Autowired ApplicationContext applicationContext) {
|
||||
assertThat(applicationContext.getBean(MeterRegistry.class)).isInstanceOf(SimpleMeterRegistry.class);
|
||||
assertThat(applicationContext.getBeansOfType(PrometheusMeterRegistry.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizerRunsAndSetsExclusionPropertiesWhenNoAnnotationPresent() {
|
||||
assertThat(this.environment.getProperty("management.metrics.export.enabled")).isEqualTo("false");
|
||||
assertThat(this.environment.getProperty("management.metrics.export.simple.enabled")).isEqualTo("true");
|
||||
void customizerRunsAndSetsExclusionPropertiesWhenNoAnnotationPresent(@Autowired Environment environment) {
|
||||
assertThat(environment.getProperty("management.metrics.export.defaults.enabled")).isEqualTo("false");
|
||||
assertThat(environment.getProperty("management.metrics.export.simple.enabled")).isEqualTo("true");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -14,12 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.metrics;
|
||||
package org.springframework.boot.test.autoconfigure.actuate.metrics;
|
||||
|
||||
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -34,13 +36,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@AutoConfigureMetrics
|
||||
class AutoConfigureMetricsPresentIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
@Test
|
||||
void customizerDoesNotDisableAvailableMeterRegistriesWhenAnnotationPresent(
|
||||
@Autowired ApplicationContext applicationContext) {
|
||||
assertThat(applicationContext.getBeansOfType(PrometheusMeterRegistry.class)).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizerDoesNotRunWhenAnnotationPresent() {
|
||||
assertThat(this.environment.containsProperty("management.metrics.export.enabled")).isFalse();
|
||||
assertThat(this.environment.containsProperty("management.metrics.export.simple.enabled")).isFalse();
|
||||
void customizerDoesNotSetExclusionPropertiesWhenAnnotationPresent(@Autowired Environment environment) {
|
||||
assertThat(environment.containsProperty("management.metrics.export.enabled")).isFalse();
|
||||
assertThat(environment.containsProperty("management.metrics.export.simple.enabled")).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.metrics;
|
||||
package org.springframework.boot.test.autoconfigure.actuate.metrics;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -14,7 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.metrics;
|
||||
package org.springframework.boot.test.autoconfigure.actuate.metrics;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -26,21 +28,23 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link AutoConfigureMetrics} and
|
||||
* {@link ExcludeMetricExportersContextCustomizerFactory} working together.
|
||||
* {@link MetricsExportContextCustomizerFactory} working together.
|
||||
*
|
||||
* @author Chris Bono
|
||||
*/
|
||||
class ExcludeMetricExportersContextCustomizerFactoryTests {
|
||||
class MetricsExportContextCustomizerFactoryTests {
|
||||
|
||||
private ExcludeMetricExportersContextCustomizerFactory factory = new ExcludeMetricExportersContextCustomizerFactory();
|
||||
private final MetricsExportContextCustomizerFactory factory = new MetricsExportContextCustomizerFactory();
|
||||
|
||||
@Test
|
||||
void getContextCustomizerWhenHasNoAnnotationShouldReturnCustomizer() {
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null);
|
||||
ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class,
|
||||
Collections.emptyList());
|
||||
assertThat(customizer).isNotNull();
|
||||
ConfigurableApplicationContext context = new GenericApplicationContext();
|
||||
customizer.customizeContext(context, null);
|
||||
assertThat(context.getEnvironment().getProperty("management.metrics.export.enabled")).isEqualTo("false");
|
||||
assertThat(context.getEnvironment().getProperty("management.metrics.export.defaults.enabled"))
|
||||
.isEqualTo("false");
|
||||
assertThat(context.getEnvironment().getProperty("management.metrics.export.simple.enabled")).isEqualTo("true");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.restdocs;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
|
||||
@@ -24,7 +25,7 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
|
||||
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class })
|
||||
public class RestDocsTestApplication {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user