2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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=========================================================
21 package org.openecomp.sdc.be.components.distribution.engine;
23 import java.util.HashMap;
24 import java.util.LinkedList;
26 import java.util.concurrent.atomic.AtomicBoolean;
27 import mockit.Deencapsulation;
28 import org.junit.jupiter.api.BeforeAll;
29 import org.junit.jupiter.api.Test;
30 import org.openecomp.sdc.be.components.BeConfDependentTest;
31 import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineClusterHealth.HealthCheckScheduledTask;
32 import org.openecomp.sdc.common.api.HealthCheckInfo;
34 class DistributionEngineClusterHealthTest extends BeConfDependentTest {
36 private DistributionEngineClusterHealth createTestSubject() {
37 return new DistributionEngineClusterHealth();
40 // TODO - move to BeConfDependentTest after migration to Junit 5
42 public static void setupBeforeClass() {
43 componentName = "catalog-be";
44 confPath = "src/test/resources/config";
49 void testDestroy() throws Exception {
50 DistributionEngineClusterHealth testSubject;
53 testSubject = createTestSubject();
54 Deencapsulation.invoke(testSubject, "destroy");
58 void testStartHealthCheckTask() throws Exception {
59 DistributionEngineClusterHealth testSubject;
60 Map<String, AtomicBoolean> envNamePerStatus = null;
61 boolean startTask = false;
64 testSubject = createTestSubject();
65 testSubject.startHealthCheckTask(envNamePerStatus, startTask);
69 void testStartHealthCheckTask_1() {
70 final DistributionEngineClusterHealth distributionEngineClusterHealth = new DistributionEngineClusterHealth();
71 final Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
72 distributionEngineClusterHealth.init("myKey");
73 distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus);
77 void testHealthCheckScheduledTask() throws Exception {
78 DistributionEngineClusterHealth testSubject;
79 Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
82 testSubject = createTestSubject();
83 HealthCheckScheduledTask healthCheckScheduledTask = testSubject.new HealthCheckScheduledTask(new LinkedList<>());
84 LinkedList<UebHealthCheckCall> healthCheckCalls = new LinkedList<>();
85 UebHealthCheckCall hcc = new UebHealthCheckCall("mock", "mock");
86 healthCheckCalls.add(hcc);
87 healthCheckScheduledTask.healthCheckCalls = healthCheckCalls;
89 Deencapsulation.invoke(healthCheckScheduledTask, "queryUeb");
93 void testHealthCheckScheduledTaskRun() throws Exception {
94 DistributionEngineClusterHealth testSubject;
95 Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
96 envNamePerStatus.put("mock", new AtomicBoolean(true));
98 testSubject = createTestSubject();
99 testSubject.startHealthCheckTask(envNamePerStatus, false);
100 HealthCheckScheduledTask healthCheckScheduledTask = testSubject.new HealthCheckScheduledTask(new LinkedList<>());
101 LinkedList<UebHealthCheckCall> healthCheckCalls = new LinkedList<>();
102 UebHealthCheckCall hcc = new UebHealthCheckCall("mock", "mock");
103 healthCheckCalls.add(hcc);
104 healthCheckScheduledTask.healthCheckCalls = healthCheckCalls;
106 Deencapsulation.invoke(healthCheckScheduledTask, "run");
110 void testHealthCheckScheduledTaskRun_2() throws Exception {
111 DistributionEngineClusterHealth testSubject;
112 Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
113 envNamePerStatus.put("mock", new AtomicBoolean(false));
115 testSubject = createTestSubject();
116 testSubject.startHealthCheckTask(envNamePerStatus, false);
117 HealthCheckScheduledTask healthCheckScheduledTask = testSubject.new HealthCheckScheduledTask(new LinkedList<>());
118 LinkedList<UebHealthCheckCall> healthCheckCalls = new LinkedList<>();
119 UebHealthCheckCall hcc = new UebHealthCheckCall("mock", "mock");
120 healthCheckCalls.add(hcc);
121 healthCheckScheduledTask.healthCheckCalls = healthCheckCalls;
123 Deencapsulation.invoke(healthCheckScheduledTask, "run");
127 void testLogAlarm() throws Exception {
128 DistributionEngineClusterHealth testSubject;
129 boolean lastHealthState = false;
132 testSubject = createTestSubject();
133 Deencapsulation.invoke(testSubject, "logAlarm", new Object[]{lastHealthState});
137 void testGetHealthCheckInfo() throws Exception {
138 DistributionEngineClusterHealth testSubject;
139 HealthCheckInfo result;
142 testSubject = createTestSubject();
143 result = testSubject.getHealthCheckInfo();
147 void testSetHealthCheckUebIsDisabled() throws Exception {
148 DistributionEngineClusterHealth testSubject;
151 testSubject = createTestSubject();
152 testSubject.setHealthCheckUebIsDisabled();
156 void testSetHealthCheckUebConfigurationError() throws Exception {
157 DistributionEngineClusterHealth testSubject;
160 testSubject = createTestSubject();
161 testSubject.setHealthCheckUebConfigurationError();
165 void testSetHealthCheckOkAndReportInCaseLastStateIsDown() throws Exception {
166 DistributionEngineClusterHealth testSubject;
169 testSubject = createTestSubject();
170 testSubject.setHealthCheckOkAndReportInCaseLastStateIsDown();