2 * Copyright (C) 2019 CMCC, Inc. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.usecaseui.server.service.nsmf.impl;
18 import static org.mockito.Mockito.mock;
19 import static org.mockito.Mockito.when;
20 import static org.onap.usecaseui.server.util.CallStub.failedCall;
21 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
23 import com.alibaba.fastjson.JSONObject;
24 import java.util.ArrayList;
25 import java.util.List;
26 import okhttp3.RequestBody;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceInfo;
30 import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceList;
31 import org.onap.usecaseui.server.constant.nsmf.NsmfParamConstant;
32 import org.onap.usecaseui.server.service.slicingdomain.aai.AAISliceService;
33 import org.onap.usecaseui.server.service.slicingdomain.kpi.KpiSliceService;
34 import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiTotalBandwidth;
35 import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiTotalTraffic;
36 import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiUserNumber;
38 public class ResourceMonitorServiceImplTest {
40 ResourceMonitorServiceImpl resourceMonitorService = null;
41 KpiSliceService kpiSliceService = null;
44 public void before() throws Exception {
45 kpiSliceService = mock(KpiSliceService.class);
46 resourceMonitorService = new ResourceMonitorServiceImpl(kpiSliceService);
50 public void itCanInitConfig() {
51 resourceMonitorService.initConfig();
55 public void itCanQuerySlicingUsageTraffic() {
56 ServiceList serviceList = new ServiceList();
57 List<ServiceInfo> serviceInfoList = new ArrayList<>();
58 ServiceInfo serviceInfo = new ServiceInfo();
59 serviceInfo.setServiceId("123e-456t-567t-yui8");
60 serviceInfoList.add(serviceInfo);
61 serviceList.setServiceInfoList(serviceInfoList);
62 String queryTimestamp = "1577071879000";
64 KpiTotalTraffic kpiTotalTraffic = new KpiTotalTraffic();
65 RequestBody body = null;
66 when(kpiSliceService.listTotalTraffic(body)).thenReturn(successfulCall(kpiTotalTraffic));
67 resourceMonitorService.querySlicingUsageTraffic(queryTimestamp, serviceList);
71 public void querySlicingUsageTrafficWithThrowsException() {
72 ServiceList serviceList = new ServiceList();
73 List<ServiceInfo> serviceInfoList = new ArrayList<>();
74 ServiceInfo serviceInfo = new ServiceInfo();
75 serviceInfo.setServiceId("123e-456t-567t-yui8");
76 serviceInfoList.add(serviceInfo);
77 serviceList.setServiceInfoList(serviceInfoList);
78 String queryTimestamp = "1577071879000";
80 RequestBody body = null;
81 when(kpiSliceService.listTotalTraffic(body)).thenReturn(failedCall("kpi is not exist!"));
82 resourceMonitorService.querySlicingUsageTraffic(queryTimestamp, serviceList);
86 public void itCanQuerySlicingOnlineUserNumber() {
87 ServiceList serviceList = new ServiceList();
88 List<ServiceInfo> serviceInfoList = new ArrayList<>();
89 ServiceInfo serviceInfo = new ServiceInfo();
90 serviceInfo.setServiceId("123e-456t-567t-yui8");
91 serviceInfoList.add(serviceInfo);
92 serviceList.setServiceInfoList(serviceInfoList);
93 String queryTimestamp = "1577071879000";
95 KpiUserNumber kpiUserNumber = new KpiUserNumber();
96 RequestBody body = null;
97 when(kpiSliceService.listUserNumber(body)).thenReturn(successfulCall(kpiUserNumber));
98 resourceMonitorService.querySlicingOnlineUserNumber(queryTimestamp, serviceList);
102 public void querySlicingOnlineUserNumberWithThrowsException() {
103 ServiceList serviceList = new ServiceList();
104 List<ServiceInfo> serviceInfoList = new ArrayList<>();
105 ServiceInfo serviceInfo = new ServiceInfo();
106 serviceInfo.setServiceId("123e-456t-567t-yui8");
107 serviceInfoList.add(serviceInfo);
108 serviceList.setServiceInfoList(serviceInfoList);
109 String queryTimestamp = "1577071879000";
111 RequestBody body = null;
112 when(kpiSliceService.listUserNumber(body)).thenReturn(failedCall("kpi is not exist!"));
113 resourceMonitorService.querySlicingOnlineUserNumber(queryTimestamp, serviceList);
117 public void itCanQuerySlicingTotalBandwidth() {
118 ServiceList serviceList = new ServiceList();
119 List<ServiceInfo> serviceInfoList = new ArrayList<>();
120 ServiceInfo serviceInfo = new ServiceInfo();
121 serviceInfo.setServiceId("123e-456t-567t-yui8");
122 serviceInfoList.add(serviceInfo);
123 serviceList.setServiceInfoList(serviceInfoList);
124 String queryTimestamp = "1577071879000";
126 KpiTotalBandwidth kpiTotalBandwidth = new KpiTotalBandwidth();
127 RequestBody body = null;
128 when(kpiSliceService.listTotalBandwidth(body)).thenReturn(successfulCall(kpiTotalBandwidth));
129 resourceMonitorService.querySlicingTotalBandwidth(queryTimestamp, serviceList);
133 public void querySlicingTotalBandwidthWithThrowsException() {
134 ServiceList serviceList = new ServiceList();
135 List<ServiceInfo> serviceInfoList = new ArrayList<>();
136 ServiceInfo serviceInfo = new ServiceInfo();
137 serviceInfo.setServiceId("123e-456t-567t-yui8");
138 serviceInfoList.add(serviceInfo);
139 serviceList.setServiceInfoList(serviceInfoList);
140 String queryTimestamp = "1577071879000";
142 RequestBody body = null;
143 when(kpiSliceService.listTotalBandwidth(body)).thenReturn(failedCall("kpi is not exist!"));
144 resourceMonitorService.querySlicingTotalBandwidth(queryTimestamp, serviceList);
148 public void querySlicingPDUSessionEstSRWithThrowsException() {
149 ServiceList serviceList = new ServiceList();
150 List<ServiceInfo> serviceInfoList = new ArrayList<>();
151 ServiceInfo serviceInfo = new ServiceInfo();
152 serviceInfo.setServiceId("123e-456t-567t-yui8");
153 serviceInfoList.add(serviceInfo);
154 serviceList.setServiceInfoList(serviceInfoList);
155 String queryTimestamp = "1577071879000";
157 RequestBody body = null;
158 when(kpiSliceService.listPDUSessionEstSR(body)).thenReturn(failedCall("kpi is not exist!"));
159 resourceMonitorService.querySlicingPDUSessionEstSR(queryTimestamp, serviceList);