2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
4 * ===============================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6 * in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License
11 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing permissions and limitations under
14 * ============LICENSE_END========================================================================
17 package org.onap.dcaegen2.collectors.datafile.tasks;
19 import static org.mockito.ArgumentMatchers.any;
20 import static org.mockito.Mockito.doReturn;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.spy;
23 import static org.mockito.Mockito.times;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.verifyNoMoreInteractions;
26 import static org.mockito.Mockito.when;
28 import org.junit.jupiter.api.BeforeAll;
29 import org.junit.jupiter.api.Test;
30 import org.onap.dcaegen2.collectors.datafile.config.DmaapPublisherConfiguration;
31 import org.onap.dcaegen2.collectors.datafile.config.ImmutableDmaapPublisherConfiguration;
32 import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
33 import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
34 import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
35 import org.onap.dcaegen2.collectors.datafile.service.producer.DmaapProducerReactiveHttpClient;
36 import org.springframework.http.HttpStatus;
38 import reactor.core.publisher.Flux;
39 import reactor.test.StepVerifier;
42 * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18
43 * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
45 class DmaapPublisherTaskImplTest {
46 private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz";
48 private static ConsumerDmaapModel consumerDmaapModel;
49 private static DmaapPublisherTaskImpl dmaapPublisherTask;
50 private static DmaapProducerReactiveHttpClient dMaaPProducerReactiveHttpClient;
51 private static AppConfig appConfig;
52 private static DmaapPublisherConfiguration dmaapPublisherConfiguration;
55 public static void setUp() {
56 dmaapPublisherConfiguration =
57 new ImmutableDmaapPublisherConfiguration.Builder().dmaapContentType("application/json")
58 .dmaapHostName("54.45.33.2").dmaapPortNumber(1234).dmaapProtocol("https").dmaapUserName("DFC")
59 .dmaapUserPassword("DFC").dmaapTopicName("unauthenticated.VES_NOTIFICATION_OUTPUT").build();
60 consumerDmaapModel = ImmutableConsumerDmaapModel.builder().name(PM_FILE_NAME).location("target/" + PM_FILE_NAME)
61 .compression("gzip").fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
62 appConfig = mock(AppConfig.class);
66 public void whenPassedObjectFits_ReturnsCorrectStatus() {
67 prepareMocksForTests(HttpStatus.OK.value());
69 StepVerifier.create(dmaapPublisherTask.execute(consumerDmaapModel)).expectNext("200").verifyComplete();
71 verify(dMaaPProducerReactiveHttpClient, times(1)).getDmaapProducerResponse(any());
72 verifyNoMoreInteractions(dMaaPProducerReactiveHttpClient);
75 private void prepareMocksForTests(Integer httpResponseCode) {
76 dMaaPProducerReactiveHttpClient = mock(DmaapProducerReactiveHttpClient.class);
77 when(dMaaPProducerReactiveHttpClient.getDmaapProducerResponse(any()))
78 .thenReturn(Flux.just(httpResponseCode.toString()));
79 when(appConfig.getDmaapPublisherConfiguration()).thenReturn(dmaapPublisherConfiguration);
80 dmaapPublisherTask = spy(new DmaapPublisherTaskImpl(appConfig));
81 when(dmaapPublisherTask.resolveConfiguration()).thenReturn(dmaapPublisherConfiguration);
82 doReturn(dMaaPProducerReactiveHttpClient).when(dmaapPublisherTask).resolveClient();