1 /*******************************************************************************
 
   2  *  ============LICENSE_START=======================================================
 
   4  *  ================================================================================
 
   5  *   Copyright (C) 2020 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 java.io.IOException;
 
  25 import java.nio.file.Files;
 
  26 import java.nio.file.Paths;
 
  27 import java.util.ArrayList;
 
  28 import java.util.HashMap;
 
  29 import java.util.List;
 
  32 import static org.junit.Assert.assertEquals;
 
  33 import static org.mockito.Mockito.*;
 
  35 import org.junit.Test;
 
  36 import org.junit.runner.RunWith;
 
  37 import org.mockito.InjectMocks;
 
  38 import org.mockito.Mock;
 
  39 import org.onap.slice.analysis.ms.configdb.IConfigDbService;
 
  40 import org.onap.slice.analysis.ms.models.MLOutputModel;
 
  41 import org.onap.slice.analysis.ms.models.policy.AdditionalProperties;
 
  42 import org.springframework.boot.test.context.SpringBootTest;
 
  43 import org.springframework.test.context.junit4.SpringRunner;
 
  45 import com.fasterxml.jackson.core.type.TypeReference;
 
  46 import com.fasterxml.jackson.databind.ObjectMapper;
 
  48 @RunWith(SpringRunner.class)
 
  49 @SpringBootTest(classes = MLMessageProcessorTest.class)
 
  50 public class MLMessageProcessorTest {
 
  51         ObjectMapper obj = new ObjectMapper();
 
  54         private MLMessageProcessor mlMessageProcessor;
 
  57         private IConfigDbService configDbService;
 
  60         private PolicyService policyService;
 
  62         @SuppressWarnings({"unchecked" })
 
  64         public void processMLMsgTest() {
 
  65                 MLOutputModel mloutput = null;
 
  66                 MLOutputModel mloutputExp = null;
 
  68                 Map<String, List<String>> ricToCellMapping = new HashMap<>();
 
  69                 List<String> myList = new ArrayList<String>();
 
  72                 ricToCellMapping.put("12", myList);
 
  73                 myList = new ArrayList<String>();
 
  76                 ricToCellMapping.put("13", myList);
 
  79                         mloutput = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel1.json"))), new TypeReference<MLOutputModel>(){});
 
  80                         mloutputExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel.json"))), new TypeReference<MLOutputModel>(){});
 
  82                 catch (IOException e) { 
 
  85                 when(configDbService.fetchRICsOfSnssai("0001-0111")).thenReturn(ricToCellMapping);
 
  86                 AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>();
 
  87                 addProps.setResourceConfig(mloutputExp);
 
  88                 doNothing().when(policyService).sendOnsetMessageToPolicy(anyString(), any(AdditionalProperties.class), anyMap());
 
  89                 mlMessageProcessor.processMLMsg(mloutput);
 
  90                 assertEquals(mloutputExp, mloutput);