add alarm synchronization related operation
[holmes/engine-management.git] / engine-d / src / test / java / org / onap / holmes / engine / dmaap / DMaaPAlarmPollingTest.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 package org.onap.holmes.engine.dmaap;
17
18 import static org.hamcrest.CoreMatchers.is;
19 import static org.hamcrest.core.IsEqual.equalTo;
20 import static org.junit.Assert.*;
21
22 import java.lang.reflect.Field;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.onap.holmes.common.api.entity.AlarmInfo;
27 import org.onap.holmes.common.api.stat.VesAlarm;
28 import org.onap.holmes.dsa.dmaappolling.Subscriber;
29 import org.onap.holmes.engine.db.AlarmInfoDao;
30 import org.onap.holmes.engine.manager.DroolsEngine;
31 import org.powermock.api.easymock.PowerMock;
32 import org.powermock.core.classloader.annotations.PrepareForTest;
33 import org.powermock.modules.junit4.PowerMockRunner;
34 import org.powermock.reflect.Whitebox;
35
36 @PrepareForTest({Subscriber.class, DroolsEngine.class,DMaaPAlarmPolling.class})
37 @RunWith(PowerMockRunner.class)
38 public class DMaaPAlarmPollingTest {
39
40     private DMaaPAlarmPolling dMaaPAlarmPolling;
41     private Subscriber subscriber;
42     private DroolsEngine droolsEngine;
43     private AlarmInfoDao alarmInfoDao;
44
45     @Before
46     public void setUp() {
47         subscriber = PowerMock.createMock(Subscriber.class);
48         droolsEngine = PowerMock.createMock(DroolsEngine.class);
49         alarmInfoDao = PowerMock.createMock(AlarmInfoDao.class);
50         dMaaPAlarmPolling = new DMaaPAlarmPolling(subscriber, droolsEngine,alarmInfoDao);
51         PowerMock.replayAll();
52     }
53
54     @Test
55     public void test_stop_task_ok() throws Exception {
56         dMaaPAlarmPolling.stopTask();
57         Field field = DMaaPAlarmPolling.class.getDeclaredField("isAlive");
58         field.setAccessible(true);
59         assertThat(field.get(dMaaPAlarmPolling), equalTo(false));
60     }
61
62     @Test
63     public void testGetAlarmInfo() throws Exception {
64         VesAlarm vesAlarm = new VesAlarm();
65         vesAlarm.setAlarmIsCleared(1);
66         vesAlarm.setSourceName("sourceName");
67         vesAlarm.setSourceId("sourceId");
68         vesAlarm.setStartEpochMicrosec(1L);
69         vesAlarm.setLastEpochMicrosec(1L);
70         vesAlarm.setEventName("eventName");
71         vesAlarm.setEventId("eventId");
72         vesAlarm.setRootFlag(0);
73
74         PowerMock.replayAll();
75         AlarmInfo alarmInfo = Whitebox.invokeMethod(dMaaPAlarmPolling,"getAlarmInfo",vesAlarm);
76         PowerMock.verifyAll();
77
78         assertThat(alarmInfo.getAlarmIsCleared(), is(1));
79         assertThat(alarmInfo.getSourceName(), equalTo("sourceName"));
80         assertThat(alarmInfo.getSourceId(), equalTo("sourceId"));
81         assertThat(alarmInfo.getStartEpochMicroSec(), is(1L));
82         assertThat(alarmInfo.getLastEpochMicroSec(), is(1L));
83         assertThat(alarmInfo.getEventName(), equalTo("eventName"));
84         assertThat(alarmInfo.getEventId(), equalTo("eventId"));
85         assertThat(alarmInfo.getRootFlag(), is(0));
86     }
87
88 }