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.configdb.AaiService;
41 import org.onap.slice.analysis.ms.configdb.CpsService;
42 import org.onap.slice.analysis.ms.models.MLOutputModel;
43 import org.onap.slice.analysis.ms.models.policy.AdditionalProperties;
44 import org.springframework.boot.test.context.SpringBootTest;
45 import org.springframework.test.context.junit4.SpringRunner;
47 import com.fasterxml.jackson.core.type.TypeReference;
48 import com.fasterxml.jackson.databind.ObjectMapper;
50 @RunWith(SpringRunner.class)
51 @SpringBootTest(classes = MLMessageProcessorTest.class)
52 public class MLMessageProcessorTest {
53 ObjectMapper obj = new ObjectMapper();
56 private MLMessageProcessor mlMessageProcessor;
59 private IConfigDbService configDbService;
62 AaiService aaiService;
65 CpsService cpsService;
68 private PolicyService policyService;
70 @SuppressWarnings({"unchecked" })
72 public void processMLMsgTest() {
73 MLOutputModel mloutput = null;
74 MLOutputModel mloutputExp = null;
76 Map<String, List<String>> ricToCellMapping = new HashMap<>();
77 List<String> myList = new ArrayList<String>();
80 ricToCellMapping.put("12", myList);
81 myList = new ArrayList<String>();
84 ricToCellMapping.put("13", myList);
87 mloutput = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel1.json"))), new TypeReference<MLOutputModel>(){});
88 mloutputExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel.json"))), new TypeReference<MLOutputModel>(){});
90 catch (IOException e) {
93 when(configDbService.fetchRICsOfSnssai("0001-0111")).thenReturn(ricToCellMapping);
94 AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>();
95 addProps.setResourceConfig(mloutputExp);
96 doNothing().when(policyService).sendOnsetMessageToPolicy(anyString(), any(AdditionalProperties.class), anyMap());
97 mlMessageProcessor.processMLMsg(mloutput);
98 assertEquals(mloutputExp, mloutput);