81d63d5d4eb98d532942f5290fb4e8b680ed4081
[vfc/nfvo/wfengine.git] / wfenginemgrservice / src / test / java / org / onap / workflow / resources / RestClientTest.java
1 /**
2  * Copyright 2017 ZTE Corporation.
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.workflow.resources;
18
19 import static org.powermock.api.mockito.PowerMockito.mock;
20
21 import org.apache.http.HttpEntity;
22 import org.apache.http.HttpHost;
23 import org.apache.http.HttpRequest;
24 import org.apache.http.client.methods.CloseableHttpResponse;
25 import org.apache.http.impl.client.CloseableHttpClient;
26 import org.apache.http.impl.client.HttpClients;
27 import org.junit.After;
28 import org.junit.AfterClass;
29 import org.junit.Before;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mockito;
34 import org.onap.workflow.common.RestClient;
35 import org.onap.workflow.common.RestClient.HttpMethod;
36 import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
37 import org.powermock.api.mockito.PowerMockito;
38 import org.powermock.core.classloader.annotations.PowerMockIgnore;
39 import org.powermock.core.classloader.annotations.PrepareForTest;
40 import org.powermock.modules.junit4.PowerMockRunner;
41
42
43 @PrepareForTest({RestClient.class, HttpClients.class})
44 @RunWith(PowerMockRunner.class)
45 @PowerMockIgnore("javax.net.ssl.*")
46 public class RestClientTest {
47   private RestClient restClient;
48   @BeforeClass
49   public static void setUpBeforeClass() throws Exception {}
50
51   @AfterClass
52   public static void tearDownAfterClass() throws Exception {}
53
54   @Before
55   public void setUp() throws Exception {
56     restClient = new RestClient();
57
58   }
59
60   @After
61   public void tearDown() throws Exception {}
62
63   @Test
64   public final void testExecuteHttp() throws Exception {
65     HttpEntity httpEntity = mock(HttpEntity.class);
66     PowerMockito.mockStatic(HttpClients.class);
67     CloseableHttpClient tt = mock(CloseableHttpClient.class);
68     CloseableHttpResponse reponse = mock(CloseableHttpResponse.class);
69     PowerMockito.when(HttpClients.createDefault()).thenReturn(tt);
70     PowerMockito.when(tt.execute(Mockito.any(HttpHost.class), Mockito.any(HttpRequest.class)))
71         .thenReturn(reponse);
72     PowerMockito.when(reponse.getEntity()).thenReturn(httpEntity);
73     restClient.executeHttp(HttpMethod.POST, "127.0.0.1", 80, "test", httpEntity);
74   }
75
76   @Test
77   public final void testExecuteHttpDeleteDeploy() throws Exception {
78     HttpEntity httpEntity = mock(HttpEntity.class);
79     PowerMockito.mockStatic(HttpClients.class);
80     CloseableHttpClient tt = mock(CloseableHttpClient.class);
81     CloseableHttpResponse reponse = mock(CloseableHttpResponse.class);
82     PowerMockito.when(HttpClients.createDefault()).thenReturn(tt);
83     PowerMockito.when(tt.execute(Mockito.any(HttpHost.class), Mockito.any(HttpRequest.class)))
84         .thenReturn(reponse);
85     PowerMockito.when(reponse.getEntity()).thenReturn(httpEntity);
86     restClient.executeHttpDeleteDeploy(HttpMethod.DELETE, "127.0.0.1", 80, "test");
87   }
88
89   @Test
90   public final void testExecuteHttpStartIntance() throws Exception {
91
92     ActivitiStartProcessRequest activitiStartProcessRequest =
93         mock(ActivitiStartProcessRequest.class);
94
95     HttpEntity httpEntity = mock(HttpEntity.class);
96     PowerMockito.mockStatic(HttpClients.class);
97     CloseableHttpClient tt = mock(CloseableHttpClient.class);
98     CloseableHttpResponse reponse = mock(CloseableHttpResponse.class);
99     PowerMockito.when(HttpClients.createDefault()).thenReturn(tt);
100     PowerMockito.when(tt.execute(Mockito.any(HttpHost.class), Mockito.any(HttpRequest.class)))
101         .thenReturn(reponse);
102     PowerMockito.when(reponse.getEntity()).thenReturn(httpEntity);
103     restClient.executeHttpStartIntance(HttpMethod.POST, "127.0.0.1", 80, "test",activitiStartProcessRequest);
104
105   }
106 }