1 /*******************************************************************************
 
   2  *  ============LICENSE_START=======================================================
 
   4  *  ================================================================================
 
   5  *   Copyright (C) 2020-2022 Wipro Limited.
 
   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
 
  11  *          http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  20  *******************************************************************************/
 
  22 package org.onap.slice.analysis.ms.service;
 
  24 import static org.junit.Assert.assertEquals;
 
  25 import static org.mockito.Mockito.doNothing;
 
  26 import static org.mockito.Mockito.when;
 
  27 import static org.mockito.Mockito.any;
 
  28 import static org.mockito.Mockito.anyString;
 
  29 import static org.mockito.Mockito.anyMap;
 
  31 import com.fasterxml.jackson.core.type.TypeReference;
 
  32 import com.fasterxml.jackson.databind.ObjectMapper;
 
  34 import java.io.IOException;
 
  35 import java.nio.file.Files;
 
  36 import java.nio.file.Paths;
 
  37 import java.util.ArrayList;
 
  38 import java.util.HashMap;
 
  39 import java.util.List;
 
  42 import org.junit.Test;
 
  43 import org.junit.runner.RunWith;
 
  44 import org.mockito.InjectMocks;
 
  45 import org.mockito.Mock;
 
  46 import org.onap.slice.analysis.ms.aai.AaiService;
 
  47 import org.onap.slice.analysis.ms.configdb.IConfigDbService;
 
  48 import org.onap.slice.analysis.ms.cps.CpsService;
 
  49 import org.onap.slice.analysis.ms.models.MLOutputModel;
 
  50 import org.onap.slice.analysis.ms.models.policy.AdditionalProperties;
 
  51 import org.springframework.boot.test.context.SpringBootTest;
 
  52 import org.springframework.test.context.junit4.SpringRunner;
 
  54 @RunWith(SpringRunner.class)
 
  55 @SpringBootTest(classes = MLMessageProcessorTest.class)
 
  56 public class MLMessageProcessorTest {
 
  57     ObjectMapper obj = new ObjectMapper();
 
  60     private MLMessageProcessor mlMessageProcessor;
 
  63     private IConfigDbService configDbService;
 
  66     AaiService aaiService;
 
  69     CpsService cpsService;
 
  72     private PolicyService policyService;
 
  74     @SuppressWarnings({"unchecked"})
 
  76     public void processMLMsgTest() {
 
  77         MLOutputModel mloutput = null;
 
  78         MLOutputModel mloutputExp = null;
 
  80         Map<String, List<String>> ricToCellMapping = new HashMap<>();
 
  81         List<String> myList = new ArrayList<String>();
 
  84         ricToCellMapping.put("12", myList);
 
  85         myList = new ArrayList<String>();
 
  88         ricToCellMapping.put("13", myList);
 
  92                     obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel1.json"))),
 
  93                             new TypeReference<MLOutputModel>() {});
 
  95                     obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel.json"))),
 
  96                             new TypeReference<MLOutputModel>() {});
 
  97         } catch (IOException e) {
 
 100         when(configDbService.fetchRICsOfSnssai("0001-0111")).thenReturn(ricToCellMapping);
 
 101         AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>();
 
 102         addProps.setResourceConfig(mloutputExp);
 
 103         doNothing().when(policyService).sendOnsetMessageToPolicy(anyString(), any(AdditionalProperties.class),
 
 105         mlMessageProcessor.processMLMsg(mloutput);
 
 106         assertEquals(mloutputExp, mloutput);