2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Samsung. 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.so.adapters.vevnfm.service;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.never;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mock;
31 import org.mockito.junit.MockitoJUnitRunner;
32 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinks;
33 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance;
34 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification;
35 import org.onap.so.adapters.vevnfm.aai.AaiConnection;
36 import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
37 import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
39 @RunWith(MockitoJUnitRunner.class)
40 public class DmaapConditionalSenderTest {
42 private static final String GENERIC_ID = "gener77";
43 private static final String INSTANCE_ID = "insta44";
44 private static final String HREF = "/href";
47 private ConfigProperties configProperties;
50 private AaiConnection aaiConnection;
53 private DmaapService dmaapService;
55 private static VnfLcmOperationOccurrenceNotification createNotification() {
56 final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification();
57 final LcnVnfLcmOperationOccurrenceNotificationLinks links = new LcnVnfLcmOperationOccurrenceNotificationLinks();
58 final LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance vnfInstance =
59 new LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance();
61 notification.setVnfInstanceId(INSTANCE_ID);
62 notification.setLinks(links);
63 links.setVnfInstance(vnfInstance);
64 vnfInstance.setHref(HREF);
70 public void testSendNone() {
72 when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.NONE);
74 final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
75 final VnfLcmOperationOccurrenceNotification notification = createNotification();
78 sender.send(notification);
81 verify(aaiConnection, never()).receiveGenericVnfId(any());
82 verify(dmaapService, never()).send(any(), any());
86 public void testSendAll() {
88 when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.ALL);
89 when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(GENERIC_ID);
91 final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
92 final VnfLcmOperationOccurrenceNotification notification = createNotification();
95 sender.send(notification);
98 verify(aaiConnection).receiveGenericVnfId(eq(HREF));
99 verify(dmaapService).send(eq(notification), eq(GENERIC_ID));
103 public void testSendAaiCheckedPresent() {
105 when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.AAI_CHECKED);
106 when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(GENERIC_ID);
108 final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
109 final VnfLcmOperationOccurrenceNotification notification = createNotification();
112 sender.send(notification);
115 verify(aaiConnection).receiveGenericVnfId(eq(HREF));
116 verify(dmaapService).send(eq(notification), eq(GENERIC_ID));
120 public void testSendAaiCheckedAbsent() {
122 when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.AAI_CHECKED);
123 when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(null);
125 final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
126 final VnfLcmOperationOccurrenceNotification notification = createNotification();
129 sender.send(notification);
132 verify(aaiConnection).receiveGenericVnfId(eq(HREF));
133 verify(dmaapService, never()).send(any(), any());