7
7
import de .filefighter .rest .domain .user .business .UserBusinessService ;
8
8
import org .junit .jupiter .api .BeforeEach ;
9
9
import org .junit .jupiter .api .Test ;
10
+ import org .springframework .core .env .Environment ;
10
11
11
12
import java .time .Instant ;
12
13
@@ -19,12 +20,13 @@ class SystemHealthBusinessServiceUnitTest {
19
20
20
21
private final UserBusinessService userBusinessServiceMock = mock (UserBusinessService .class );
21
22
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 );
23
25
private SystemHealthBusinessService systemHealthBusinessService ;
24
26
25
27
@ BeforeEach
26
28
void setUp () {
27
- systemHealthBusinessService = new SystemHealthBusinessService (userBusinessServiceMock , accessTokenBusinessServiceMock , fileSystemBusinessService );
29
+ systemHealthBusinessService = new SystemHealthBusinessService (userBusinessServiceMock , accessTokenBusinessServiceMock , fileSystemBusinessServiceMock , environmentMock );
28
30
}
29
31
30
32
@ Test
@@ -33,7 +35,8 @@ void getCurrentSystemHealthInfo() {
33
35
double expectedSize = 1234.532 ;
34
36
35
37
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" });
37
40
38
41
SystemHealth systemHealth = systemHealthBusinessService .getCurrentSystemHealthInfo ();
39
42
@@ -50,9 +53,10 @@ void getCurrentEpochSecondsReturnsEpochSeconds() {
50
53
}
51
54
52
55
@ Test
53
- void calculateDataIntegrityReturnsStable (){
56
+ void calculateDataIntegrityReturnsStable () {
54
57
when (userBusinessServiceMock .getUserCount ()).thenReturn (2L );
55
58
when (accessTokenBusinessServiceMock .getAccessTokenCount ()).thenReturn (2L );
59
+ when (environmentMock .getActiveProfiles ()).thenReturn (new String []{"test" });
56
60
57
61
DataIntegrity dataIntegrity = DataIntegrity .STABLE ;
58
62
DataIntegrity actual = systemHealthBusinessService .getCurrentSystemHealthInfo ().getDataIntegrity ();
@@ -67,12 +71,24 @@ void calculateDataIntegrityReturnsStable(){
67
71
}
68
72
69
73
@ Test
70
- void calculateDataIntegrityReturnsRisk (){
74
+ void calculateDataIntegrityReturnsRisk () {
71
75
when (userBusinessServiceMock .getUserCount ()).thenReturn (2L );
72
76
when (accessTokenBusinessServiceMock .getAccessTokenCount ()).thenReturn (3L );
77
+ when (environmentMock .getActiveProfiles ()).thenReturn (new String []{"test" });
73
78
74
79
DataIntegrity dataIntegrity = DataIntegrity .POSSIBLE_RISK ;
75
80
DataIntegrity actual = systemHealthBusinessService .getCurrentSystemHealthInfo ().getDataIntegrity ();
76
81
assertEquals (dataIntegrity , actual );
77
82
}
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
+ }
78
94
}
0 commit comments