185f2b28a1080607159e4f1ce4697e1392247213
[vfc/nfvo/driver/vnfm/svnfm.git] /
1 /*
2  * Copyright 2016 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
17 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect;
18
19 import static org.junit.Assert.*;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.apache.commons.httpclient.Header;
25 import org.junit.Test;
26 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmException;
27 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.HttpRequests;
28
29 public class HttpRequestsTest {
30
31     String authenticateMode = "test";
32     HttpRequests.Builder builder = new HttpRequests.Builder(authenticateMode);
33
34     @Test
35     public void addHeaderTest(){
36         builder.addHeader("id", "1234");
37         assertTrue(true);
38     }
39     @Test
40     public void addHeadersTest(){
41         Header header = new Header();
42         builder.addHeaders(header, header);
43         assertNotNull(builder);
44     }
45     @Test
46     public void addHeadersListTest(){
47         List<Header> list = new ArrayList<>();
48         Header header = new Header();
49         list.add(header);
50         builder.addHeaders(list);
51         assertNotNull(builder);
52     }
53
54     @Test(expected = VnfmException.class)
55     public void setUrlTestException() throws VnfmException{
56         String url=null;
57         String path=null;
58         builder.setUrl(url, path);
59     }
60     @Test(expected = VnfmException.class)
61     public void setUrlTestException2() throws VnfmException{
62         String url="";
63         String path=null;
64         builder.setUrl(url, path);
65     }
66
67     @Test(expected = VnfmException.class)
68     public void setUrlTestNormal() throws VnfmException{
69         String url="/test/123";
70         String path="http://localhost:8080";
71         builder.setUrl(url, path);
72     }
73
74     @Test(expected = VnfmException.class)
75     public void setUrl2TestException() throws VnfmException{
76         String url=null;
77         String path=null;
78         builder.setUrl(url, path,101);
79     }
80     @Test(expected = VnfmException.class)
81     public void setUrl2TestException2() throws VnfmException{
82         String url="";
83         String path=null;
84         builder.setUrl(url, path,101);
85     }
86
87     @Test(expected = VnfmException.class)
88     public void setUrl2TestNormal() throws VnfmException{
89         String url="/test/123";
90         String path="http://localhost:8080";
91         builder.setUrl(url, path,101);
92     }
93     @Test(expected = Exception.class)
94     public void requestTestException(){
95         String res = builder.request();
96         assertNotNull(res);
97     }
98
99 }