6e0d1243e19bd567db301d5bb0d308df2d70a18f
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
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
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 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;
30 import java.util.Map;
31
32 import static org.junit.Assert.assertEquals;
33 import static org.mockito.Mockito.*;
34
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;
46
47 import com.fasterxml.jackson.core.type.TypeReference;
48 import com.fasterxml.jackson.databind.ObjectMapper;
49
50 @RunWith(SpringRunner.class)
51 @SpringBootTest(classes = MLMessageProcessorTest.class)
52 public class MLMessageProcessorTest {
53         ObjectMapper obj = new ObjectMapper();
54         
55         @InjectMocks
56         private MLMessageProcessor mlMessageProcessor;
57         
58         @Mock
59         private IConfigDbService configDbService;
60
61         @Mock
62         AaiService aaiService;
63
64         @Mock
65         CpsService  cpsService;
66
67         @Mock
68         private PolicyService policyService;
69         
70         @SuppressWarnings({"unchecked" })
71         @Test
72         public void processMLMsgTest() {
73                 MLOutputModel mloutput = null;
74                 MLOutputModel mloutputExp = null;
75
76                 Map<String, List<String>> ricToCellMapping = new HashMap<>();
77                 List<String> myList = new ArrayList<String>();
78                 myList.add("111");
79                 myList.add("112");
80                 ricToCellMapping.put("12", myList);
81                 myList = new ArrayList<String>();
82                 myList.add("113");
83                 myList.add("114");
84                 ricToCellMapping.put("13", myList);
85
86                 try {
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>(){});
89                 }
90                 catch (IOException e) { 
91              e.printStackTrace(); 
92         } 
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);
99         }
100         
101 }