Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 0747914

Browse files
authored
FF-249 SystemHealthShows Currently Active Profiles. (#57)
1 parent 9e7c846 commit 0747914

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

src/main/java/de/filefighter/rest/domain/health/business/SystemHealthBusinessService.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import de.filefighter.rest.domain.token.business.AccessTokenBusinessService;
77
import de.filefighter.rest.domain.user.business.UserBusinessService;
88
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.core.env.Environment;
910
import org.springframework.stereotype.Service;
1011

1112
import java.time.Instant;
@@ -16,16 +17,19 @@ public class SystemHealthBusinessService {
1617
private final UserBusinessService userBusinessService;
1718
private final AccessTokenBusinessService accessTokenBusinessService;
1819
private final FileSystemBusinessService fileSystemBusinessService;
20+
private final Environment environment;
21+
1922
private final long serverStartedAt;
2023
private DataIntegrity cachedIntegrity = DataIntegrity.STABLE;
2124

2225
@Value("${filefighter.version}")
2326
String version;
2427

25-
public SystemHealthBusinessService(UserBusinessService userBusinessService, AccessTokenBusinessService accessTokenBusinessService, FileSystemBusinessService fileSystemBusinessService) {
28+
public SystemHealthBusinessService(UserBusinessService userBusinessService, AccessTokenBusinessService accessTokenBusinessService, FileSystemBusinessService fileSystemBusinessService, Environment environment) {
2629
this.userBusinessService = userBusinessService;
2730
this.accessTokenBusinessService = accessTokenBusinessService;
2831
this.fileSystemBusinessService = fileSystemBusinessService;
32+
this.environment = environment;
2933
this.serverStartedAt = this.getCurrentEpochSeconds();
3034
}
3135

@@ -36,10 +40,22 @@ public SystemHealth getCurrentSystemHealthInfo() {
3640
.userCount(userBusinessService.getUserCount())
3741
.usedStorageInMb(fileSystemBusinessService.getTotalFileSize())
3842
.dataIntegrity(calculateDataIntegrity())
43+
.deployment(getDeploymentStatus())
3944
.version("v" + this.version)
4045
.build();
4146
}
4247

48+
public String getDeploymentStatus() {
49+
String[] profiles = environment.getActiveProfiles();
50+
51+
StringBuilder deploymentStatus = new StringBuilder();
52+
53+
for (String profile : profiles) {
54+
deploymentStatus.append(profile).append(" ");
55+
}
56+
return deploymentStatus.toString().strip();
57+
}
58+
4359
private DataIntegrity calculateDataIntegrity() {
4460
long userCount = userBusinessService.getUserCount();
4561
long accessTokenCount = accessTokenBusinessService.getAccessTokenCount();

src/main/java/de/filefighter/rest/domain/health/data/SystemHealth.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class SystemHealth {
1414
private final long userCount;
1515
private final double usedStorageInMb;
1616
private final DataIntegrity dataIntegrity;
17+
private final String deployment;
1718
private final String version;
1819

1920
public enum DataIntegrity {

src/test/java/de/filefighter/rest/domain/health/business/SystemHealthBusinessServiceUnitTest.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import de.filefighter.rest.domain.user.business.UserBusinessService;
88
import org.junit.jupiter.api.BeforeEach;
99
import org.junit.jupiter.api.Test;
10+
import org.springframework.core.env.Environment;
1011

1112
import java.time.Instant;
1213

@@ -19,12 +20,13 @@ class SystemHealthBusinessServiceUnitTest {
1920

2021
private final UserBusinessService userBusinessServiceMock = mock(UserBusinessService.class);
2122
private final AccessTokenBusinessService accessTokenBusinessServiceMock = mock(AccessTokenBusinessService.class);
22-
private final FileSystemBusinessService fileSystemBusinessService = mock(FileSystemBusinessService.class);
23+
private final FileSystemBusinessService fileSystemBusinessServiceMock = mock(FileSystemBusinessService.class);
24+
private final Environment environmentMock = mock(Environment.class);
2325
private SystemHealthBusinessService systemHealthBusinessService;
2426

2527
@BeforeEach
2628
void setUp() {
27-
systemHealthBusinessService = new SystemHealthBusinessService(userBusinessServiceMock, accessTokenBusinessServiceMock, fileSystemBusinessService);
29+
systemHealthBusinessService = new SystemHealthBusinessService(userBusinessServiceMock, accessTokenBusinessServiceMock, fileSystemBusinessServiceMock, environmentMock);
2830
}
2931

3032
@Test
@@ -33,7 +35,8 @@ void getCurrentSystemHealthInfo() {
3335
double expectedSize = 1234.532;
3436

3537
when(userBusinessServiceMock.getUserCount()).thenReturn(expectedUserCount);
36-
when(fileSystemBusinessService.getTotalFileSize()).thenReturn(expectedSize);
38+
when(fileSystemBusinessServiceMock.getTotalFileSize()).thenReturn(expectedSize);
39+
when(environmentMock.getActiveProfiles()).thenReturn(new String[]{"test"});
3740

3841
SystemHealth systemHealth = systemHealthBusinessService.getCurrentSystemHealthInfo();
3942

@@ -50,9 +53,10 @@ void getCurrentEpochSecondsReturnsEpochSeconds() {
5053
}
5154

5255
@Test
53-
void calculateDataIntegrityReturnsStable(){
56+
void calculateDataIntegrityReturnsStable() {
5457
when(userBusinessServiceMock.getUserCount()).thenReturn(2L);
5558
when(accessTokenBusinessServiceMock.getAccessTokenCount()).thenReturn(2L);
59+
when(environmentMock.getActiveProfiles()).thenReturn(new String[]{"test"});
5660

5761
DataIntegrity dataIntegrity = DataIntegrity.STABLE;
5862
DataIntegrity actual = systemHealthBusinessService.getCurrentSystemHealthInfo().getDataIntegrity();
@@ -67,12 +71,24 @@ void calculateDataIntegrityReturnsStable(){
6771
}
6872

6973
@Test
70-
void calculateDataIntegrityReturnsRisk(){
74+
void calculateDataIntegrityReturnsRisk() {
7175
when(userBusinessServiceMock.getUserCount()).thenReturn(2L);
7276
when(accessTokenBusinessServiceMock.getAccessTokenCount()).thenReturn(3L);
77+
when(environmentMock.getActiveProfiles()).thenReturn(new String[]{"test"});
7378

7479
DataIntegrity dataIntegrity = DataIntegrity.POSSIBLE_RISK;
7580
DataIntegrity actual = systemHealthBusinessService.getCurrentSystemHealthInfo().getDataIntegrity();
7681
assertEquals(dataIntegrity, actual);
7782
}
83+
84+
@Test
85+
void getDeploymentStatusWorks() {
86+
String string0 = "dev";
87+
String string1 = "non-prod";
88+
String string2 = "stage";
89+
90+
when(environmentMock.getActiveProfiles()).thenReturn(new String[]{string0, string1, string2});
91+
92+
assertEquals(string0 + " " + string1 + " " + string2, systemHealthBusinessService.getDeploymentStatus());
93+
}
7894
}

0 commit comments

Comments
 (0)