Merge "switch drools pdp image to new one"
[integration.git] / test / mocks / mass-pnf-sim / pnf-sim-lightweight / src / test / java / org / onap / pnfsimulator / simulator / client / HttpClientAdapterImplTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.pnfsimulator.simulator.client;
22
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.doReturn;
25 import static org.mockito.Mockito.doThrow;
26 import static org.mockito.Mockito.never;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.MockitoAnnotations.initMocks;
29
30 import java.io.IOException;
31 import org.apache.http.HttpResponse;
32 import org.apache.http.client.HttpClient;
33 import org.junit.jupiter.api.BeforeEach;
34 import org.junit.jupiter.api.Test;
35 import org.mockito.Mock;
36
37 class HttpClientAdapterImplTest {
38
39     private HttpClientAdapter adapter;
40
41     @Mock
42     private HttpClient httpClient;
43     @Mock
44     private HttpResponse httpResponse;
45
46     @BeforeEach
47     void setup() {
48         initMocks(this);
49         adapter = new HttpClientAdapterImpl(httpClient);
50     }
51
52     @Test
53     void send_should_successfully_send_request_given_valid_url() throws IOException {
54         doReturn(httpResponse).when(httpClient).execute(any());
55
56         adapter.send("test-msg", "http://valid-url");
57
58         verify(httpClient).execute(any());
59         verify(httpResponse).getStatusLine();
60     }
61
62     @Test
63     void send_should_not_send_request_given_invalid_url() throws IOException {
64         doThrow(new IOException("test")).when(httpClient).execute(any());
65
66         adapter.send("test-msg", "http://invalid-url");
67
68         verify(httpClient).execute(any());
69         verify(httpResponse, never()).getStatusLine();
70     }
71 }