1
1
package com .symphony .bdk .app .spring .service ;
2
2
3
- import com .symphony .bdk .app .spring .service .SymphonyBdkHealthIndicator .CustomStatusCodeMapper ;
4
3
import com .symphony .bdk .core .service .health .HealthService ;
5
4
import com .symphony .bdk .gen .api .model .V3Health ;
6
5
import com .symphony .bdk .gen .api .model .V3HealthComponent ;
7
6
import com .symphony .bdk .gen .api .model .V3HealthStatus ;
8
7
import com .symphony .bdk .http .api .ApiException ;
9
8
import com .symphony .bdk .http .api .ApiRuntimeException ;
10
9
11
- import org .junit .jupiter .api .Nested ;
12
10
import org .junit .jupiter .api .Test ;
13
11
import org .junit .jupiter .api .extension .ExtendWith ;
14
12
import org .junit .jupiter .params .ParameterizedTest ;
15
13
import org .junit .jupiter .params .provider .Arguments ;
16
- import org .junit .jupiter .params .provider .CsvSource ;
17
14
import org .junit .jupiter .params .provider .MethodSource ;
18
15
import org .mockito .InjectMocks ;
19
16
import org .mockito .Mock ;
20
17
import org .mockito .junit .jupiter .MockitoExtension ;
21
18
import org .springframework .boot .actuate .health .Health ;
22
- import org .springframework .boot .actuate .health .HttpCodeStatusMapper ;
23
19
import org .springframework .boot .actuate .health .Status ;
24
20
25
21
import java .util .Collections ;
22
+ import java .util .Map ;
26
23
import java .util .stream .Stream ;
27
24
28
25
import static org .assertj .core .api .Assertions .assertThat ;
@@ -34,20 +31,29 @@ class SymphonyBdkHealthIndicatorTest {
34
31
@ Mock HealthService healthService ;
35
32
@ InjectMocks SymphonyBdkHealthIndicator healthIndicator ;
36
33
37
- @ Test
38
- void doHealthCheck_successful () throws Exception {
34
+ @ ParameterizedTest
35
+ @ MethodSource ("datafeedHealthTestArguments" )
36
+ void doHealthCheck_datafeedStatus_expectedStatusCode (V3HealthStatus dfl , V3HealthStatus df , String globalCode ) throws Exception {
39
37
V3Health health = new V3Health ();
40
38
health .putServicesItem ("pod" , new V3HealthComponent ().status (V3HealthStatus .UP ));
41
- health .putServicesItem ("datafeed" , new V3HealthComponent ().status (V3HealthStatus . UP ));
39
+ health .putServicesItem ("datafeed" , new V3HealthComponent ().status (df ));
42
40
health .putServicesItem ("key_manager" , new V3HealthComponent ().status (V3HealthStatus .UP ));
43
41
health .putUsersItem ("agentservice" , new V3HealthComponent ().status (V3HealthStatus .UP ));
44
42
health .putUsersItem ("ceservice" , new V3HealthComponent ().status (V3HealthStatus .UP ));
45
43
when (healthService .healthCheckExtended ()).thenReturn (health );
46
- when (healthService .datafeedHealthCheck ()).thenReturn (V3HealthStatus . UP );
44
+ when (healthService .datafeedHealthCheck ()).thenReturn (dfl );
47
45
Health .Builder builder = new Health .Builder ();
48
46
healthIndicator .doHealthCheck (builder );
49
47
Health build = builder .build ();
50
- assertThat (build .getStatus ().getCode ()).isEqualTo ("UP" );
48
+ assertThat (build .getStatus ().getCode ()).isEqualTo (globalCode );
49
+ }
50
+
51
+ private static Stream <Arguments > datafeedHealthTestArguments () {
52
+ return Stream .of (
53
+ Arguments .of (V3HealthStatus .UP , V3HealthStatus .UP , Status .UP .getCode ()),
54
+ Arguments .of (V3HealthStatus .DOWN , V3HealthStatus .UP , Status .OUT_OF_SERVICE .getCode ()),
55
+ Arguments .of (V3HealthStatus .UP , V3HealthStatus .DOWN , "WARNING" )
56
+ );
51
57
}
52
58
53
59
@ Test
@@ -78,7 +84,7 @@ void doHealthCheck_exception() throws Exception {
78
84
+ " \" message\" : \" Ceservice authentication credentials missing or misconfigured\" \n " + " }\n "
79
85
+ " }\n " + "}" ;
80
86
81
- doThrow (new ApiRuntimeException (new ApiException (503 , "message" , Collections . EMPTY_MAP , body ))).when (healthService )
87
+ doThrow (new ApiRuntimeException (new ApiException (503 , "message" , Map . of () , body ))).when (healthService )
82
88
.healthCheckExtended ();
83
89
when (healthService .datafeedHealthCheck ()).thenReturn (V3HealthStatus .UP );
84
90
Health .Builder builder = new Health .Builder ();
@@ -92,32 +98,12 @@ void doHealthCheck_badGw_exception() throws Exception {
92
98
final String body = "<html>\n " + "<head><title>502 Bad Gateway</title></head>\n " + "<body>\n "
93
99
+ "<center><h1>502 Bad Gateway</h1></center>\n " + "</body>\n " + "</html>" ;
94
100
95
- doThrow (new ApiRuntimeException (new ApiException (502 , "message" , Collections . EMPTY_MAP , body ))).when (healthService )
101
+ doThrow (new ApiRuntimeException (new ApiException (502 , "message" , Map . of () , body ))).when (healthService )
96
102
.healthCheckExtended ();
97
103
Health .Builder builder = new Health .Builder ();
98
104
healthIndicator .doHealthCheck (builder );
99
105
Health build = builder .build ();
100
106
assertThat (build .getStatus ().getCode ()).isEqualTo ("DOWN" );
101
107
}
102
108
103
- @ Nested
104
- class CustomStatusCodeMapperTest {
105
-
106
- HttpCodeStatusMapper mapper = new CustomStatusCodeMapper ();
107
-
108
- @ ParameterizedTest
109
- @ MethodSource ("getStatusArguments" )
110
- void getStatusCode_status_code (Status status , int code ) {
111
- assertThat (mapper .getStatusCode (status )).isEqualTo (code );
112
- }
113
-
114
- private static Stream <Arguments > getStatusArguments () {
115
- return Stream .of (
116
- Arguments .of (Status .UP , 200 ),
117
- Arguments .of (Status .DOWN , 500 ),
118
- Arguments .of (new Status ("WARNING" ), 500 ),
119
- Arguments .of (Status .OUT_OF_SERVICE , 503 ),
120
- Arguments .of (Status .UNKNOWN , 500 ));
121
- }
122
- }
123
109
}
0 commit comments