d9bf76171140767cbe9dafc804041466700f4547
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
4  *  ================================================================================
5  *   Copyright (C) 2020 Wipro Limited.
6  *   Copyright (C) 2022 Huawei Canada Limited.
7  *   ==============================================================================
8  *     Licensed under the Apache License, Version 2.0 (the "License");
9  *     you may not use this file except in compliance with the License.
10  *     You may obtain a copy of the License at
11  *
12  *          http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *     Unless required by applicable law or agreed to in writing, software
15  *     distributed under the License is distributed on an "AS IS" BASIS,
16  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *     See the License for the specific language governing permissions and
18  *     limitations under the License.
19  *     ============LICENSE_END=========================================================
20  *
21  *******************************************************************************/
22
23 package org.onap.slice.analysis.ms.service;
24
25 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
26
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import java.util.HashMap;
31 import java.util.Map;
32
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.InjectMocks;
36 import org.onap.slice.analysis.ms.models.policy.AdditionalProperties;
37 import org.onap.slice.analysis.ms.models.policy.OnsetMessage;
38 import org.onap.slice.analysis.ms.service.ccvpn.RequestOwner;
39 import org.springframework.boot.test.context.SpringBootTest;
40 import org.springframework.test.context.junit4.SpringRunner;
41
42 import com.fasterxml.jackson.core.type.TypeReference;
43 import com.fasterxml.jackson.databind.ObjectMapper;
44 import com.google.gson.Gson;
45
46 @RunWith(SpringRunner.class)
47 @SpringBootTest(classes = PolicyServiceTest.class)
48 public class PolicyServiceTest {
49     ObjectMapper obj = new ObjectMapper();
50
51     @InjectMocks
52     PolicyService policyService;
53
54     @Test
55     public void formPolicyOnsetMessageTest() {
56         String snssai = "001-100001";
57         Map<String, String> input = null;
58         OnsetMessage output = null;
59         String expected = "";
60         String actual = "";
61         Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>();
62         Map<String, Integer> ric1 = new HashMap<>();
63         Map<String, Integer> ric2 = new HashMap<>();
64         ric1.put("dLThptPerSlice",50);
65         ric1.put("uLThptPerSlice",40);
66         ric2.put("dLThptPerSlice",50);
67         ric2.put("uLThptPerSlice",30);
68         ricToThroughputMapping.put("1", ric1);
69         ricToThroughputMapping.put("2", ric2);
70         try {
71             input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/serviceDetails.json"))), new TypeReference<Map<String,String>>(){});
72             output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/onsetMessage.json"))), OnsetMessage.class);
73             expected = obj.writeValueAsString(output);
74         }
75         catch (IOException e) {
76             e.printStackTrace();
77         }
78         AdditionalProperties<Map<String, Map<String, Integer>>> addProps = new AdditionalProperties<>();
79         addProps.setResourceConfig(ricToThroughputMapping);
80         actual = new Gson().toJson(policyService.formPolicyOnsetMessage(snssai,addProps,input));
81
82         assertThatJson(actual)
83                 .whenIgnoringPaths("requestID","payload","closedLoopAlarmStart", "AAI", "target_type", "aai", "targetType")
84                 .isEqualTo(expected);
85     }
86
87     @Test
88     public void formPolicyOnsetMessageForCCVPNTest() {
89         String cllId = "cll-instance-01";
90         OnsetMessage output = null;
91         String expected = "";
92         String actual = "";
93         try {
94             output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/onsetMessage2.json"))), OnsetMessage.class);
95             expected = obj.writeValueAsString(output);
96
97             String msg = obj.writeValueAsString(policyService
98                     .formPolicyOnsetMessageForCCVPN(cllId, 3000, RequestOwner.UUI));
99             actual = new Gson().toJson(msg);
100         }
101         catch (IOException e) {
102             e.printStackTrace();
103         }
104         assertThatJson(actual)
105                 .whenIgnoringPaths("requestID","payload","closedLoopAlarmStart", "AAI", "target_type", "aai", "targetType")
106                 .isEqualTo(expected);
107     }
108 }