From d2a4c791d0fd7e92ae4a57b2113d014bee35d1e0 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 13 Apr 2023 23:42:23 +0000 Subject: [PATCH] fix(signalfx): Fixed metric type missing due to duplicated field from parent class (#957) (#958) (cherry picked from commit 179492b1d54aed59c825d0ef888c3445ca8e8ebd) Co-authored-by: Jason --- .../SignalFxNamedAccountCredentials.java | 7 ++- .../config/SignalFxConfigLoadTest.java | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 kayenta-signalfx/src/test/java/com/netflix/kayenta/signalfx/config/SignalFxConfigLoadTest.java diff --git a/kayenta-signalfx/src/main/java/com/netflix/kayenta/signalfx/security/SignalFxNamedAccountCredentials.java b/kayenta-signalfx/src/main/java/com/netflix/kayenta/signalfx/security/SignalFxNamedAccountCredentials.java index eeebd856e..beaad4357 100644 --- a/kayenta-signalfx/src/main/java/com/netflix/kayenta/signalfx/security/SignalFxNamedAccountCredentials.java +++ b/kayenta-signalfx/src/main/java/com/netflix/kayenta/signalfx/security/SignalFxNamedAccountCredentials.java @@ -21,9 +21,10 @@ import com.netflix.kayenta.retrofit.config.RemoteService; import com.netflix.kayenta.security.AccountCredentials; import com.netflix.kayenta.signalfx.service.SignalFxSignalFlowRemoteService; -import java.util.List; import javax.validation.constraints.NotNull; -import lombok.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.experimental.SuperBuilder; @Getter @@ -34,8 +35,6 @@ public class SignalFxNamedAccountCredentials extends AccountCredentials supportedTypes; - @NotNull private SignalFxCredentials credentials; @NotNull private RemoteService endpoint; diff --git a/kayenta-signalfx/src/test/java/com/netflix/kayenta/signalfx/config/SignalFxConfigLoadTest.java b/kayenta-signalfx/src/test/java/com/netflix/kayenta/signalfx/config/SignalFxConfigLoadTest.java new file mode 100644 index 000000000..92e213c34 --- /dev/null +++ b/kayenta-signalfx/src/test/java/com/netflix/kayenta/signalfx/config/SignalFxConfigLoadTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2023 Armory, Inc. + * + * 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 + * + * http://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 com.netflix.kayenta.signalfx.config; + +import static junit.framework.TestCase.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.netflix.kayenta.retrofit.config.RetrofitClientFactory; +import com.netflix.kayenta.security.AccountCredentials; +import com.netflix.kayenta.security.AccountCredentialsRepository; +import com.netflix.kayenta.security.MapBackedAccountCredentialsRepository; +import com.squareup.okhttp.OkHttpClient; +import java.util.List; +import org.junit.Test; + +public class SignalFxConfigLoadTest { + + private AccountCredentialsRepository accountRepo = new MapBackedAccountCredentialsRepository(); + + @Test + public void testThatConfigLoadFromAccountRendersCorrectly() { + SignalFxConfigurationProperties signalFxConfigurationProperties = + mock(SignalFxConfigurationProperties.class); + when(signalFxConfigurationProperties.getAccounts()) + .thenReturn(List.of(new SignalFxManagedAccount().setName("Test-account"))); + RetrofitClientFactory mockRetrofitFactory = mock(RetrofitClientFactory.class); + OkHttpClient mockOkHttpFactory = mock(OkHttpClient.class); + new SignalFxConfiguration() + .signalFxMetricService( + signalFxConfigurationProperties, mockRetrofitFactory, mockOkHttpFactory, accountRepo); + assertEquals("signalfx", accountRepo.getRequiredOne("Test-account").getType()); + assertEquals( + List.of(AccountCredentials.Type.METRICS_STORE), + accountRepo.getRequiredOne("Test-account").getSupportedTypes()); + } +}