14a52c0571f78ca7524b2d31dd7849c5a0095c87
[holmes/common.git] / holmes-actions / src / test / java / org / openo / holmes / common / api / entity / CorrelationResultTest.java
1 /**
2  * Copyright 2017 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.openo.holmes.common.api.entity;
18
19 import static org.hamcrest.core.IsEqual.equalTo;
20 import static org.junit.Assert.assertThat;
21
22 import java.util.Date;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.openo.holmes.common.api.stat.Alarm;
27
28 public class CorrelationResultTest {
29
30     private CorrelationResult correlationResult;
31
32     @Before
33     public void before() throws Exception {
34         correlationResult = new CorrelationResult();
35     }
36
37     @After
38     public void after() throws Exception {
39     }
40
41     @Test
42     public void getterAndSetter4RuleId() throws Exception {
43         final String ruleId = "ruleId";
44         correlationResult.setRuleId(ruleId);
45         assertThat(correlationResult.getRuleId(), equalTo(ruleId));
46     }
47
48     @Test
49     public void getterAndSetter4CreateTimeL() throws Exception {
50         final long createTimeL = new Date().getTime();
51         correlationResult.setCreateTimeL(
52                 createTimeL);
53         assertThat(correlationResult.getCreateTimeL(), equalTo(createTimeL));
54     }
55
56     @Test
57     public void getterAndSetter4GetResultType() throws Exception {
58         final byte resultType = 2;
59         correlationResult.setResultType(resultType);
60         assertThat(correlationResult.getResultType(), equalTo(resultType));
61     }
62
63     @Test
64     public void getterAndSetter4AffectedAlarms() throws Exception {
65         final Alarm alarm[] = new Alarm[2];
66         correlationResult.setAffectedAlarms(alarm);
67         assertThat(correlationResult.getAffectedAlarms(), equalTo(alarm));
68     }
69
70     @Test
71     public void testToString() throws Exception {
72         CorrelationResult resultTemp = new CorrelationResult();
73         final String tempStr = "aa";
74         resultTemp.setRuleId(tempStr);
75         correlationResult.setRuleId(tempStr);
76         assertThat(correlationResult.toString(), equalTo(resultTemp.toString()));
77     }
78 }