Refactor SOL003 Adapter to organize its modules
[so.git] / adapters / etsi-sol002-adapter / src / test / java / org / onap / so / adapters / vevnfm / service / DmaapConditionalSenderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.adapters.vevnfm.service;
22
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;
38
39 @RunWith(MockitoJUnitRunner.class)
40 public class DmaapConditionalSenderTest {
41
42     private static final String GENERIC_ID = "gener77";
43     private static final String INSTANCE_ID = "insta44";
44     private static final String HREF = "/href";
45
46     @Mock
47     private ConfigProperties configProperties;
48
49     @Mock
50     private AaiConnection aaiConnection;
51
52     @Mock
53     private DmaapService dmaapService;
54
55     private static VnfLcmOperationOccurrenceNotification createNotification() {
56         final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification();
57         final LcnVnfLcmOperationOccurrenceNotificationLinks links = new LcnVnfLcmOperationOccurrenceNotificationLinks();
58         final LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance vnfInstance =
59                 new LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance();
60
61         notification.setVnfInstanceId(INSTANCE_ID);
62         notification.setLinks(links);
63         links.setVnfInstance(vnfInstance);
64         vnfInstance.setHref(HREF);
65
66         return notification;
67     }
68
69     @Test
70     public void testSendNone() {
71         // given
72         when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.NONE);
73
74         final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
75         final VnfLcmOperationOccurrenceNotification notification = createNotification();
76
77         // when
78         sender.send(notification);
79
80         // then
81         verify(aaiConnection, never()).receiveGenericVnfId(any());
82         verify(dmaapService, never()).send(any(), any());
83     }
84
85     @Test
86     public void testSendAll() {
87         // given
88         when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.ALL);
89         when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(GENERIC_ID);
90
91         final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
92         final VnfLcmOperationOccurrenceNotification notification = createNotification();
93
94         // when
95         sender.send(notification);
96
97         // then
98         verify(aaiConnection).receiveGenericVnfId(eq(HREF));
99         verify(dmaapService).send(eq(notification), eq(GENERIC_ID));
100     }
101
102     @Test
103     public void testSendAaiCheckedPresent() {
104         // given
105         when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.AAI_CHECKED);
106         when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(GENERIC_ID);
107
108         final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
109         final VnfLcmOperationOccurrenceNotification notification = createNotification();
110
111         // when
112         sender.send(notification);
113
114         // then
115         verify(aaiConnection).receiveGenericVnfId(eq(HREF));
116         verify(dmaapService).send(eq(notification), eq(GENERIC_ID));
117     }
118
119     @Test
120     public void testSendAaiCheckedAbsent() {
121         // given
122         when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.AAI_CHECKED);
123         when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(null);
124
125         final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
126         final VnfLcmOperationOccurrenceNotification notification = createNotification();
127
128         // when
129         sender.send(notification);
130
131         // then
132         verify(aaiConnection).receiveGenericVnfId(eq(HREF));
133         verify(dmaapService, never()).send(any(), any());
134     }
135 }