3e9972afc6b09d12b9817fd9cb7f3790f30d0929
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / service / csm / connect / HttpRequestsTest.java
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.assertNotNull;
20 import static org.junit.Assert.assertTrue;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.commons.httpclient.Header;
26 import org.junit.Test;
27 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmException;
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
40         @Test
41         public void addHeadersTest() {
42                 Header header = new Header();
43                 builder.addHeaders(header, header);
44                 assertNotNull(builder);
45         }
46
47         @Test
48         public void addHeadersListTest() {
49                 List<Header> list = new ArrayList<>();
50                 Header header = new Header();
51                 list.add(header);
52                 builder.addHeaders(list);
53                 assertNotNull(builder);
54         }
55
56         @Test(expected = VnfmException.class)
57         public void setUrlTestException() throws VnfmException {
58                 String url = null;
59                 String path = null;
60                 builder.setUrl(url, path);
61         }
62
63         @Test(expected = VnfmException.class)
64         public void setUrlTestException2() throws VnfmException {
65                 String url = "";
66                 String path = null;
67                 builder.setUrl(url, path);
68         }
69
70         @Test(expected = VnfmException.class)
71         public void setUrlTestNormal() throws VnfmException {
72                 String url = "/test/123";
73                 String path = "http://localhost:8080";
74                 builder.setUrl(url, path);
75         }
76
77         @Test(expected = VnfmException.class)
78         public void setUrl2TestException() throws VnfmException {
79                 String url = null;
80                 String path = null;
81                 builder.setUrl(url, path, 101);
82         }
83
84         @Test(expected = VnfmException.class)
85         public void setUrl2TestException2() throws VnfmException {
86                 String url = "";
87                 String path = null;
88                 builder.setUrl(url, path, 101);
89         }
90
91         @Test(expected = VnfmException.class)
92         public void setUrl2TestNormal() throws VnfmException {
93                 String url = "/test/123";
94                 String path = "http://localhost:8080";
95                 builder.setUrl(url, path, 101);
96         }
97
98         @Test(expected = Exception.class)
99         public void requestTestException() {
100                 String res = builder.request();
101                 assertNotNull(res);
102         }
103
104         @Test
105         public void postTest() throws VnfmException {
106                 assertNotNull(builder.post());
107         }
108
109         @Test
110         public void putTest() throws VnfmException {
111                 assertNotNull(builder.put());
112         }
113
114         @Test
115         public void getTest() throws VnfmException {
116                 assertNotNull(builder.get());
117         }
118
119         @Test
120         public void deleteTest() throws VnfmException {
121                 assertNotNull(builder.delete());
122         }
123
124         @Test
125         public void setParamsTest() throws VnfmException {
126                 String json = "test";
127                 assertNotNull(builder.setParams(json));
128         }
129         
130         @Test
131         public void setEncodingTest() throws VnfmException {
132                 String json = "test";
133                 assertNotNull(builder.setEncoding(json));
134         }
135
136 }