2 * ============LICENSE_START=======================================================
3 * DCAEGEN2-SERVICES-SDK
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.dcaegen2.services.sdk.rest.services.adapters.http;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import org.junit.jupiter.api.Test;
26 import reactor.core.publisher.Mono;
27 import reactor.netty.DisposableServer;
28 import reactor.netty.http.client.HttpClient;
29 import reactor.netty.http.server.HttpServer;
30 import reactor.netty.resources.ConnectionProvider;
31 import reactor.test.StepVerifier;
33 class CloudHttpClientIT {
35 private static final String SAMPLE_URL = "/sampleURL";
36 private static final int MAX_CONNECTIONS = 1;
37 private static final ConnectionProvider connectionProvider = ConnectionProvider.fixed("test", MAX_CONNECTIONS);
50 void successfulGetResponse() {
51 String sampleString = "sampleString";
52 Mono<String> response = Mono.just(sampleString);
53 DisposableServer server =
55 .handle((req, resp) -> resp.sendString(response))
58 HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider);
59 CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient);
61 Mono<String> content = cloudHttpClient.get(SAMPLE_URL, String.class);
63 StepVerifier.create(content)
64 .expectNext(sampleString)
71 void errorGetRequest() {
72 DisposableServer server =
74 .handle((req, resp) -> Mono.error(new Exception("returnError")))
77 HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider);
78 CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient);
80 Mono<String> content = cloudHttpClient.get(SAMPLE_URL, String.class);
82 StepVerifier.create(content)
88 private HttpClient createHttpClientForContextWithAddress(DisposableServer context) {
89 return createHttpClientForContextWithAddress(context, null);
92 private HttpClient createHttpClientForContextWithAddress(DisposableServer disposableServer,
93 ConnectionProvider connectionProvider) {
94 HttpClient client = connectionProvider == null? HttpClient.create() : HttpClient.create(connectionProvider);
95 return client.addressSupplier(disposableServer::address).wiretap(true);