|
|
|
@ -18,8 +18,12 @@ package org.springframework.boot.actuate.autoconfigure.wavefront;
|
|
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
|
|
|
|
|
import com.wavefront.sdk.common.clients.service.token.TokenService.Type;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
|
import org.junit.jupiter.params.provider.EnumSource;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.TokenType;
|
|
|
|
|
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
@ -34,21 +38,54 @@ class WavefrontPropertiesTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void apiTokenIsOptionalWhenUsingProxy() {
|
|
|
|
|
WavefrontProperties sut = new WavefrontProperties();
|
|
|
|
|
sut.setUri(URI.create("proxy://localhost:2878"));
|
|
|
|
|
sut.setApiToken(null);
|
|
|
|
|
assertThat(sut.getApiTokenOrThrow()).isNull();
|
|
|
|
|
assertThat(sut.getEffectiveUri()).isEqualTo(URI.create("http://localhost:2878"));
|
|
|
|
|
WavefrontProperties properties = new WavefrontProperties();
|
|
|
|
|
properties.setUri(URI.create("proxy://localhost:2878"));
|
|
|
|
|
properties.setApiToken(null);
|
|
|
|
|
assertThat(properties.getApiTokenOrThrow()).isNull();
|
|
|
|
|
assertThat(properties.getEffectiveUri()).isEqualTo(URI.create("http://localhost:2878"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void apiTokenIsMandatoryWhenNotUsingProxy() {
|
|
|
|
|
WavefrontProperties sut = new WavefrontProperties();
|
|
|
|
|
sut.setUri(URI.create("http://localhost:2878"));
|
|
|
|
|
sut.setApiToken(null);
|
|
|
|
|
assertThat(sut.getEffectiveUri()).isEqualTo(URI.create("http://localhost:2878"));
|
|
|
|
|
assertThatThrownBy(sut::getApiTokenOrThrow).isInstanceOf(InvalidConfigurationPropertyValueException.class)
|
|
|
|
|
WavefrontProperties properties = new WavefrontProperties();
|
|
|
|
|
properties.setUri(URI.create("http://localhost:2878"));
|
|
|
|
|
properties.setApiToken(null);
|
|
|
|
|
assertThat(properties.getEffectiveUri()).isEqualTo(URI.create("http://localhost:2878"));
|
|
|
|
|
assertThatThrownBy(properties::getApiTokenOrThrow)
|
|
|
|
|
.isInstanceOf(InvalidConfigurationPropertyValueException.class)
|
|
|
|
|
.hasMessageContaining("management.wavefront.api-token");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void shouldNotFailIfTokenTypeIsSetToNoToken() {
|
|
|
|
|
WavefrontProperties properties = new WavefrontProperties();
|
|
|
|
|
properties.setUri(URI.create("http://localhost:2878"));
|
|
|
|
|
properties.setApiTokenType(TokenType.NO_TOKEN);
|
|
|
|
|
properties.setApiToken(null);
|
|
|
|
|
assertThat(properties.getApiTokenOrThrow()).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void wavefrontApiTokenTypeWhenUsingProxy() {
|
|
|
|
|
WavefrontProperties properties = new WavefrontProperties();
|
|
|
|
|
properties.setUri(URI.create("proxy://localhost:2878"));
|
|
|
|
|
assertThat(properties.getWavefrontApiTokenType()).isEqualTo(Type.NO_TOKEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void wavefrontApiTokenTypeWhenNotUsingProxy() {
|
|
|
|
|
WavefrontProperties properties = new WavefrontProperties();
|
|
|
|
|
properties.setUri(URI.create("http://localhost:2878"));
|
|
|
|
|
assertThat(properties.getWavefrontApiTokenType()).isEqualTo(Type.WAVEFRONT_API_TOKEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest
|
|
|
|
|
@EnumSource(TokenType.class)
|
|
|
|
|
void wavefrontApiTokenMapping(TokenType from) {
|
|
|
|
|
WavefrontProperties properties = new WavefrontProperties();
|
|
|
|
|
properties.setApiTokenType(from);
|
|
|
|
|
Type expected = Type.valueOf(from.name());
|
|
|
|
|
assertThat(properties.getWavefrontApiTokenType()).isEqualTo(expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|