Fixed the CLM Issues
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / api / stat / AlarmTest.java
1 /**
2  * Copyright 2017-2020 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.holmes.common.api.stat;
18
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Rule;
22 import org.junit.Test;
23 import org.junit.rules.ExpectedException;
24
25 import java.util.Date;
26
27 import static org.hamcrest.core.IsEqual.equalTo;
28 import static org.junit.Assert.*;
29
30 public class AlarmTest {
31
32     @Rule
33     public ExpectedException thrown = ExpectedException.none();
34
35     private Alarm alarm;
36
37     @Before
38     public void before() {
39         alarm = new Alarm();
40     }
41
42     @After
43     public void after() {
44     }
45
46     @Test
47     public void testContainNode_NoContainLink() {
48         alarm.addLinkIdNodeIdx(1, 2);
49         assertThat(false, equalTo(alarm.containNode(2, 2)));
50     }
51
52     @Test
53     public void testContainNode_ContainLinkNoIdx() {
54         alarm.addLinkIdNodeIdx(1, 2);
55         assertFalse(alarm.containNode(1, 3));
56     }
57
58     @Test
59     public void testContainNode_ContainLinkAndIdx() {
60         alarm.addLinkIdNodeIdx(1, 2);
61         assertTrue(alarm.containNode(1, 2));
62     }
63
64     @Test
65     public void testGetDataType() {
66         assertThat(Alarm.APLUS_EVENT, equalTo(alarm.getDataType()));
67     }
68
69     @Test
70     public void testToString() {
71         Alarm alarmTempA = new Alarm();
72         Alarm alarmTempB = new Alarm();
73         Date date = new Date();
74         alarmTempA.setClearedTime(date);
75         alarmTempA.setRaisedTime(date);
76         alarmTempA.setRaisedServerTime(date);
77         alarmTempB.setClearedTime(date);
78         alarmTempB.setRaisedTime(date);
79         alarmTempB.setRaisedServerTime(date);
80         assertThat(alarmTempA.toString(),equalTo(alarmTempB.toString()));
81     }
82
83     @Test
84     public void testHashCode() {
85         final Alarm alarmTemp = new Alarm();
86         final String alarmKey = "alarmKey";
87         alarm.setAlarmKey(alarmKey);
88         alarmTemp.setAlarmKey(alarmKey);
89         assertThat(alarm.hashCode(), equalTo(alarmTemp.hashCode()));
90     }
91
92     @Test
93     public void testEqualsAnd_NotNull() {
94         final Alarm alarmTemp = new Alarm();
95         final String alarmKey = "alarmKey";
96         alarm.setAlarmKey(alarmKey);
97         alarmTemp.setAlarmKey(alarmKey);
98         assertTrue(alarm.equals(alarmTemp));
99     }
100
101     @Test
102     public void testEqualsAndH_isNull() {
103         assertFalse(alarm.equals(null));
104     }
105
106     @Test
107     public void testClone() throws CloneNotSupportedException {
108         alarm.setAlarmKey("alarmKey");
109         Alarm alarmTemp = (Alarm) alarm.clone();
110         assertTrue(alarm.equals(alarmTemp));
111         assertFalse(alarm == alarmTemp);
112     }
113
114     @Test
115     public void testGetObjectId() {
116         alarm.setId(11);
117         assertThat("11", equalTo(alarm.getObjectId()));
118     }
119
120     @Test
121     public void testAddLinkIds() {
122         final int linkId = 11;
123         alarm.addLinkIds(linkId);
124         assertTrue(alarm.getLinkIds().contains(linkId));
125     }
126
127     @Test
128     public void testContainsPriority_true() {
129         String ruleId = "ruleId";
130         alarm.getPriorityMap().put(ruleId, 2);
131         assertTrue(alarm.containsPriority(ruleId));
132     }
133
134     @Test
135     public void testContainsPriority_false() {
136         final String ruleId = "ruleId";
137         assertFalse(alarm.containsPriority(ruleId));
138     }
139
140     @Test
141     public void testGetPriority_isNull() {
142         final String ruleId = "ruleId";
143         alarm.getPriorityMap().put(ruleId, null);
144         assertThat(0, equalTo(alarm.getPriority(ruleId)));
145     }
146
147     @Test
148     public void testGetPriority_notNull() {
149         final String ruleId = "ruleId";
150         final int priority = 2;
151         alarm.getPriorityMap().put(ruleId, priority);
152         assertThat(priority, equalTo(alarm.getPriority(ruleId)));
153     }
154
155     @Test
156     public void testGetAlarmTypeRuleId_isNull() {
157         final String ruleId = "ruleId";
158         alarm.getRootAlarmTypeMap().put(ruleId, null);
159         assertThat(-1, equalTo(alarm.getRootAlarmType(ruleId)));
160     }
161
162     @Test
163     public void testGetAlarmTypeRuleId_notNull() {
164         final String ruleId = "ruleId";
165         final int rootAlarmType = 2;
166         alarm.getRootAlarmTypeMap().put(ruleId, rootAlarmType);
167         assertThat(rootAlarmType, equalTo(alarm.getRootAlarmType(ruleId)));
168     }
169
170     @Test
171     public void getterAndSetter4CenterType() {
172         final int centerType = 1;
173         alarm.setCenterType(centerType);
174         assertThat(centerType, equalTo(alarm.getCenterType()));
175     }
176 }