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