Update URL according to microservice name
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / test / java / org / openo / nfvo / 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.openo.nfvo.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.openo.nfvo.vnfmadapter.common.VnfmException;
27
28 public class HttpRequestsTest {
29
30     String authenticateMode = "test";
31     HttpRequests.Builder builder = new HttpRequests.Builder(authenticateMode);
32
33     @Test
34     public void addHeaderTest(){
35         builder.addHeader("id", "1234");
36         assertTrue(true);
37     }
38     @Test
39     public void addHeadersTest(){
40         Header header = new Header();
41         builder.addHeaders(header, header);
42         assertNotNull(builder);
43     }
44     @Test
45     public void addHeadersListTest(){
46         List<Header> list = new ArrayList<>();
47         Header header = new Header();
48         list.add(header);
49         builder.addHeaders(list);
50         assertNotNull(builder);
51     }
52
53     @Test(expected = VnfmException.class)
54     public void setUrlTestException() throws VnfmException{
55         String url=null;
56         String path=null;
57         builder.setUrl(url, path);
58     }
59     @Test(expected = VnfmException.class)
60     public void setUrlTestException2() throws VnfmException{
61         String url="";
62         String path=null;
63         builder.setUrl(url, path);
64     }
65
66     @Test(expected = VnfmException.class)
67     public void setUrlTestNormal() throws VnfmException{
68         String url="/test/123";
69         String path="http://localhost:8080";
70         builder.setUrl(url, path);
71     }
72
73     @Test(expected = VnfmException.class)
74     public void setUrl2TestException() throws VnfmException{
75         String url=null;
76         String path=null;
77         builder.setUrl(url, path,101);
78     }
79     @Test(expected = VnfmException.class)
80     public void setUrl2TestException2() throws VnfmException{
81         String url="";
82         String path=null;
83         builder.setUrl(url, path,101);
84     }
85
86     @Test(expected = VnfmException.class)
87     public void setUrl2TestNormal() throws VnfmException{
88         String url="/test/123";
89         String path="http://localhost:8080";
90         builder.setUrl(url, path,101);
91     }
92     @Test(expected = Exception.class)
93     public void requestTestException(){
94         String res = builder.request();
95         assertNotNull(res);
96     }
97
98 }