Skip to content

Commit 029d495

Browse files
committed
Fix SSL metrics for dynamically registered bundles
Also add regression test and adjust imports in SslMeterBinderTests.
1 parent 195528f commit 029d495

File tree

1 file changed

+16
-16
lines changed
  • module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/ssl

1 file changed

+16
-16
lines changed

module/spring-boot-micrometer-metrics/src/test/java/org/springframework/boot/micrometer/metrics/autoconfigure/ssl/SslMeterBinderTests.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.time.Duration;
2121
import java.time.Instant;
2222
import java.time.ZoneId;
23+
import java.util.Collections;
24+
import java.util.List;
2325

2426
import io.micrometer.core.instrument.MeterRegistry;
2527
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
@@ -34,12 +36,10 @@
3436
import org.springframework.boot.ssl.jks.JksSslStoreDetails;
3537

3638
import static org.assertj.core.api.Assertions.assertThat;
37-
import java.util.List;
38-
39+
import static org.mockito.BDDMockito.given;
40+
import static org.mockito.BDDMockito.then;
3941
import static org.mockito.Mockito.atLeast;
4042
import static org.mockito.Mockito.mock;
41-
import static org.mockito.Mockito.verify;
42-
import static org.mockito.Mockito.when;
4343

4444
/**
4545
* Tests for {@link SslMeterBinder}.
@@ -73,25 +73,25 @@ void shouldRegisterChainExpiryMetrics() {
7373
void shouldWatchUpdatesForBundlesRegisteredAfterConstruction() {
7474
DefaultSslBundleRegistry sslBundleRegistry = new DefaultSslBundleRegistry();
7575
SslInfo sslInfo = mock(SslInfo.class);
76-
when(sslInfo.getBundles()).thenReturn(List.of());
76+
given(sslInfo.getBundles()).willReturn(Collections.emptyList());
7777

7878
SslInfo.BundleInfo bundleInfo = mock(SslInfo.BundleInfo.class);
7979
SslInfo.CertificateChainInfo chainInfo = mock(SslInfo.CertificateChainInfo.class);
8080
SslInfo.CertificateInfo certificateInfo = mock(SslInfo.CertificateInfo.class);
8181
SslInfo.CertificateValidityInfo validityInfo = mock(SslInfo.CertificateValidityInfo.class);
8282

83-
when(sslInfo.getBundle("dynamic")).thenReturn(bundleInfo);
84-
when(bundleInfo.getName()).thenReturn("dynamic");
85-
when(bundleInfo.getCertificateChains()).thenReturn(List.of(chainInfo));
86-
when(chainInfo.getAlias()).thenReturn("server");
87-
when(chainInfo.getCertificates()).thenReturn(List.of(certificateInfo));
88-
when(certificateInfo.getSerialNumber()).thenReturn("serial");
83+
given(sslInfo.getBundle("dynamic")).willReturn(bundleInfo);
84+
given(bundleInfo.getName()).willReturn("dynamic");
85+
given(bundleInfo.getCertificateChains()).willReturn(List.of(chainInfo));
86+
given(chainInfo.getAlias()).willReturn("server");
87+
given(chainInfo.getCertificates()).willReturn(List.of(certificateInfo));
88+
given(certificateInfo.getSerialNumber()).willReturn("serial");
8989

9090
Instant expiry = CLOCK.instant().plus(Duration.ofDays(365));
91-
when(certificateInfo.getValidityEnds()).thenReturn(expiry);
92-
when(certificateInfo.getValidity()).thenReturn(validityInfo);
93-
when(validityInfo.getStatus()).thenReturn(SslInfo.CertificateValidityInfo.Status.VALID);
94-
when(validityInfo.getMessage()).thenReturn(null);
91+
given(certificateInfo.getValidityEnds()).willReturn(expiry);
92+
given(certificateInfo.getValidity()).willReturn(validityInfo);
93+
given(validityInfo.getStatus()).willReturn(SslInfo.CertificateValidityInfo.Status.VALID);
94+
given(validityInfo.getMessage()).willReturn(null);
9595

9696
SslMeterBinder binder = new SslMeterBinder(sslInfo, sslBundleRegistry, CLOCK);
9797
SimpleMeterRegistry meterRegistry = new SimpleMeterRegistry();
@@ -101,7 +101,7 @@ void shouldWatchUpdatesForBundlesRegisteredAfterConstruction() {
101101
sslBundleRegistry.registerBundle("dynamic", bundle);
102102
sslBundleRegistry.updateBundle("dynamic", bundle);
103103

104-
verify(sslInfo, atLeast(2)).getBundle("dynamic");
104+
then(sslInfo).should(atLeast(2)).getBundle("dynamic");
105105
}
106106

107107
private static long findExpiryGauge(MeterRegistry meterRegistry, String chain, String certificateSerialNumber) {

0 commit comments

Comments
 (0)