solve test code bug
[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         private Thread severThread;
31
32         @Before
33         public void setUp() throws IOException {
34                 severThread = new Thread(new Runnable(){
35                         public void run() {
36                                 server = new AlarmSocketServer();
37                                 server.socketServer();
38                         }
39                 });
40                 severThread.start();
41                 CollectVo collectVo = new CollectVo();
42                 collectVo.setIP("127.0.0.1");
43                 collectVo.setPort("12345");
44                 collectVo.setUser("user");
45                 collectVo.setPassword("12345");
46                 collectVo.setReadTimeout("10000");
47                 taskThread = new AlarmTaskThread(collectVo);
48         }
49
50         @Test
51         public void build120Alarm() {
52                 String alarm = "{\"alarmSeq\":495,\"alarmTitle\":\"LTE cell outage\",\"alarmStatus\":1,\"alarmType\":\"processingErrorAlarm\"}";
53                 try {
54                         new Thread() {
55                                 public void run() {
56                                         try {
57                                                 Thread.sleep(3000);
58                                                 server.stop();
59                                                 taskThread.setStop(true);
60                                                 taskThread.close();
61                                         } catch (InterruptedException e) {
62                                                 // TODO Auto-generated catch block
63                                                 e.printStackTrace();
64                                         }
65                                 }
66                         }.start();
67                         taskThread.init();
68                         taskThread.receive();
69                 } catch (Exception e) {
70                         // TODO Auto-generated catch block
71                         e.printStackTrace();
72                 }
73                 assertNotNull(alarm);
74         }
75
76         @Test
77         public void runAlarmTaskThread() {
78                         taskThread.start();
79                         //Thread.sleep(3000);
80                         server.stop();
81                         severThread.stop();
82                         taskThread.setStop(true);
83                         taskThread.close();
84         }
85
86 }