1 /*******************************************************************************
 
   2  *  ============LICENSE_START=======================================================
 
   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
 
  12  *          http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  21  *******************************************************************************/
 
  23 package org.onap.slice.analysis.ms.service;
 
  25 import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
 
  27 import java.io.IOException;
 
  28 import java.nio.file.Files;
 
  29 import java.nio.file.Paths;
 
  30 import java.util.HashMap;
 
  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;
 
  42 import com.fasterxml.jackson.core.type.TypeReference;
 
  43 import com.fasterxml.jackson.databind.ObjectMapper;
 
  44 import com.google.gson.Gson;
 
  46 @RunWith(SpringRunner.class)
 
  47 @SpringBootTest(classes = PolicyServiceTest.class)
 
  48 public class PolicyServiceTest {
 
  49     ObjectMapper obj = new ObjectMapper();
 
  52     PolicyService policyService;
 
  55     public void formPolicyOnsetMessageTest() {
 
  56         String snssai = "001-100001";
 
  57         Map<String, String> input = null;
 
  58         OnsetMessage output = null;
 
  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);
 
  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);
 
  75         catch (IOException e) {
 
  78         AdditionalProperties<Map<String, Map<String, Integer>>> addProps = new AdditionalProperties<>();
 
  79         addProps.setResourceConfig(ricToThroughputMapping);
 
  80         actual = new Gson().toJson(policyService.formPolicyOnsetMessage(snssai,addProps,input));
 
  82         assertThatJson(actual)
 
  83                 .whenIgnoringPaths("requestID","payload","closedLoopAlarmStart", "AAI", "target_type", "aai", "targetType")
 
  88     public void formPolicyOnsetMessageForCCVPNTest() {
 
  89         String cllId = "cll-instance-01";
 
  90         OnsetMessage output = null;
 
  94             output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/onsetMessage2.json"))), OnsetMessage.class);
 
  95             expected = obj.writeValueAsString(output);
 
  97             String msg = obj.writeValueAsString(policyService
 
  98                     .formPolicyOnsetMessageForCCVPN(cllId, 3000, RequestOwner.UUI));
 
  99             actual = new Gson().toJson(msg);
 
 101         catch (IOException e) {
 
 104         assertThatJson(actual)
 
 105                 .whenIgnoringPaths("requestID","payload","closedLoopAlarmStart", "AAI", "target_type", "aai", "targetType")
 
 106                 .isEqualTo(expected);