d80160c9f7e504d2649f816f00c519dde5255b3f
[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.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;
44
45 import com.fasterxml.jackson.core.type.TypeReference;
46 import com.fasterxml.jackson.databind.ObjectMapper;
47
48 @RunWith(SpringRunner.class)
49 @SpringBootTest(classes = MLMessageProcessorTest.class)
50 public class MLMessageProcessorTest {
51         ObjectMapper obj = new ObjectMapper();
52         
53         @InjectMocks
54         private MLMessageProcessor mlMessageProcessor;
55         
56         @Mock
57         private IConfigDbService configDbService;
58         
59         @Mock
60         private PolicyService policyService;
61         
62         @SuppressWarnings({"unchecked" })
63         @Test
64         public void processMLMsgTest() {
65                 MLOutputModel mloutput = null;
66                 MLOutputModel mloutputExp = null;
67
68                 Map<String, List<String>> ricToCellMapping = new HashMap<>();
69                 List<String> myList = new ArrayList<String>();
70                 myList.add("111");
71                 myList.add("112");
72                 ricToCellMapping.put("12", myList);
73                 myList = new ArrayList<String>();
74                 myList.add("113");
75                 myList.add("114");
76                 ricToCellMapping.put("13", myList);
77
78                 try {
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>(){});
81                 }
82                 catch (IOException e) { 
83              e.printStackTrace(); 
84         } 
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);
91         }
92         
93 }