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 PRODUCT_NAME = "NrRadio";
47 private static final String VENDOR_NAME = "Ericsson";
48 private static final String LAST_EPOCH_MICROSEC = "8745745764578";
49 private static final String SOURCE_NAME = "oteNB5309";
50 private static final String START_EPOCH_MICROSEC = "8745745764578";
51 private static final String TIME_ZONE_OFFSET = "UTC+05:00";
52 private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz";
54 private static ConsumerDmaapModel consumerDmaapModel;
55 private static DmaapPublisherTaskImpl dmaapPublisherTask;
56 private static DmaapProducerReactiveHttpClient dMaaPProducerReactiveHttpClient;
57 private static AppConfig appConfig;
58 private static DmaapPublisherConfiguration dmaapPublisherConfiguration;
61 public static void setUp() {
63 dmaapPublisherConfiguration = new ImmutableDmaapPublisherConfiguration.Builder()
64 .dmaapContentType("application/json")
65 .dmaapHostName("54.45.33.2")
66 .dmaapPortNumber(1234)
67 .dmaapProtocol("https")
69 .dmaapUserPassword("DFC")
70 .dmaapTopicName("unauthenticated.VES_NOTIFICATION_OUTPUT")
72 consumerDmaapModel = ImmutableConsumerDmaapModel.builder()
73 .productName(PRODUCT_NAME)
74 .vendorName(VENDOR_NAME)
75 .lastEpochMicrosec(LAST_EPOCH_MICROSEC)
76 .sourceName(SOURCE_NAME)
77 .startEpochMicrosec(START_EPOCH_MICROSEC)
78 .timeZoneOffset(TIME_ZONE_OFFSET)
80 .location("ftpes://192.168.0.101:22/ftp/rop/" + PM_FILE_NAME)
81 .internalLocation("target/" + PM_FILE_NAME)
83 .fileFormatType("org.3GPP.32.435#measCollec")
84 .fileFormatVersion("V10")
86 appConfig = mock(AppConfig.class);
91 public void whenPassedObjectFits_ReturnsCorrectStatus() {
92 prepareMocksForTests(HttpStatus.OK.value());
94 StepVerifier.create(dmaapPublisherTask.execute(consumerDmaapModel)).expectNext("200").verifyComplete();
96 verify(dMaaPProducerReactiveHttpClient, times(1)).getDmaapProducerResponse(any());
97 verifyNoMoreInteractions(dMaaPProducerReactiveHttpClient);
100 private void prepareMocksForTests(Integer httpResponseCode) {
101 dMaaPProducerReactiveHttpClient = mock(DmaapProducerReactiveHttpClient.class);
102 when(dMaaPProducerReactiveHttpClient.getDmaapProducerResponse(any()))
103 .thenReturn(Flux.just(httpResponseCode.toString()));
104 when(appConfig.getDmaapPublisherConfiguration()).thenReturn(dmaapPublisherConfiguration);
105 dmaapPublisherTask = spy(new DmaapPublisherTaskImpl(appConfig));
106 when(dmaapPublisherTask.resolveConfiguration()).thenReturn(dmaapPublisherConfiguration);
107 doReturn(dMaaPProducerReactiveHttpClient).when(dmaapPublisherTask).resolveClient();