1 /*******************************************************************************
 
   2  *  ============LICENSE_START=======================================================
 
   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
 
  12  *          http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  21  *******************************************************************************/
 
  23 package org.onap.slice.analysis.ms.dmaap;
 
  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;
 
  40 import java.io.IOException;
 
  41 import java.nio.file.Files;
 
  42 import java.nio.file.Paths;
 
  44 import static org.mockito.ArgumentMatchers.any;
 
  45 import static org.powermock.api.mockito.PowerMockito.doNothing;
 
  48 @RunWith(SpringRunner.class)
 
  49 @SpringBootTest(classes = VesNotificationCallbackTest.class)
 
  50 public class AaiEventNotificationCallbackTest {
 
  54     AaiEventNotificationCallback aaiEventNotificationCallback;
 
  57     BandwidthEvaluator bandwidthEvaluator;
 
  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         Configuration configuration = Configuration.getInstance();
 
  91         configuration.updateConfigurationFromJsonObject(jsonObject);
 
  92         doNothing().when(bandwidthEvaluator).post(any());
 
  96     public void initTest() {
 
  97         aaiEventNotificationCallback.init();
 
  98         Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).init();
 
 102     public void activateCallBackTest() throws IOException {
 
 103         aaiEventNotificationCallback.init();
 
 104         String input = new String(Files.readAllBytes(Paths.get("src/test/resources/aaiEventDmaapMsg.json")));
 
 105         aaiEventNotificationCallback.activateCallBack(input);
 
 106         Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).activateCallBack(Mockito.anyString());
 
 109     public void activateCallBackArrayTest() throws IOException {
 
 110         aaiEventNotificationCallback.init();
 
 111         String input = new String(Files.readAllBytes(Paths.get("src/test/resources/aaiEventDmaapMsg.json")));
 
 112         JsonArray jsonArray = new JsonArray();
 
 114         JsonPrimitive jsonPrimitive = new JsonPrimitive(input);
 
 115         jsonArray.add(jsonPrimitive);
 
 116         aaiEventNotificationCallback.activateCallBack(jsonArray.toString());
 
 117         Mockito.verify(aaiEventNotificationCallback, Mockito.atLeastOnce()).activateCallBack(Mockito.anyString());