Change: add OPEN-O seed code for VF-C
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / test / java / org / openo / nfvo / vnfmadapter / common / DownloadCsarManagerTest.java
1 /*
2  * Copyright 2017 Huawei 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.openo.nfvo.vnfmadapter.common;
17
18 import org.apache.http.HttpResponse;
19 import org.apache.http.ProtocolVersion;
20 import org.apache.http.StatusLine;
21 import org.apache.http.message.BasicHttpResponse;
22 import org.apache.http.message.BasicStatusLine;
23 import org.junit.Test;
24 import org.springframework.mock.web.MockHttpServletRequest;
25
26 import javax.servlet.http.HttpServletRequest;
27
28 /**
29  * Created by QuanZhong on 2017/3/17.
30  */
31 public class DownloadCsarManagerTest {
32
33     @Test
34     public void getFileNameTest(){
35         ProtocolVersion version = new ProtocolVersion("HTTP",1,1);
36         StatusLine sl = new BasicStatusLine(version,200,"success");
37         HttpResponse response = new BasicHttpResponse(sl);
38         response.setHeader("Content-Disposition","filename");
39         DownloadCsarManager.getFileName(response);
40     }
41
42     @Test
43     public void downloadTest(){
44         DownloadCsarManager.download("http://www.baidu.com");
45         DownloadCsarManager.download("http://www.baidu.com","/opt");
46         DownloadCsarManager.getRandomFileName();
47     }
48     @Test
49     public void getFilePath(){
50         ProtocolVersion version = new ProtocolVersion("HTTP",1,1);
51         StatusLine sl = new BasicStatusLine(version,200,"success");
52         HttpResponse response = new BasicHttpResponse(sl);
53         response.setHeader("Content-Disposition","filename");
54         DownloadCsarManager.getFilePath(response);
55     }
56     @Test
57     public void testUnzip(){
58         DownloadCsarManager.unzipCSAR("test.zip","/opt");
59     }
60
61     @Test
62     public void testJsonUtils(){
63         MockHttpServletRequest req = new MockHttpServletRequest();
64         req.setContent("[{'abc':123}]".getBytes());
65         VnfmJsonUtil.getJsonFromContexts(req);
66     }
67     @Test
68     public void testJsonUtils2(){
69         MockHttpServletRequest req = new MockHttpServletRequest();
70         req.setContent("{'abc':123}".getBytes());
71         VnfmJsonUtil.getJsonFromContexts(req);
72     }
73
74 }