summaryrefslogtreecommitdiffstats
path: root/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java
blob: 3b0c32fa061659dec22cd215731cf075faa270a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*******************************************************************************
 *  ============LICENSE_START=======================================================
 *  slice-analysis-ms
 *  ================================================================================
 *  Copyright (C) 2022 Huawei Canada Limited.
 *  Copyright (C) 2022 CTC, Inc.
 *  ==============================================================================
 *     Licensed under the Apache License, Version 2.0 (the "License");
 *     you may not use this file except in compliance with the License.
 *     You may obtain a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS,
 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *     See the License for the specific language governing permissions and
 *     limitations under the License.
 *     ============LICENSE_END=========================================================
 *
 *******************************************************************************/

package org.onap.slice.analysis.ms.dmaap;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.onap.slice.analysis.ms.models.Configuration;
import org.onap.slice.analysis.ms.service.ccvpn.BandwidthEvaluator;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import static org.mockito.ArgumentMatchers.any;
import static org.powermock.api.mockito.PowerMockito.doNothing;


@RunWith(SpringRunner.class)
@SpringBootTest(classes = VesNotificationCallbackTest.class)
public class AaiEventNotificationCallbackTest {

    @Spy
    @InjectMocks
    AaiEventNotificationCallback aaiEventNotificationCallback;

    @Mock
    BandwidthEvaluator bandwidthEvaluator;

    @Before
    public void initConfiguration() {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("sliceanalysisms.aaiNotif.targetAction", "UPDATE");
        jsonObject.addProperty("sliceanalysisms.aaiNotif.targetEntity", "service-instance");
        jsonObject.addProperty("sliceanalysisms.aaiNotif.targetSource", "UUI");
        jsonObject.addProperty("postgres.port", "1");
        jsonObject.addProperty("sliceanalysisms.pollingInterval", "1");
        jsonObject.addProperty("postgres.password", "1");
        jsonObject.addProperty("postgres.username", "1");
        jsonObject.addProperty("postgres.host", "1");
        jsonObject.addProperty("sliceanalysisms.cg", "1");
        jsonObject.addProperty("sliceanalysisms.cid", "1");
        jsonObject.addProperty("sliceanalysisms.configDb.service", "1");
        jsonObject.addProperty("sliceanalysisms.configDbEnabled", "1");
        jsonObject.addProperty("sliceanalysisms.pollingTimeout", "1");
        jsonObject.addProperty("sliceanalysisms.samples", "1");
        jsonObject.addProperty("sliceanalysisms.minPercentageChange", "1");
        jsonObject.addProperty("sliceanalysisms.initialDelaySeconds", "1");
        jsonObject.addProperty("sliceanalysisms.rannfnssiDetailsTemplateId", "1");
        jsonObject.addProperty("sliceanalysisms.desUrl", "1");
        jsonObject.addProperty("sliceanalysisms.pmDataDurationInWeeks", "1");
        jsonObject.addProperty("sliceanalysisms.pollingInterval", "1");
        jsonObject.addProperty("sliceanalysisms.vesNotifChangeIdentifier", "1");
        jsonObject.addProperty("sliceanalysisms.vesNotifChangeType", "1");
        jsonObject.addProperty("sliceanalysisms.vesNotifPollingInterval", "1");
        jsonObject.addProperty("sliceanalysisms.ccvpnEvalInterval", "1");
        jsonObject.addProperty("sliceanalysisms.ccvpnEvalThreshold", "1");
        jsonObject.addProperty("sliceanalysisms.ccvpnEvalPrecision", "1");
        jsonObject.addProperty("sliceanalysisms.ccvpnEvalPeriodicCheckOn", "1");
        jsonObject.addProperty("sliceanalysisms.ccvpnEvalOnDemandCheckOn", "1");
        Configuration configuration = Configuration.getInstance();
        configuration.updateConfigurationFromJsonObject(jsonObject);
        doNothing().when(bandwidthEvaluator).post(any());
    }

    @Test
    public void initTest() {
        aaiEventNotificationCallback.init();
        Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).init();
    }

    @Test
    public void activateCallBackTest() throws IOException {
        aaiEventNotificationCallback.init();
        String input = new String(Files.readAllBytes(Paths.get("src/test/resources/aaiEventDmaapMsg.json")));
        aaiEventNotificationCallback.activateCallBack(input);
        Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).activateCallBack(Mockito.anyString());
    }
    @Test
    public void activateCallBackArrayTest() throws IOException {
        aaiEventNotificationCallback.init();
        String input = new String(Files.readAllBytes(Paths.get("src/test/resources/aaiEventDmaapMsg.json")));
        JsonArray jsonArray = new JsonArray();

        JsonPrimitive jsonPrimitive = new JsonPrimitive(input);
        jsonArray.add(jsonPrimitive);
        aaiEventNotificationCallback.activateCallBack(jsonArray.toString());
        Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).activateCallBack(Mockito.anyString());
    }
}