1674519316fc5142f68bf18cbe3c2a48a23eed0b
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
4  *  ================================================================================
5  *  Copyright (C) 2022 Huawei Canada Limited.
6  *  Copyright (C) 2022 CTC, Inc.
7  *  ==============================================================================
8  *     Licensed under the Apache License, Version 2.0 (the "License");
9  *     you may not use this file except in compliance with the License.
10  *     You may obtain a copy of the License at
11  *
12  *          http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *     Unless required by applicable law or agreed to in writing, software
15  *     distributed under the License is distributed on an "AS IS" BASIS,
16  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *     See the License for the specific language governing permissions and
18  *     limitations under the License.
19  *     ============LICENSE_END=========================================================
20  *
21  *******************************************************************************/
22
23 package org.onap.slice.analysis.ms.dmaap;
24
25 import com.google.gson.JsonArray;
26 import com.google.gson.JsonObject;
27 import com.google.gson.JsonPrimitive;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.Spy;
35 import org.onap.slice.analysis.ms.models.Configuration;
36 import org.onap.slice.analysis.ms.service.ccvpn.BandwidthEvaluator;
37 import org.springframework.boot.test.context.SpringBootTest;
38 import org.springframework.test.context.junit4.SpringRunner;
39
40 import java.io.IOException;
41 import java.nio.file.Files;
42 import java.nio.file.Paths;
43
44 import static org.mockito.ArgumentMatchers.any;
45 import static org.powermock.api.mockito.PowerMockito.doNothing;
46
47
48 @RunWith(SpringRunner.class)
49 @SpringBootTest(classes = VesNotificationCallbackTest.class)
50 public class AaiEventNotificationCallbackTest {
51
52     @Spy
53     @InjectMocks
54     AaiEventNotificationCallback aaiEventNotificationCallback;
55
56     @Mock
57     BandwidthEvaluator bandwidthEvaluator;
58
59     @Before
60     public void initConfiguration() {
61         JsonObject jsonObject = new JsonObject();
62         jsonObject.addProperty("sliceanalysisms.aaiNotif.targetAction", "UPDATE");
63         jsonObject.addProperty("sliceanalysisms.aaiNotif.targetEntity", "service-instance");
64         jsonObject.addProperty("sliceanalysisms.aaiNotif.targetSource", "UUI");
65         jsonObject.addProperty("postgres.port", "1");
66         jsonObject.addProperty("sliceanalysisms.pollingInterval", "1");
67         jsonObject.addProperty("postgres.password", "1");
68         jsonObject.addProperty("postgres.username", "1");
69         jsonObject.addProperty("postgres.host", "1");
70         jsonObject.addProperty("sliceanalysisms.cg", "1");
71         jsonObject.addProperty("sliceanalysisms.cid", "1");
72         jsonObject.addProperty("sliceanalysisms.configDb.service", "1");
73         jsonObject.addProperty("sliceanalysisms.configDbEnabled", "1");
74         jsonObject.addProperty("sliceanalysisms.pollingTimeout", "1");
75         jsonObject.addProperty("sliceanalysisms.samples", "1");
76         jsonObject.addProperty("sliceanalysisms.minPercentageChange", "1");
77         jsonObject.addProperty("sliceanalysisms.initialDelaySeconds", "1");
78         jsonObject.addProperty("sliceanalysisms.rannfnssiDetailsTemplateId", "1");
79         jsonObject.addProperty("sliceanalysisms.desUrl", "1");
80         jsonObject.addProperty("sliceanalysisms.pmDataDurationInWeeks", "1");
81         jsonObject.addProperty("sliceanalysisms.pollingInterval", "1");
82         jsonObject.addProperty("sliceanalysisms.vesNotifChangeIdentifier", "1");
83         jsonObject.addProperty("sliceanalysisms.vesNotifChangeType", "1");
84         jsonObject.addProperty("sliceanalysisms.vesNotifPollingInterval", "1");
85         jsonObject.addProperty("sliceanalysisms.ccvpnEvalInterval", "1");
86         jsonObject.addProperty("sliceanalysisms.ccvpnEvalThreshold", "1");
87         jsonObject.addProperty("sliceanalysisms.ccvpnEvalPrecision", "1");
88         jsonObject.addProperty("sliceanalysisms.ccvpnEvalPeriodicCheckOn", "1");
89         jsonObject.addProperty("sliceanalysisms.ccvpnEvalOnDemandCheckOn", "1");
90         jsonObject.addProperty("sliceanalysisms.ccvpnEvalStrategy", "1");
91         Configuration configuration = Configuration.getInstance();
92         configuration.updateConfigurationFromJsonObject(jsonObject);
93         doNothing().when(bandwidthEvaluator).post(any());
94     }
95
96     @Test
97     public void initTest() {
98         aaiEventNotificationCallback.init();
99         Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).init();
100     }
101
102     @Test
103     public void activateCallBackTest() throws IOException {
104         aaiEventNotificationCallback.init();
105         String input = new String(Files.readAllBytes(Paths.get("src/test/resources/aaiEventDmaapMsg.json")));
106         aaiEventNotificationCallback.activateCallBack(input);
107         Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).activateCallBack(Mockito.anyString());
108     }
109     @Test
110     public void activateCallBackArrayTest() throws IOException {
111         aaiEventNotificationCallback.init();
112         String input = new String(Files.readAllBytes(Paths.get("src/test/resources/aaiEventDmaapMsg.json")));
113         JsonArray jsonArray = new JsonArray();
114
115         JsonPrimitive jsonPrimitive = new JsonPrimitive(input);
116         jsonArray.add(jsonPrimitive);
117         aaiEventNotificationCallback.activateCallBack(jsonArray.toString());
118         Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).activateCallBack(Mockito.anyString());
119     }
120 }