6b2b6c86a57fea4666295ce41af3701477fa81c9
[vfc/nfvo/driver/ems.git] / ems / boco / src / test / java / org / onap / vfc / nfvo / emsdriver / collector / alarm / AlarmTaskThreadTest.java
1 /*
2  * Copyright 2017 BOCO Corporation.  CMCC Technologies Co., Ltd
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.vfc.nfvo.emsdriver.collector.alarm;
17
18 import static org.junit.Assert.assertNotNull;
19
20 import java.io.IOException;
21
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo;
25
26 public class AlarmTaskThreadTest {
27
28         private AlarmTaskThread taskThread;
29         private AlarmSocketServer server;
30
31         @Before
32         public void setUp() throws IOException {
33                 new Thread() {
34                         public void run() {
35                                 server = new AlarmSocketServer();
36                                 server.socketServer();
37                         }
38                 }.start();
39                 CollectVo collectVo = new CollectVo();
40                 collectVo.setIP("127.0.0.1");
41                 collectVo.setPort("12345");
42                 collectVo.setUser("user");
43                 collectVo.setPassword("12345");
44                 collectVo.setReadTimeout("10000");
45                 taskThread = new AlarmTaskThread(collectVo);
46         }
47
48         @Test
49         public void build120Alarm() {
50                 String alarm = "{\"alarmSeq\":495,\"alarmTitle\":\"LTE cell outage\",\"alarmStatus\":1,\"alarmType\":\"processingErrorAlarm\"}";
51                 try {
52                         new Thread() {
53                                 public void run() {
54                                         try {
55                                                 Thread.sleep(3000);
56                                                 server.stop();
57                                                 taskThread.setStop(true);
58                                                 taskThread.close();
59                                         } catch (InterruptedException e) {
60                                                 // TODO Auto-generated catch block
61                                                 e.printStackTrace();
62                                         }
63                                 }
64                         }.start();
65                         taskThread.init();
66                         taskThread.receive();
67                 } catch (Exception e) {
68                         // TODO Auto-generated catch block
69                         e.printStackTrace();
70                 }
71                 assertNotNull(alarm);
72         }
73
74         @Test
75         public void runAlarmTaskThread() {
76                 try {
77                         taskThread.run();
78                         Thread.sleep(10000);
79                         taskThread.setStop(true);
80                         server.stop();
81                 } catch (InterruptedException e) {
82                         // TODO Auto-generated catch block
83                         e.printStackTrace();
84                 }
85
86         }
87
88 }