48596b3d9f9c64a17ab587095b72766f2c8e5776
[integration.git] /
1 package org.onap.pnfsimulator.simulator.client;
2
3 import static org.mockito.ArgumentMatchers.any;
4 import static org.mockito.Mockito.doReturn;
5 import static org.mockito.Mockito.doThrow;
6 import static org.mockito.Mockito.never;
7 import static org.mockito.Mockito.verify;
8 import static org.mockito.MockitoAnnotations.initMocks;
9
10 import java.io.IOException;
11 import org.apache.http.HttpResponse;
12 import org.apache.http.client.HttpClient;
13 import org.junit.jupiter.api.BeforeEach;
14 import org.junit.jupiter.api.Test;
15 import org.mockito.Mock;
16
17 class HttpClientAdapterImplTest {
18
19     private HttpClientAdapter adapter;
20
21     @Mock
22     private HttpClient httpClient;
23     @Mock
24     private HttpResponse httpResponse;
25
26     @BeforeEach
27     void setup() {
28         initMocks(this);
29         adapter = new HttpClientAdapterImpl(httpClient);
30     }
31
32     @Test
33     void send_should_successfully_send_request_given_valid_url() throws IOException {
34         doReturn(httpResponse).when(httpClient).execute(any());
35
36         adapter.send("test-msg", "http://valid-url");
37
38         verify(httpClient).execute(any());
39         verify(httpResponse).getStatusLine();
40     }
41
42     @Test
43     void send_should_not_send_request_given_invalid_url() throws IOException {
44         doThrow(new IOException("test")).when(httpClient).execute(any());
45
46         adapter.send("test-msg", "http://invalid-url");
47
48         verify(httpClient).execute(any());
49         verify(httpResponse, never()).getStatusLine();
50     }
51 }