refactoring tests in Common-App-Api util
[sdc.git] / common-app-api / src / test / java / org / openecomp / sdc / common / util / HealthCheckUtilTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.common.util;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mock;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.openecomp.sdc.common.api.HealthCheckInfo;
29
30 import java.util.Collection;
31 import java.util.Collections;
32 import java.util.List;
33
34 import static junit.framework.TestCase.assertFalse;
35 import static junit.framework.TestCase.assertTrue;
36 import static org.mockito.Mockito.when;
37
38 @RunWith(MockitoJUnitRunner.class)
39 public class HealthCheckUtilTest {
40
41     private HealthCheckUtil healthCheckUtil;
42
43     private final String testComponent = "service";
44
45     @Mock
46     private HealthCheckInfo healthCheckInfo;
47
48     private List<HealthCheckInfo> healthCheckInfos;
49
50     @Before
51     public void setUp() {
52         healthCheckUtil = new HealthCheckUtil();
53         healthCheckInfos = Collections.singletonList(healthCheckInfo);
54         when(healthCheckInfo.getHealthCheckComponent()).thenReturn(testComponent);
55     }
56
57     @Test
58     public void validateGetAggregateStatusReturnsTrue() {
59         final Collection<String> excludes = Collections.emptyList();
60         when(healthCheckInfo.getHealthCheckStatus()).thenReturn(HealthCheckInfo.HealthCheckStatus.UP);
61
62         final boolean result = healthCheckUtil.getAggregateStatus(healthCheckInfos, excludes);
63
64         assertTrue(result);
65     }
66
67     @Test
68     public void validateGetAggregateStatusReturnsFalseIfStatusIsDown() {
69         final Collection<String> excludes = Collections.emptyList();
70         when(healthCheckInfo.getHealthCheckStatus()).thenReturn(HealthCheckInfo.HealthCheckStatus.DOWN);
71
72         final boolean result = healthCheckUtil.getAggregateStatus(healthCheckInfos, excludes);
73
74         assertFalse(result);
75     }
76
77     @Test
78     public void validateGetAggregateDescriptionReturnsProperDescription() {
79         final String parentDescription = "";
80         when(healthCheckInfo.getHealthCheckStatus()).thenReturn(HealthCheckInfo.HealthCheckStatus.DOWN);
81
82         final String result = healthCheckUtil.getAggregateDescription(healthCheckInfos, parentDescription);
83
84         assertTrue(result.contains(testComponent));
85         assertTrue(result.contains("Down"));
86     }
87
88 }