Modify emsdriver Code
[vfc/nfvo/driver/ems.git] / ems / boco / src / test / java / org / onap / vfc / nfvo / emsdriver / collector / TaskThreadTest.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;
17
18 import static org.junit.Assert.assertTrue;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.util.List;
23
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.onap.vfc.nfvo.emsdriver.collector.TaskThread;
28 import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant;
29 import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo;
30 import org.onap.vfc.nfvo.emsdriver.commons.utils.Gzip;
31 import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannelFactory;
32
33 public class TaskThreadTest {
34         private String csvPath = System.getProperty("user.dir")+"/data/" +"PM-ENB-EUTRANCELLNB-test.csv";
35         private String xmlPath = System.getProperty("user.dir")+"/data/" +"PM-test.xml";
36         private String gzPath = System.getProperty("user.dir")+"/data/" +"PM-ENB-EUTRANCELLNB-testa.csv.gz";
37         private TaskThread taskThread;
38         private List<File> list = null;
39         @Before
40     public void setUp() throws IOException {
41                 taskThread = new TaskThread();
42                 taskThread.pmResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_RESULT_PM_CHANNEL_KEY);
43                 Gzip gzip = new Gzip();
44                 gzip.compress(csvPath, gzPath);
45     }
46         
47         @Test
48         public void decompressed(){
49                 list = taskThread.decompressed(gzPath);
50                 assertTrue(list.size() > 0);
51                 new File(gzPath).delete();
52         }
53
54         @Test
55         public void processPMCsv(){
56                 list = taskThread.decompressed(gzPath);
57                 for(File file : list){
58                         boolean re = taskThread.processPMCsv(file);
59                         assertTrue(re);
60                 }
61         }
62         @Test
63         public void processPMXml(){
64                 File file = new File(xmlPath);
65                 boolean re = taskThread.processPMXml(file);
66                 assertTrue(re);
67                 System.out.println(taskThread.pmResultChannel.size()); 
68         }
69         
70         @Test
71         public void parseFtpAndSendMessage(){
72                 CollectVo collectVo = new CollectVo();
73                 collectVo.setType("ems-p");
74                 taskThread.parseFtpAndSendMessage(gzPath,collectVo);
75         }
76         
77         @Test
78         public void createMessage(){
79                 CollectVo collectVo = new CollectVo();
80                 collectVo.setType("ems-p");
81                 taskThread.createMessage("zipName", "user", "pwd", "ip", "port", 122, "nename");
82         }
83         
84         @After
85     public void setDown() throws IOException {
86                 new File(gzPath).delete();
87                 new File(gzPath.replace(".gz", "")).delete();
88     }
89 }