Code Improvements-Vnfsdk-refrepo sonar issue fixes
[vnfsdk/refrepo.git] / vnfmarket-be / vnf-sdk-marketplace / src / test / java / org / onap / vnfsdk / marketplace / rest / RestfulClientTest.java
1 /**
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  * <p>
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  * <p>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p>
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.vnfsdk.marketplace.rest;
18
19 import org.apache.http.HttpEntity;
20 import org.apache.http.HttpHost;
21 import org.apache.http.HttpRequest;
22 import org.apache.http.HttpResponse;
23 import org.apache.http.impl.client.CloseableHttpClient;
24 import org.junit.Before;
25 import org.junit.Test;
26
27 import static org.junit.Assert.*;
28 import static org.mockito.Mockito.mock;
29 import static org.onap.vnfsdk.marketplace.rest.RestfulClient.HttpMethod.PUT;
30 import static org.powermock.api.mockito.PowerMockito.when;
31
32 public class RestfulClientTest {
33
34
35     private RestfulClient restfulClient;
36     private HttpEntity entity;
37
38     @Before
39     public void setUp() {
40         restfulClient = new RestfulClient();
41         entity = mock(HttpEntity.class);
42     }
43
44
45     @Test
46     public void testGet() {
47         assertNotNull(RestfulClient.get("172.11.10.22,1212", 1211, "http://localhost"));
48     }
49
50     @Test
51     public void testPost() {
52         assertNotNull(RestfulClient.post("172.11.10.22,1212", 1211, "http://localhost", null));
53     }
54
55     @Test
56     public void testDelete() {
57         assertNotNull(RestfulClient.delete("172.11.10.22,1212", 1211, "http://localhost"));
58     }
59
60     @Test
61     public void testSendPostRequest() {
62         RestfulClient.sendPostRequest("172.11.10.22,1212", "1211", "http://www.engineering.uiowa.edu/~hawkeng//fall01/graphics/potato.gif", "jason");
63         HttpResponse httpResponse = mock(HttpResponse.class);
64         HttpEntity httpEntity = mock(HttpEntity.class);
65         when(httpResponse.getEntity()).thenReturn(httpEntity);
66         assertEquals(httpResponse.getEntity(), httpEntity);
67
68     }
69
70     @Test
71     public void testExecuteHttp() throws  Exception{
72         assertNotNull(RestfulClient.executeHttp(PUT, "172.11.10.22,1212", 1211, "http://localhost", null));
73         /*HttpResponse httpResponse = mock(HttpResponse.class);
74         CloseableHttpClient httpclient= mock(CloseableHttpClient.class);
75         HttpEntity httpEntity= mock(HttpEntity.class);
76         when(httpResponse.getEntity()).thenReturn(null);
77         assertEquals(httpResponse.getEntity(), null);*/
78
79
80     }
81
82 }