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 static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import java.util.HashMap;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.onap.slice.analysis.ms.models.policy.AdditionalProperties;
36 import org.onap.slice.analysis.ms.models.policy.OnsetMessage;
37 import org.springframework.boot.test.context.SpringBootTest;
38 import org.springframework.test.context.junit4.SpringRunner;
40 import com.fasterxml.jackson.core.type.TypeReference;
41 import com.fasterxml.jackson.databind.ObjectMapper;
42 import com.google.gson.Gson;
44 @RunWith(SpringRunner.class)
45 @SpringBootTest(classes = PolicyServiceTest.class)
46 public class PolicyServiceTest {
47 ObjectMapper obj = new ObjectMapper();
50 PolicyService policyService;
53 public void formPolicyOnsetMessageTest() {
54 String snssai = "001-100001";
55 Map<String, String> input = null;
56 OnsetMessage output = null;
59 Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>();
60 Map<String, Integer> ric1 = new HashMap<>();
61 Map<String, Integer> ric2 = new HashMap<>();
62 ric1.put("dLThptPerSlice",50);
63 ric1.put("uLThptPerSlice",40);
64 ric2.put("dLThptPerSlice",50);
65 ric2.put("uLThptPerSlice",30);
66 ricToThroughputMapping.put("1", ric1);
67 ricToThroughputMapping.put("2", ric2);
69 input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/serviceDetails.json"))), new TypeReference<Map<String,String>>(){});
70 output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/onsetMessage.json"))), OnsetMessage.class);
71 expected = obj.writeValueAsString(output);
73 catch (IOException e) {
76 AdditionalProperties<Map<String, Map<String, Integer>>> addProps = new AdditionalProperties<>();
77 addProps.setResourceConfig(ricToThroughputMapping);
78 actual = new Gson().toJson(policyService.formPolicyOnsetMessage(snssai,addProps,input));
80 assertThatJson(actual)
81 .whenIgnoringPaths("requestID","payload","closedLoopAlarmStart", "AAI", "target_type", "aai", "targetType")