2 * ============LICENSE_START=======================================================
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
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.common.util;
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;
30 import java.util.Collection;
31 import java.util.Collections;
32 import java.util.List;
34 import static junit.framework.TestCase.assertFalse;
35 import static junit.framework.TestCase.assertTrue;
36 import static org.mockito.Mockito.when;
38 @RunWith(MockitoJUnitRunner.class)
39 public class HealthCheckUtilTest {
41 private HealthCheckUtil healthCheckUtil;
43 private final String testComponent = "service";
46 private HealthCheckInfo healthCheckInfo;
48 private List<HealthCheckInfo> healthCheckInfos;
52 healthCheckUtil = new HealthCheckUtil();
53 healthCheckInfos = Collections.singletonList(healthCheckInfo);
54 when(healthCheckInfo.getHealthCheckComponent()).thenReturn(testComponent);
58 public void validateGetAggregateStatusReturnsTrue() {
59 final Collection<String> excludes = Collections.emptyList();
60 when(healthCheckInfo.getHealthCheckStatus()).thenReturn(HealthCheckInfo.HealthCheckStatus.UP);
62 final boolean result = healthCheckUtil.getAggregateStatus(healthCheckInfos, excludes);
68 public void validateGetAggregateStatusReturnsFalseIfStatusIsDown() {
69 final Collection<String> excludes = Collections.emptyList();
70 when(healthCheckInfo.getHealthCheckStatus()).thenReturn(HealthCheckInfo.HealthCheckStatus.DOWN);
72 final boolean result = healthCheckUtil.getAggregateStatus(healthCheckInfos, excludes);
78 public void validateGetAggregateDescriptionReturnsProperDescription() {
79 final String parentDescription = "";
80 when(healthCheckInfo.getHealthCheckStatus()).thenReturn(HealthCheckInfo.HealthCheckStatus.DOWN);
82 final String result = healthCheckUtil.getAggregateDescription(healthCheckInfos, parentDescription);
84 assertTrue(result.contains(testComponent));
85 assertTrue(result.contains("Down"));