708ba7e44e5dcba5d39545e374afffc90f2fe069
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  *******************************************************************************/
21
22 package org.onap.slice.analysis.ms.service;
23
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;
30
31 import com.fasterxml.jackson.core.type.TypeReference;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33
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;
40 import java.util.Map;
41
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;
53
54 @RunWith(SpringRunner.class)
55 @SpringBootTest(classes = MLMessageProcessorTest.class)
56 public class MLMessageProcessorTest {
57     ObjectMapper obj = new ObjectMapper();
58
59     @InjectMocks
60     private MLMessageProcessor mlMessageProcessor;
61
62     @Mock
63     private IConfigDbService configDbService;
64
65     @Mock
66     AaiService aaiService;
67
68     @Mock
69     CpsService cpsService;
70
71     @Mock
72     private PolicyService policyService;
73
74     @SuppressWarnings({"unchecked"})
75     @Test
76     public void processMLMsgTest() {
77         MLOutputModel mloutput = null;
78         MLOutputModel mloutputExp = null;
79
80         Map<String, List<String>> ricToCellMapping = new HashMap<>();
81         List<String> myList = new ArrayList<String>();
82         myList.add("111");
83         myList.add("112");
84         ricToCellMapping.put("12", myList);
85         myList = new ArrayList<String>();
86         myList.add("113");
87         myList.add("114");
88         ricToCellMapping.put("13", myList);
89
90         try {
91             mloutput =
92                     obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel1.json"))),
93                             new TypeReference<MLOutputModel>() {});
94             mloutputExp =
95                     obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel.json"))),
96                             new TypeReference<MLOutputModel>() {});
97         } catch (IOException e) {
98             e.printStackTrace();
99         }
100         when(configDbService.fetchCUCPCellsOfSnssai("0001-0111")).thenReturn(ricToCellMapping);
101         AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>();
102         addProps.setResourceConfig(mloutputExp);
103         doNothing().when(policyService).sendOnsetMessageToPolicy(anyString(), any(AdditionalProperties.class),
104                 anyMap());
105         mlMessageProcessor.processMLMsg(mloutput);
106         assertEquals(mloutputExp, mloutput);
107     }
108
109 }