4f4cbd28d306a47e65174242e8ddf5d3f178534c
[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 gzPath = System.getProperty("user.dir")+"/data/" +"PM-ENB-EUTRANCELLNB-testa.csv.gz";
36         private TaskThread taskThread;
37         private List<File> list = null;
38         @Before
39     public void setUp() throws IOException {
40                 taskThread = new TaskThread();
41                 taskThread.pmResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_CHANNEL_KEY);
42                 Gzip gzip = new Gzip();
43                 gzip.compress(csvPath, gzPath);
44     }
45         
46         @Test
47         public void decompressed(){
48                 list = taskThread.decompressed(gzPath);
49                 assertTrue(list.size() > 0);
50                 new File(gzPath).delete();
51         }
52
53         @Test
54         public void processPMCsv(){
55                 list = taskThread.decompressed(gzPath);
56                 for(File file : list){
57                         boolean re = taskThread.processPMCsv(file);
58                         assertTrue(re);
59                 }
60         }
61         
62         @Test
63         public void parseFtpAndSendMessage(){
64                 CollectVo collectVo = new CollectVo();
65                 collectVo.setType("ems-p");
66                 taskThread.parseFtpAndSendMessage(gzPath,collectVo);
67         }
68         
69         @Test
70         public void createMessage(){
71                 CollectVo collectVo = new CollectVo();
72                 collectVo.setType("ems-p");
73                 taskThread.createMessage("zipName", "user", "pwd", "ip", "port", 122, "nename");
74         }
75         
76         
77         
78         
79         
80         @After
81     public void setDown() throws IOException {
82                 new File(gzPath).delete();
83                 new File(gzPath.replace(".gz", "")).delete();
84     }
85 }