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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.pnfsimulator.simulator.client;
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;
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;
37 class HttpClientAdapterImplTest {
39 private HttpClientAdapter adapter;
42 private HttpClient httpClient;
44 private HttpResponse httpResponse;
49 adapter = new HttpClientAdapterImpl(httpClient);
53 void send_should_successfully_send_request_given_valid_url() throws IOException {
54 doReturn(httpResponse).when(httpClient).execute(any());
56 adapter.send("test-msg", "http://valid-url");
58 verify(httpClient).execute(any());
59 verify(httpResponse).getStatusLine();
63 void send_should_not_send_request_given_invalid_url() throws IOException {
64 doThrow(new IOException("test")).when(httpClient).execute(any());
66 adapter.send("test-msg", "http://invalid-url");
68 verify(httpClient).execute(any());
69 verify(httpResponse, never()).getStatusLine();