|
| 1 | +/* |
| 2 | + * Copyright 2012-2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.actuate.autoconfigure.metrics.export.statsd; |
| 18 | + |
| 19 | +import java.time.Duration; |
| 20 | + |
| 21 | +import io.micrometer.statsd.StatsdFlavor; |
| 22 | +import io.micrometer.statsd.StatsdProtocol; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +import static org.assertj.core.api.Assertions.assertThat; |
| 26 | + |
| 27 | +/** |
| 28 | + * Tests for {@link StatsdPropertiesConfigAdapter}. |
| 29 | + * |
| 30 | + * @author Johnny Lim |
| 31 | + */ |
| 32 | +class StatsdPropertiesConfigAdapterTests { |
| 33 | + |
| 34 | + @Test |
| 35 | + void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { |
| 36 | + StatsdProperties properties = new StatsdProperties(); |
| 37 | + properties.setEnabled(false); |
| 38 | + assertThat(new StatsdPropertiesConfigAdapter(properties).enabled()).isEqualTo(properties.isEnabled()); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void whenPropertiesFlavorIsSetAdapterFlavorReturnsIt() { |
| 43 | + StatsdProperties properties = new StatsdProperties(); |
| 44 | + properties.setFlavor(StatsdFlavor.ETSY); |
| 45 | + assertThat(new StatsdPropertiesConfigAdapter(properties).flavor()).isEqualTo(properties.getFlavor()); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + void whenPropertiesHostIsSetAdapterHostReturnsIt() { |
| 50 | + StatsdProperties properties = new StatsdProperties(); |
| 51 | + properties.setHost("my-host"); |
| 52 | + assertThat(new StatsdPropertiesConfigAdapter(properties).host()).isEqualTo(properties.getHost()); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + void whenPropertiesPortIsSetAdapterPortReturnsIt() { |
| 57 | + StatsdProperties properties = new StatsdProperties(); |
| 58 | + properties.setPort(1234); |
| 59 | + assertThat(new StatsdPropertiesConfigAdapter(properties).port()).isEqualTo(properties.getPort()); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + void whenPropertiesProtocolIsSetAdapterProtocolReturnsIt() { |
| 64 | + StatsdProperties properties = new StatsdProperties(); |
| 65 | + properties.setProtocol(StatsdProtocol.TCP); |
| 66 | + assertThat(new StatsdPropertiesConfigAdapter(properties).protocol()).isEqualTo(properties.getProtocol()); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + void whenPropertiesMaxPacketLengthIsSetAdapterMaxPacketLengthReturnsIt() { |
| 71 | + StatsdProperties properties = new StatsdProperties(); |
| 72 | + properties.setMaxPacketLength(1234); |
| 73 | + assertThat(new StatsdPropertiesConfigAdapter(properties).maxPacketLength()) |
| 74 | + .isEqualTo(properties.getMaxPacketLength()); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + void whenPropertiesPollingFrequencyIsSetAdapterPollingFrequencyReturnsIt() { |
| 79 | + StatsdProperties properties = new StatsdProperties(); |
| 80 | + properties.setPollingFrequency(Duration.ofSeconds(1)); |
| 81 | + assertThat(new StatsdPropertiesConfigAdapter(properties).pollingFrequency()) |
| 82 | + .isEqualTo(properties.getPollingFrequency()); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + void whenPropertiesStepIsSetAdapterStepReturnsIt() { |
| 87 | + StatsdProperties properties = new StatsdProperties(); |
| 88 | + properties.setStep(Duration.ofSeconds(1)); |
| 89 | + assertThat(new StatsdPropertiesConfigAdapter(properties).step()).isEqualTo(properties.getStep()); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + void whenPropertiesPublishUnchangedMetersIsSetAdapterPublishUnchangedMetersReturnsIt() { |
| 94 | + StatsdProperties properties = new StatsdProperties(); |
| 95 | + properties.setPublishUnchangedMeters(false); |
| 96 | + assertThat(new StatsdPropertiesConfigAdapter(properties).publishUnchangedMeters()) |
| 97 | + .isEqualTo(properties.isPublishUnchangedMeters()); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + void whenPropertiesBufferedIsSetAdapterBufferedReturnsIt() { |
| 102 | + StatsdProperties properties = new StatsdProperties(); |
| 103 | + properties.setBuffered(false); |
| 104 | + assertThat(new StatsdPropertiesConfigAdapter(properties).buffered()).isEqualTo(properties.isBuffered()); |
| 105 | + } |
| 106 | + |
| 107 | +} |
0 commit comments