[SDC] rebase 1710 code
[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  */
20
21 package org.openecomp.sdc.be.components;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import javax.annotation.Resource;
27
28 import org.junit.Test;
29 import org.openecomp.sdc.be.components.impl.HealthCheckBusinessLogic;
30 import org.openecomp.sdc.be.dao.cassandra.schema.SdcSchemaUtils;
31 import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
32 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
33 import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
34 import org.openecomp.sdc.be.resources.data.UserData;
35 import org.openecomp.sdc.common.api.HealthCheckInfo;
36 import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckComponent;
37 import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
38
39 import com.datastax.driver.core.Cluster;
40
41 import fj.data.Either;
42
43 import static org.junit.Assert.assertTrue;
44 import static org.junit.Assert.assertFalse;
45
46 public class HealthCheckBusinessLogicTest {
47
48         HealthCheckBusinessLogic healthCheckBusinessLogic = new HealthCheckBusinessLogic();
49         
50         @Test
51         public void checkStausUpdated() {
52
53                 boolean statusChanged = healthCheckBusinessLogic.anyStatusChanged(null, null);
54                 assertFalse("check false", statusChanged);
55
56                 List<HealthCheckInfo> checkInfosLeft = new ArrayList<HealthCheckInfo>();
57                 List<HealthCheckInfo> checkInfosRight = new ArrayList<HealthCheckInfo>();
58
59                 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
60                 assertFalse("check false", statusChanged);
61
62                 HealthCheckInfo checkInfoTitanUp = new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.UP, null, null);
63                 HealthCheckInfo checkInfoTitanDown = new HealthCheckInfo(HealthCheckComponent.TITAN, HealthCheckStatus.DOWN, null, null);
64
65                 /*
66                  * HealthCheckInfo checkInfoUebUp = new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.UP, null, null); HealthCheckInfo checkInfoUebDown = new HealthCheckInfo(HealthCheckComponent.DE, HealthCheckStatus.DOWN, null, null);
67                  */
68
69                 checkInfosLeft.add(checkInfoTitanUp);
70
71                 checkInfosRight.add(checkInfoTitanUp);
72
73                 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
74                 assertFalse("check false", statusChanged);
75
76                 checkInfosRight.remove(checkInfoTitanUp);
77                 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
78                 assertTrue("check true", statusChanged);
79
80                 checkInfosRight.add(checkInfoTitanDown);
81                 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
82                 assertTrue("check true", statusChanged);
83
84                 checkInfosRight.remove(checkInfoTitanDown);
85                 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
86                 assertTrue("check true", statusChanged);
87
88                 checkInfosRight.add(checkInfoTitanUp);
89                 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, checkInfosRight);
90                 assertFalse("check false", statusChanged);
91
92                 statusChanged = healthCheckBusinessLogic.anyStatusChanged(checkInfosLeft, null);
93                 assertTrue("check true", statusChanged);
94
95         }
96
97 }