2 * Copyright 2017 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.openo.nfvo.vnfmadapter.common;
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;
26 import javax.servlet.http.HttpServletRequest;
29 * Created by QuanZhong on 2017/3/17.
31 public class DownloadCsarManagerTest {
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);
43 public void downloadTest(){
44 DownloadCsarManager.download("http://www.baidu.com");
45 DownloadCsarManager.download("http://www.baidu.com","/opt");
46 DownloadCsarManager.getRandomFileName();
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);
57 public void testUnzip(){
58 DownloadCsarManager.unzipCSAR("test.zip","/opt");
62 public void testJsonUtils(){
63 MockHttpServletRequest req = new MockHttpServletRequest();
64 req.setContent("[{'abc':123}]".getBytes());
65 VnfmJsonUtil.getJsonFromContexts(req);
68 public void testJsonUtils2(){
69 MockHttpServletRequest req = new MockHttpServletRequest();
70 req.setContent("{'abc':123}".getBytes());
71 VnfmJsonUtil.getJsonFromContexts(req);