Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / HealthCheckBusinessLogicTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. 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  * Modifications copyright (c) 2019 Nokia
20  * ================================================================================
21  */
22
23 package org.openecomp.sdc.be.components;
24
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.openecomp.sdc.be.components.health.HealthCheckBusinessLogic;
28 import org.openecomp.sdc.be.switchover.detector.SwitchoverDetector;
29 import org.openecomp.sdc.common.api.Constants;
30 import org.openecomp.sdc.common.api.HealthCheckInfo;
31 import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
32
33 import java.util.ArrayList;
34 import java.util.List;
35
36 import static org.junit.Assert.assertFalse;
37 import static org.junit.Assert.assertTrue;
38 public class HealthCheckBusinessLogicTest {
39
40     private final SwitchoverDetector switchoverDetector = Mockito.mock(SwitchoverDetector.class);
41
42     HealthCheckBusinessLogic healthCheckBusinessLogic = new HealthCheckBusinessLogic();
43
44     @Test
45     public void checkStausUpdated() {
46
47         boolean statusChanged = healthCheckBusinessLogic.anyStatusChanged(null, null);
48         assertFalse("check false", statusChanged);
49
50         List<HealthCheckInfo> checkInfosLeft = new ArrayList<>();
51         List<HealthCheckInfo> checkInfosRight = new ArrayList<>();
52
53         statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
54         assertFalse("check false", statusChanged);
55
56         HealthCheckInfo checkInfoJanusGraphUp = new HealthCheckInfo(Constants.HC_COMPONENT_JANUSGRAPH, HealthCheckStatus.UP, null, null);
57         HealthCheckInfo checkInfoJanusGraphDown = new HealthCheckInfo(Constants.HC_COMPONENT_JANUSGRAPH, HealthCheckStatus.DOWN, null, null);
58
59         HealthCheckInfo checkInfoDmaapProducerUp = new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckStatus.UP, null, null);
60
61         HealthCheckInfo healthCheckInfoCADIUp = new HealthCheckInfo(Constants.HC_COMPONENT_CADI, HealthCheckStatus.UP, null, null);
62
63         /*
64          * HealthCheckInfo checkInfoUebUp = new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.UP, null, null); HealthCheckInfo checkInfoUebDown = new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.DOWN, null, null);
65          */
66
67         checkInfosLeft.add(checkInfoJanusGraphUp);
68
69         checkInfosRight.add(checkInfoJanusGraphUp);
70
71         checkInfosLeft.add(checkInfoDmaapProducerUp);
72
73         checkInfosRight.add(checkInfoDmaapProducerUp);
74
75         checkInfosLeft.add(healthCheckInfoCADIUp);
76
77         checkInfosRight.add(healthCheckInfoCADIUp);
78
79         statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
80         assertFalse("check false", statusChanged);
81
82         checkInfosRight.remove(checkInfoJanusGraphUp);
83         statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
84         assertTrue("check true", statusChanged);
85
86         checkInfosRight.add(checkInfoJanusGraphDown);
87         statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
88         assertTrue("check true", statusChanged);
89
90         checkInfosRight.remove(checkInfoJanusGraphDown);
91         statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
92         assertTrue("check true", statusChanged);
93
94         checkInfosRight.add(checkInfoJanusGraphUp);
95         statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
96         assertFalse("check false", statusChanged);
97
98         checkInfosRight.remove(healthCheckInfoCADIUp);
99         statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
100         assertTrue("check true", statusChanged);
101
102         checkInfosRight.add(healthCheckInfoCADIUp);
103         statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, null);
104         assertTrue("check true", statusChanged);
105
106     }
107
108 }