-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for auto-configuration fro micrometer support
- Loading branch information
1 parent
7c81df3
commit 5e250b8
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...ava/org/springframework/cloud/openfeign/FeignClientsMicrometerAutoConfigurationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2022-2022 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.cloud.openfeign; | ||
|
||
import feign.micrometer.MicrometerCapability; | ||
import feign.micrometer.MicrometerObservationCapability; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; | ||
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; | ||
import org.springframework.boot.actuate.autoconfigure.observation.ObservationAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.FilteredClassLoader; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Micrometer auto-configuration tests for {@link FeignClientsConfiguration}. | ||
* | ||
* @author Jonatan Ivanov | ||
*/ | ||
class FeignClientsMicrometerAutoConfigurationTests { | ||
|
||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration( | ||
AutoConfigurations.of(ObservationAutoConfiguration.class, SimpleMetricsExportAutoConfiguration.class, | ||
MetricsAutoConfiguration.class, FeignClientsConfiguration.class)); | ||
|
||
@Test | ||
void shouldProvideMicrometerObservationCapability() { | ||
contextRunner.run(context -> assertThat(context).hasSingleBean(MicrometerObservationCapability.class) | ||
.doesNotHaveBean(MicrometerCapability.class)); | ||
} | ||
|
||
@Test | ||
void shouldNotProvideMicrometerObservationCapabilityIfFeatureIsDisabled() { | ||
contextRunner.withPropertyValues("spring.cloud.openfeign.micrometer.enabled=false") | ||
.run(context -> assertThat(context).doesNotHaveBean(MicrometerObservationCapability.class) | ||
.doesNotHaveBean(MicrometerCapability.class)); | ||
} | ||
|
||
@Test | ||
void shouldProvideMicrometerCapabilityIfObservationRegistryIsMissing() { | ||
new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(SimpleMetricsExportAutoConfiguration.class, | ||
MetricsAutoConfiguration.class, FeignClientsConfiguration.class)) | ||
.run(context -> assertThat(context).doesNotHaveBean(MicrometerObservationCapability.class) | ||
.hasSingleBean(MicrometerCapability.class)); | ||
} | ||
|
||
@Test | ||
void shouldProvideMicrometerCapabilityIfMicrometerObservationCapabilityIsNotOnClasspath() { | ||
contextRunner.withClassLoader(new FilteredClassLoader(MicrometerObservationCapability.class)) | ||
.run(context -> assertThat(context).doesNotHaveBean(MicrometerObservationCapability.class) | ||
.hasSingleBean(MicrometerCapability.class)); | ||
} | ||
|
||
@Test | ||
void shouldNotProvideMicrometerCapabilitiesIfMicrometerSupportIsMissing() { | ||
contextRunner.withClassLoader(new FilteredClassLoader("feign.micrometer")).run(context -> assertThat(context) | ||
.doesNotHaveBean(MicrometerObservationCapability.class).doesNotHaveBean(MicrometerCapability.class)); | ||
} | ||
|
||
@Test | ||
void shouldNotProvideMicrometerCapabilitiesIfBeansAreMissing() { | ||
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(FeignClientsConfiguration.class)) | ||
.run(context -> assertThat(context).doesNotHaveBean(MicrometerObservationCapability.class) | ||
.doesNotHaveBean(MicrometerCapability.class)); | ||
} | ||
|
||
} |