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.dmaap.client.service.consumer;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
26 import com.google.gson.JsonArray;
28 import java.util.Optional;
29 import org.apache.http.entity.ContentType;
30 import org.junit.jupiter.api.Assertions;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
34 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
35 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPClientServiceUtils;
36 import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
37 import reactor.core.publisher.Mono;
38 import reactor.test.StepVerifier;
41 * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 6/27/18
43 class DMaaPConsumerReactiveHttpClientTest {
45 private static final String JSON_MESSAGE = "{ \"responseFromDmaap\": \"Success\"}";
46 private DMaaPConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient;
47 private DmaapConsumerConfiguration consumerConfigurationMock = mock(DmaapConsumerConfiguration.class);
48 private Mono<JsonArray> expectedResult;
49 private CloudHttpClient httpClient = mock(CloudHttpClient.class);
50 private URI exampleTestUri = URI
51 .create("https://54.45.33.2:1234/unauthenticated.SEC_OTHER_OUTPUT/OpenDCAE-c12/c12");
52 private RequestDiagnosticContext requestDiagnosticContext = mock(RequestDiagnosticContext.class);
56 when(consumerConfigurationMock.dmaapHostName()).thenReturn("54.45.33.2");
57 when(consumerConfigurationMock.dmaapProtocol()).thenReturn("https");
58 when(consumerConfigurationMock.dmaapPortNumber()).thenReturn(1234);
59 when(consumerConfigurationMock.dmaapUserName()).thenReturn("PRH");
60 when(consumerConfigurationMock.dmaapUserPassword()).thenReturn("PRH");
61 when(consumerConfigurationMock.dmaapContentType()).thenReturn(ContentType.APPLICATION_JSON.getMimeType());
62 when(consumerConfigurationMock.dmaapTopicName()).thenReturn("unauthenticated.SEC_OTHER_OUTPUT");
63 when(consumerConfigurationMock.consumerGroup()).thenReturn("OpenDCAE-c12");
64 when(consumerConfigurationMock.consumerId()).thenReturn("c12");
65 dmaapConsumerReactiveHttpClient = new DMaaPConsumerReactiveHttpClient(consumerConfigurationMock, httpClient);
69 void getHttpResponse_Success() {
71 expectedResult = Mono.just(mock(JsonArray.class));
72 when(httpClient.get(exampleTestUri.toString(), requestDiagnosticContext, DMaaPClientServiceUtils.getHeaders(ContentType.APPLICATION_JSON.getMimeType()), JsonArray.class))
73 .thenReturn(expectedResult);
75 Mono<JsonArray> response = dmaapConsumerReactiveHttpClient
76 .getDMaaPConsumerResponse(Optional.of(requestDiagnosticContext));
78 StepVerifier.create(response).expectSubscription()
79 .expectNextMatches(results -> {
80 Assertions.assertEquals(results, expectedResult.block());
86 void getAppropriateUri_whenPassingCorrectedPathForPnf() {
87 Assertions.assertEquals(dmaapConsumerReactiveHttpClient.getUri(), exampleTestUri);