2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
23 package org.openecomp.sdc.be.components;
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;
33 import java.util.ArrayList;
34 import java.util.List;
36 import static org.junit.Assert.assertFalse;
37 import static org.junit.Assert.assertTrue;
38 public class HealthCheckBusinessLogicTest {
40 private final SwitchoverDetector switchoverDetector = Mockito.mock(SwitchoverDetector.class);
42 HealthCheckBusinessLogic healthCheckBusinessLogic = new HealthCheckBusinessLogic();
45 public void checkStausUpdated() {
47 boolean statusChanged = healthCheckBusinessLogic.anyStatusChanged(null, null);
48 assertFalse("check false", statusChanged);
50 List<HealthCheckInfo> checkInfosLeft = new ArrayList<>();
51 List<HealthCheckInfo> checkInfosRight = new ArrayList<>();
53 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
54 assertFalse("check false", statusChanged);
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);
59 HealthCheckInfo checkInfoDmaapProducerUp = new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckStatus.UP, null, null);
61 HealthCheckInfo healthCheckInfoCADIUp = new HealthCheckInfo(Constants.HC_COMPONENT_CADI, HealthCheckStatus.UP, null, null);
64 * HealthCheckInfo checkInfoUebUp = new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.UP, null, null); HealthCheckInfo checkInfoUebDown = new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.DOWN, null, null);
67 checkInfosLeft.add(checkInfoJanusGraphUp);
69 checkInfosRight.add(checkInfoJanusGraphUp);
71 checkInfosLeft.add(checkInfoDmaapProducerUp);
73 checkInfosRight.add(checkInfoDmaapProducerUp);
75 checkInfosLeft.add(healthCheckInfoCADIUp);
77 checkInfosRight.add(healthCheckInfoCADIUp);
79 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
80 assertFalse("check false", statusChanged);
82 checkInfosRight.remove(checkInfoJanusGraphUp);
83 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
84 assertTrue("check true", statusChanged);
86 checkInfosRight.add(checkInfoJanusGraphDown);
87 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
88 assertTrue("check true", statusChanged);
90 checkInfosRight.remove(checkInfoJanusGraphDown);
91 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
92 assertTrue("check true", statusChanged);
94 checkInfosRight.add(checkInfoJanusGraphUp);
95 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
96 assertFalse("check false", statusChanged);
98 checkInfosRight.remove(healthCheckInfoCADIUp);
99 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
100 assertTrue("check true", statusChanged);
102 checkInfosRight.add(healthCheckInfoCADIUp);
103 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, null);
104 assertTrue("check true", statusChanged);