5af682dda8d1428bca4e212465eb65f31fb7b7ea
[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.Mockito.*;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mock;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinks;
29 import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance;
30 import org.onap.so.adapters.etsi.sol003.adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification;
31 import org.onap.so.adapters.vevnfm.aai.AaiConnection;
32 import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
33 import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
34
35 @RunWith(MockitoJUnitRunner.class)
36 public class DmaapConditionalSenderTest {
37
38     private static final String GENERIC_ID = "gener77";
39     private static final String INSTANCE_ID = "insta44";
40     private static final String HREF = "/href";
41
42     @Mock
43     private ConfigProperties configProperties;
44
45     @Mock
46     private AaiConnection aaiConnection;
47
48     @Mock
49     private DmaapService dmaapService;
50
51     private static VnfLcmOperationOccurrenceNotification createNotification() {
52         final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification();
53         final LcnVnfLcmOperationOccurrenceNotificationLinks links = new LcnVnfLcmOperationOccurrenceNotificationLinks();
54         final LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance vnfInstance =
55                 new LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance();
56
57         notification.setVnfInstanceId(INSTANCE_ID);
58         notification.setLinks(links);
59         links.setVnfInstance(vnfInstance);
60         vnfInstance.setHref(HREF);
61
62         return notification;
63     }
64
65     @Test
66     public void testSendNone() {
67         // given
68         when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.NONE);
69
70         final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
71         final VnfLcmOperationOccurrenceNotification notification = createNotification();
72
73         // when
74         sender.send(notification);
75
76         // then
77         verify(aaiConnection, never()).receiveGenericVnfId(any());
78         verify(dmaapService, never()).send(any(), any());
79     }
80
81     @Test
82     public void testSendAll() {
83         // given
84         when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.ALL);
85         when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(GENERIC_ID);
86
87         final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
88         final VnfLcmOperationOccurrenceNotification notification = createNotification();
89
90         // when
91         sender.send(notification);
92
93         // then
94         verify(aaiConnection).receiveGenericVnfId(eq(HREF));
95         verify(dmaapService).send(eq(notification), eq(GENERIC_ID));
96     }
97
98     @Test
99     public void testSendAaiCheckedPresent() {
100         // given
101         when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.AAI_CHECKED);
102         when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(GENERIC_ID);
103
104         final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
105         final VnfLcmOperationOccurrenceNotification notification = createNotification();
106
107         // when
108         sender.send(notification);
109
110         // then
111         verify(aaiConnection).receiveGenericVnfId(eq(HREF));
112         verify(dmaapService).send(eq(notification), eq(GENERIC_ID));
113     }
114
115     @Test
116     public void testSendAaiCheckedAbsent() {
117         // given
118         when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.AAI_CHECKED);
119         when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(null);
120
121         final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
122         final VnfLcmOperationOccurrenceNotification notification = createNotification();
123
124         // when
125         sender.send(notification);
126
127         // then
128         verify(aaiConnection).receiveGenericVnfId(eq(HREF));
129         verify(dmaapService, never()).send(any(), any());
130     }
131 }