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.
17 package org.onap.vnfsdk.marketplace.rest;
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;
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;
32 public class RestfulClientTest {
35 private RestfulClient restfulClient;
36 private HttpEntity entity;
40 restfulClient = new RestfulClient();
41 entity = mock(HttpEntity.class);
46 public void testGet() {
47 assertNotNull(RestfulClient.get("172.11.10.22,1212", 1211, "http://localhost"));
51 public void testPost() {
52 assertNotNull(RestfulClient.post("172.11.10.22,1212", 1211, "http://localhost", null));
56 public void testDelete() {
57 assertNotNull(RestfulClient.delete("172.11.10.22,1212", 1211, "http://localhost"));
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);
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);*/