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;
31 import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
32 import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
33 import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
34 import org.onap.dcaegen2.collectors.datafile.service.producer.DmaapProducerReactiveHttpClient;
35 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
36 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration;
37 import org.springframework.http.HttpStatus;
39 import reactor.core.publisher.Flux;
40 import reactor.test.StepVerifier;
43 * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18
44 * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
46 class DmaapPublisherTaskImplTest {
47 private static final String PRODUCT_NAME = "NrRadio";
48 private static final String VENDOR_NAME = "Ericsson";
49 private static final String LAST_EPOCH_MICROSEC = "8745745764578";
50 private static final String SOURCE_NAME = "oteNB5309";
51 private static final String START_EPOCH_MICROSEC = "8745745764578";
52 private static final String TIME_ZONE_OFFSET = "UTC+05:00";
53 private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz";
55 private static ConsumerDmaapModel consumerDmaapModel;
56 private static DmaapPublisherTaskImpl dmaapPublisherTask;
57 private static DmaapProducerReactiveHttpClient dMaaPProducerReactiveHttpClient;
58 private static AppConfig appConfig;
59 private static DmaapPublisherConfiguration dmaapPublisherConfiguration;
62 public static void setUp() {
64 dmaapPublisherConfiguration = new ImmutableDmaapPublisherConfiguration.Builder()
65 .dmaapContentType("application/json")
66 .dmaapHostName("54.45.33.2")
67 .dmaapPortNumber(1234)
68 .dmaapProtocol("https")
70 .dmaapUserPassword("DFC")
71 .dmaapTopicName("unauthenticated.VES_NOTIFICATION_OUTPUT")
72 .trustStorePath("trustStorePath")
73 .trustStorePasswordPath("trustStorePasswordPath")
74 .keyStorePath("keyStorePath")
75 .keyStorePasswordPath("keyStorePasswordPath")
76 .enableDmaapCertAuth(true)
78 consumerDmaapModel = ImmutableConsumerDmaapModel.builder()
79 .productName(PRODUCT_NAME)
80 .vendorName(VENDOR_NAME)
81 .lastEpochMicrosec(LAST_EPOCH_MICROSEC)
82 .sourceName(SOURCE_NAME)
83 .startEpochMicrosec(START_EPOCH_MICROSEC)
84 .timeZoneOffset(TIME_ZONE_OFFSET)
86 .location("ftpes://192.168.0.101:22/ftp/rop/" + PM_FILE_NAME)
87 .internalLocation("target/" + PM_FILE_NAME)
89 .fileFormatType("org.3GPP.32.435#measCollec")
90 .fileFormatVersion("V10")
92 appConfig = mock(AppConfig.class);
97 public void whenPassedObjectFits_ReturnsCorrectStatus() {
98 prepareMocksForTests(HttpStatus.OK.value());
100 StepVerifier.create(dmaapPublisherTask.execute(consumerDmaapModel)).expectNext("200").verifyComplete();
102 verify(dMaaPProducerReactiveHttpClient, times(1)).getDmaapProducerResponse(any());
103 verifyNoMoreInteractions(dMaaPProducerReactiveHttpClient);
106 private void prepareMocksForTests(Integer httpResponseCode) {
107 dMaaPProducerReactiveHttpClient = mock(DmaapProducerReactiveHttpClient.class);
108 when(dMaaPProducerReactiveHttpClient.getDmaapProducerResponse(any()))
109 .thenReturn(Flux.just(httpResponseCode.toString()));
110 when(appConfig.getDmaapPublisherConfiguration()).thenReturn(dmaapPublisherConfiguration);
111 dmaapPublisherTask = spy(new DmaapPublisherTaskImpl(appConfig));
112 when(dmaapPublisherTask.resolveConfiguration()).thenReturn(dmaapPublisherConfiguration);
113 doReturn(dMaaPProducerReactiveHttpClient).when(dmaapPublisherTask).resolveClient();