2 * ============LICENSE_START=======================================================
3 * BBS-RELOCATION-CPE-AUTHENTICATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2019 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.bbs.event.processor.tasks;
23 import static org.mockito.Mockito.doReturn;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.reset;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
29 import javax.net.ssl.SSLException;
31 import org.junit.Assert;
32 import org.junit.jupiter.api.AfterEach;
33 import org.junit.jupiter.api.BeforeAll;
34 import org.junit.jupiter.api.Test;
35 import org.onap.bbs.event.processor.config.ApplicationConfiguration;
36 import org.onap.bbs.event.processor.exceptions.EmptyDmaapResponseException;
37 import org.onap.bbs.event.processor.model.ImmutableReRegistrationConsumerDmaapModel;
38 import org.onap.bbs.event.processor.model.ReRegistrationConsumerDmaapModel;
39 import org.onap.bbs.event.processor.utilities.ReRegistrationDmaapConsumerJsonParser;
40 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
41 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration;
42 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer.ConsumerReactiveHttpClientFactory;
43 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer.DMaaPConsumerReactiveHttpClient;
45 import reactor.core.publisher.Mono;
46 import reactor.test.StepVerifier;
48 class DmaapReRegistrationConsumerTaskImplTest {
50 private static final String RE_REGISTRATION_EVENT_TEMPLATE = "{\"event\": {"
51 + "\"commonEventHeader\": { \"sourceName\":\"%s\"},"
52 + "\"additionalFields\": {"
53 + " \"attachment-point\": \"%s\","
54 + " \"remote-id\": \"%s\","
55 + " \"cvlan\": \"%s\","
56 + " \"svlan\": \"%s\""
59 private static DmaapReRegistrationConsumerTaskImpl dmaapConsumerTask;
60 private static ReRegistrationConsumerDmaapModel reRegistrationConsumerDmaapModel;
61 private static DMaaPConsumerReactiveHttpClient dMaaPConsumerReactiveHttpClient;
62 private static String message;
65 static void setUp() throws SSLException {
67 final String sourceName = "PNF-CorrelationId";
68 final String attachmentPoint = "olt2/2/2";
69 final String remoteId = "remoteId";
70 final String cvlan = "1005";
71 final String svlan = "100";
73 // Mock Re-registration configuration
74 DmaapConsumerConfiguration dmaapConsumerConfiguration = testVersionOfDmaapConsumerConfiguration();
75 ApplicationConfiguration configuration = mock(ApplicationConfiguration.class);
76 when(configuration.getDmaapReRegistrationConsumerConfiguration()).thenReturn(dmaapConsumerConfiguration);
78 // Mock reactive DMaaP client
79 ConsumerReactiveHttpClientFactory httpClientFactory = mock(ConsumerReactiveHttpClientFactory.class);
80 dMaaPConsumerReactiveHttpClient = mock(DMaaPConsumerReactiveHttpClient.class);
81 doReturn(dMaaPConsumerReactiveHttpClient).when(httpClientFactory).create(dmaapConsumerConfiguration);
83 dmaapConsumerTask = new DmaapReRegistrationConsumerTaskImpl(configuration,
84 new ReRegistrationDmaapConsumerJsonParser(), httpClientFactory);
86 reRegistrationConsumerDmaapModel = ImmutableReRegistrationConsumerDmaapModel.builder()
87 .correlationId(sourceName)
88 .attachmentPoint(attachmentPoint)
94 message = String.format("[" + RE_REGISTRATION_EVENT_TEMPLATE + "]",
104 reset(dMaaPConsumerReactiveHttpClient);
108 void passingEmptyMessage_NothingHappens() throws Exception {
109 when(dMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()).thenReturn(Mono.just(""));
111 StepVerifier.create(dmaapConsumerTask.execute("Sample input"))
112 .expectSubscription()
113 .expectError(EmptyDmaapResponseException.class);
114 verify(dMaaPConsumerReactiveHttpClient).getDMaaPConsumerResponse();
118 void passingNormalMessage_ResponseSucceeds() throws Exception {
119 when(dMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()).thenReturn(Mono.just(message));
121 StepVerifier.create(dmaapConsumerTask.execute("Sample input"))
122 .expectSubscription()
123 .consumeNextWith(e -> Assert.assertEquals(e, reRegistrationConsumerDmaapModel));
124 verify(dMaaPConsumerReactiveHttpClient).getDMaaPConsumerResponse();
127 private static DmaapConsumerConfiguration testVersionOfDmaapConsumerConfiguration() {
128 return new ImmutableDmaapConsumerConfiguration.Builder()
129 .consumerGroup("OpenDCAE-c12")
131 .dmaapContentType("application/json")
132 .dmaapHostName("message-router.onap.svc.cluster.local")
133 .dmaapPortNumber(3904)
134 .dmaapProtocol("http")
135 .dmaapUserName("admin")
136 .dmaapUserPassword("admin")
137 .trustStorePath("/opt/app/bbs/local/org.onap.bbs.trust.jks")
138 .trustStorePasswordPath("change_it")
139 .keyStorePath("/opt/app/bbs/local/org.onap.bbs.p12")
140 .keyStorePasswordPath("change_it")
141 .enableDmaapCertAuth(false)
142 .dmaapTopicName("/events/unauthenticated.PNF_REREGISTRATION")