generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Suppression date update: * Added infra and pipeline set up * Bumping chart version/ fixing aliases * Added main launch darkly code * Added unit tests * Added int test * load secrets after test for int * Added debug * Switched around test package for LD test * clean up * Moved to smoke tests * Update int props * Removed not needed func test --------- Co-authored-by: hmcts-jenkins-j-to-z <61242337+hmcts-jenkins-j-to-z[bot]@users.noreply.github.com>
- Loading branch information
1 parent
309a01c
commit 5185f4f
Showing
17 changed files
with
255 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
24 changes: 24 additions & 0 deletions
24
src/main/java/uk/gov/hmcts/reform/notificationservice/controller/FeatureFlagController.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,24 @@ | ||
package uk.gov.hmcts.reform.notificationservice.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import uk.gov.hmcts.reform.notificationservice.launchdarkly.LaunchDarklyClient; | ||
|
||
import static org.springframework.http.ResponseEntity.ok; | ||
|
||
@RestController | ||
public class FeatureFlagController { | ||
private final LaunchDarklyClient featureToggleService; | ||
|
||
public FeatureFlagController(LaunchDarklyClient featureToggleService) { | ||
this.featureToggleService = featureToggleService; | ||
} | ||
|
||
@GetMapping("/feature-flags/{flag}") | ||
public ResponseEntity<String> flagStatus(@PathVariable String flag) { | ||
boolean isEnabled = featureToggleService.isFeatureEnabled(flag); | ||
return ok(flag + " : " + isEnabled); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/uk/gov/hmcts/reform/notificationservice/launchdarkly/Flags.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,9 @@ | ||
package uk.gov.hmcts.reform.notificationservice.launchdarkly; | ||
|
||
public final class Flags { | ||
private Flags() { | ||
|
||
} | ||
|
||
public static final String REFORM_SCAN_NOTIFICATION_SERVICE_TEST = "reform-scan-notification-service-test"; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/uk/gov/hmcts/reform/notificationservice/launchdarkly/LaunchDarklyClient.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,41 @@ | ||
package uk.gov.hmcts.reform.notificationservice.launchdarkly; | ||
|
||
|
||
import com.launchdarkly.sdk.LDUser; | ||
import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider; | ||
import com.launchdarkly.sdk.server.interfaces.LDClientInterface; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class LaunchDarklyClient { | ||
public static final LDUser REFORM_SCAN_NOTIFICATION_SERVICE_USER = new LDUser.Builder("reform-scan-notification" | ||
+ "-service") | ||
.anonymous(true) | ||
.build(); | ||
|
||
private final LDClientInterface internalClient; | ||
|
||
@Autowired | ||
public LaunchDarklyClient( | ||
LaunchDarklyClientFactory launchDarklyClientFactory, | ||
@Value("${launchdarkly.sdk-key:YYYYY}") String sdkKey, | ||
@Value("${launchdarkly.offline-mode:false}") Boolean offlineMode | ||
) { | ||
this.internalClient = launchDarklyClientFactory.create(sdkKey, offlineMode); | ||
} | ||
|
||
public boolean isFeatureEnabled(String feature) { | ||
return internalClient.boolVariation(feature, LaunchDarklyClient.REFORM_SCAN_NOTIFICATION_SERVICE_USER, | ||
false); | ||
} | ||
|
||
public boolean isFeatureEnabled(String feature, LDUser user) { | ||
return internalClient.boolVariation(feature, user, false); | ||
} | ||
|
||
public DataSourceStatusProvider.Status getDataSourceStatus() { | ||
return internalClient.getDataSourceStatusProvider().getStatus(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../java/uk/gov/hmcts/reform/notificationservice/launchdarkly/LaunchDarklyClientFactory.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,16 @@ | ||
package uk.gov.hmcts.reform.notificationservice.launchdarkly; | ||
|
||
import com.launchdarkly.sdk.server.LDClient; | ||
import com.launchdarkly.sdk.server.LDConfig; | ||
import com.launchdarkly.sdk.server.interfaces.LDClientInterface; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class LaunchDarklyClientFactory { | ||
public LDClientInterface create(String sdkKey, boolean offlineMode) { | ||
LDConfig config = new LDConfig.Builder() | ||
.offline(offlineMode) | ||
.build(); | ||
return new LDClient(sdkKey, config); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/smokeTest/java/uk/gov/hmcts/reform/notificationservice/LaunchDarklySmokeTest.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,42 @@ | ||
package uk.gov.hmcts.reform.notificationservice; | ||
|
||
import com.launchdarkly.sdk.server.interfaces.DataSourceStatusProvider; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import uk.gov.hmcts.reform.notificationservice.launchdarkly.LaunchDarklyClient; | ||
import uk.gov.hmcts.reform.notificationservice.launchdarkly.LaunchDarklyClientFactory; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@TestPropertySource("classpath:application.conf") | ||
@ExtendWith(SpringExtension.class) | ||
class LaunchDarklySmokeTest { | ||
|
||
@MockBean | ||
private LaunchDarklyClient ldClient; | ||
@MockBean | ||
private LaunchDarklyClientFactory ldFactory; | ||
|
||
@Value("${sdk-key:YYYYY}") | ||
private String sdkKey; | ||
|
||
@Value("${offline-mode:false}") | ||
private Boolean offlineMode; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
ldFactory = new LaunchDarklyClientFactory(); | ||
ldClient = new LaunchDarklyClient(ldFactory, sdkKey, offlineMode); | ||
} | ||
|
||
@Test | ||
void checkLaunchDarklyStatus() { | ||
DataSourceStatusProvider.Status ldStatus = ldClient.getDataSourceStatus(); | ||
assertThat(ldStatus.getState()).isEqualTo(DataSourceStatusProvider.State.VALID); | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
...smokeTest/java/uk/gov/hmcts/reform/notificationservice/NotificationServiceHealthTest.java
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
test-url = "http://localhost:8583" | ||
test-url = ${?TEST_URL} | ||
offline-mode=${LAUNCH_DARKLY_OFFLINE_MODE} | ||
sdk-key=${LAUNCH_DARKLY_SDK_KEY} |
25 changes: 25 additions & 0 deletions
25
...a/uk/gov/hmcts/reform/notificationservice/launchdarkly/LaunchDarklyClientFactoryTest.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,25 @@ | ||
package uk.gov.hmcts.reform.notificationservice.launchdarkly; | ||
|
||
import com.launchdarkly.sdk.server.interfaces.LDClientInterface; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class LaunchDarklyClientFactoryTest { | ||
private LaunchDarklyClientFactory factory; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
factory = new LaunchDarklyClientFactory(); | ||
} | ||
|
||
@Test | ||
void testCreate() throws IOException { | ||
try (LDClientInterface client = factory.create("test key", true)) { | ||
assertThat(client).isNotNull(); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...est/java/uk/gov/hmcts/reform/notificationservice/launchdarkly/LaunchDarklyClientTest.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,63 @@ | ||
package uk.gov.hmcts.reform.notificationservice.launchdarkly; | ||
|
||
import com.launchdarkly.sdk.LDUser; | ||
import com.launchdarkly.sdk.server.interfaces.LDClientInterface; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyBoolean; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class LaunchDarklyClientTest { | ||
private static final String SDK_KEY = "fake-key"; | ||
private static final String FAKE_FEATURE = "fake-feature"; | ||
|
||
@Mock | ||
private LaunchDarklyClientFactory launchDarklyClientFactory; | ||
|
||
@Mock | ||
private LDClientInterface ldClient; | ||
|
||
@Mock | ||
private LDUser ldUser; | ||
|
||
private LaunchDarklyClient launchDarklyClient; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
when(launchDarklyClientFactory.create(eq(SDK_KEY), anyBoolean())).thenReturn(ldClient); | ||
launchDarklyClient = new LaunchDarklyClient(launchDarklyClientFactory, SDK_KEY, true); | ||
} | ||
|
||
@Test | ||
void testFeatureEnabled() { | ||
when(ldClient.boolVariation(eq(FAKE_FEATURE), any(LDUser.class), anyBoolean())).thenReturn(true); | ||
assertTrue(launchDarklyClient.isFeatureEnabled(FAKE_FEATURE, ldUser)); | ||
} | ||
|
||
@Test | ||
void testFeatureDisabled() { | ||
when(ldClient.boolVariation(eq(FAKE_FEATURE), any(LDUser.class), anyBoolean())).thenReturn(false); | ||
assertFalse(launchDarklyClient.isFeatureEnabled(FAKE_FEATURE, ldUser)); | ||
} | ||
|
||
@Test | ||
void testFeatureEnabledWithoutUser() { | ||
when(ldClient.boolVariation(eq(FAKE_FEATURE), any(LDUser.class), anyBoolean())).thenReturn(true); | ||
assertTrue(launchDarklyClient.isFeatureEnabled(FAKE_FEATURE)); | ||
} | ||
|
||
@Test | ||
void testFeatureDisabledWithoutUser() { | ||
when(ldClient.boolVariation(eq(FAKE_FEATURE), any(LDUser.class), anyBoolean())).thenReturn(false); | ||
assertFalse(launchDarklyClient.isFeatureEnabled(FAKE_FEATURE)); | ||
} | ||
} |