aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test/java/org/onap/usecaseui/server/service/csmf/impl/SlicingServiceImplTest.java
blob: 35928f7c9f3e97223f6ffa0e89d6cf25c0f852b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * Copyright (C) 2020 CMCC, Inc. and others. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onap.usecaseui.server.service.csmf.impl;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall;
import static org.onap.usecaseui.server.util.CallStub.failedCall;
import static org.onap.usecaseui.server.util.CallStub.successfulCall;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.RequestBody;
import org.junit.Before;
import org.junit.Test;
import org.onap.usecaseui.server.bean.csmf.CreateResponse;
import org.onap.usecaseui.server.bean.csmf.OrderInfo;
import org.onap.usecaseui.server.bean.csmf.OrderList;
import org.onap.usecaseui.server.bean.csmf.SlicingOrder;
import org.onap.usecaseui.server.bean.csmf.SlicingOrderDetail;
import org.onap.usecaseui.server.constant.nsmf.NsmfParamConstant;
import org.onap.usecaseui.server.service.nsmf.impl.ResourceMgtServiceImpl;
import org.onap.usecaseui.server.service.slicingdomain.aai.AAISliceService;
import org.onap.usecaseui.server.service.slicingdomain.so.SOSliceService;
import org.onap.usecaseui.server.service.slicingdomain.so.bean.ActivateService;
import org.onap.usecaseui.server.service.slicingdomain.so.bean.SOOperation;
import org.onap.usecaseui.server.util.nsmf.NsmfCommonUtil;
import retrofit2.Call;

public class SlicingServiceImplTest {

    SlicingServiceImpl slicingService = null;
    SOSliceService soSliceService;
    AAISliceService aaiSliceService;

    @Before
    public void before() throws Exception {
        aaiSliceService = mock(AAISliceService.class);
        soSliceService = mock(SOSliceService.class);
        slicingService = new SlicingServiceImpl(aaiSliceService, soSliceService);
    }

    @Test
    public void itCanCreateSlicingService() {
        SlicingOrderDetail slicingOrderDetail = new SlicingOrderDetail();

        slicingOrderDetail.setCoverageArea("sdfgdert");
        slicingOrderDetail.setExpDataRateDL(100);
        slicingOrderDetail.setExpDataRateUL(200);
        slicingOrderDetail.setLatency(20);
        slicingOrderDetail.setMaxNumberofUEs(200);
        slicingOrderDetail.setUEMobilityLevel("share");
        slicingOrderDetail.setName("csmf");
        slicingOrderDetail.setResourceSharingLevel("share");
        slicingOrderDetail.setUseInterval("20");

        SlicingOrder slicingOrder = new SlicingOrder();
        slicingOrder.setSlicing_order_info(slicingOrderDetail);

        CreateResponse createResponse = new CreateResponse();
        RequestBody requestBody = null;
        when(soSliceService
            .submitOrders(requestBody))
            .thenReturn(successfulCall(createResponse));
        slicingService.createSlicingService(slicingOrder);
    }

    @Test
    public void createSlicingServiceWithThrowsException() {

        SlicingOrder slicingOrder = new SlicingOrder();
        RequestBody requestBody = null;
        when(soSliceService
            .submitOrders(requestBody))
            .thenReturn(failedCall("so is not exist!"));
        slicingService.createSlicingService(slicingOrder);
    }

    @Test
    public void itCanQuerySlicingOrderList() {
        JSONObject object = new JSONObject();
        when(aaiSliceService
            .listOrders(NsmfParamConstant.CUSTOM_5G, NsmfParamConstant.SERVICE_TYPE_5G))
            .thenReturn(successfulCall(object));
        slicingService.querySlicingOrderList("processing", "1", "100");
    }

    @Test
    public void querySlicingOrderListWithThrowsException() {
        when(aaiSliceService
            .listOrders(NsmfParamConstant.CUSTOM_5G, NsmfParamConstant.SERVICE_TYPE_5G))
            .thenReturn(failedCall("aai is not exist!"));
        slicingService.querySlicingOrderList("processing", "1", "100");
    }

    @Test
    public void emptyResponseWhenQuerySlicingOrderList() {
        Call<JSONObject> call = emptyBodyCall();
        when(aaiSliceService
            .listOrders(NsmfParamConstant.CUSTOM_5G, NsmfParamConstant.SERVICE_TYPE_5G)).thenReturn(call);
        slicingService.querySlicingOrderList("processing", "1", "100");
    }

    @Test
    public void itCanBuildOrderList() throws ParseException {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("service-instance-id", "id001");
        jsonObject.put("service-instance-name", "name001");
        jsonObject.put("created-at", "2019-12-23 11:31:19");
        jsonObject.put("service-type", "emBB");
        jsonObject.put("environment-context", "cn");
        jsonObject.put("orchestration-status", "activate");

        List<OrderInfo> orderList = new ArrayList<>();
        JSONArray array = new JSONArray();
        array.add(jsonObject);
        slicingService.buildOrderList(orderList, array);
    }

    @Test
    public void itCanAddProgressToOrder() {
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrder_creation_time("34562123");
        orderInfo.setOrder_id("sde2345rr");
        orderInfo.setOrder_status("creating");
        orderInfo.setService_snssai("sdffg34-344");
        orderInfo.setOrder_name("dfer-fgree");
        orderInfo.setOrder_index("1");
        orderInfo.setLast_operation_type("activate");
        orderInfo.setLast_operation_progress("79");
        List<OrderInfo> slicing_order_list = new ArrayList<>();
        slicing_order_list.add(orderInfo);

        OrderList orderList = new OrderList();
        orderList.setRecord_number(3);
        orderList.setSlicing_order_list(slicing_order_list);

        SOOperation soOperation = new SOOperation();
        RequestBody requestBody = null;
        String businessId = "test123";
        String operationId = "opera123";
        when(soSliceService.queryOperationProgress(businessId, operationId))
            .thenReturn(successfulCall(soOperation));
        slicingService.addProgressToOrder(orderList);
    }

    @Test
    public void addProgressToOrderWithThrowsException() {

        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrder_creation_time("34562123");
        orderInfo.setOrder_id("sde2345rr");
        orderInfo.setOrder_status("creating");
        orderInfo.setService_snssai("sdffg34-344");
        orderInfo.setOrder_name("dfer-fgree");
        orderInfo.setOrder_index("1");
        orderInfo.setLast_operation_type("activate");
        orderInfo.setLast_operation_progress("79");

        OrderList orderList = new OrderList();
        orderList.setRecord_number(3);

        String businessId = "test123";
        String operationId = "opera123";
        when(soSliceService.queryOperationProgress(businessId, operationId))
            .thenReturn(failedCall("so is not exist!"));
        slicingService.addProgressToOrder(orderList);
    }
}