2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Tech Mahindra
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import static org.junit.Assert.*
25 import org.junit.Before
27 import org.mockito.ArgumentCaptor
28 import org.mockito.Captor
29 import org.mockito.Mockito
30 import com.fasterxml.jackson.databind.ObjectMapper
32 import static org.mockito.Mockito.when
33 import static org.mockito.Mockito.times
34 import static org.mockito.Mockito.eq
36 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
37 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
39 class DoAllocateCoreNonSharedSliceTest extends MsoGroovyTest {
42 void init() throws IOException {
43 super.init("DoAllocateCoreNonSharedSlice")
47 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
50 public void testPreProcessRequest() {
52 String networkServiceModelInfo=""" {
53 "modelName" : "5GC-eMBB Service Proxy",
54 "modelUuid" : "b666119e-4400-47c6-a0c1-bbe050a33b47",
55 "modelInvariantUuid" : "a26327e1-4a9b-4883-b7a5-5f37dcb7405a",
56 "modelVersion" : "1.0",
57 "modelCustomizationUuid" : "cbc12c2a-67e6-4336-9236-eaf51eacdc75",
58 "modelInstanceName" : "5gcembb_proxy 0"
61 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("123456")
62 when(mockExecution.getVariable("networkServiceModelInfo")).thenReturn(networkServiceModelInfo)
64 DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
65 allocateNssi.preProcessRequest(mockExecution)
67 Mockito.verify(mockExecution, times(1)).setVariable(eq("networkServiceModelUuid"), captor.capture())
69 assertEquals("b666119e-4400-47c6-a0c1-bbe050a33b47", captor.getValue())
71 Mockito.verify(mockExecution, times(1)).setVariable(eq("networkServiceName"), captor.capture())
72 assertEquals("5GC-eMBB", captor.getValue())
74 Mockito.verify(mockExecution, times(1)).setVariable(eq("orchestrationStatus"), captor.capture())
75 assertEquals("created", captor.getValue())
76 Mockito.verify(mockExecution, times(4)).setVariable(captor.capture() as String, captor.capture())
80 void testPrepareServiceOrderRequest() {
82 String sliceProfile = "{\r\n \"snssaiList\": [ \r\n \"001-100001\"\r\n ],\r\n \"sliceProfileId\": \"ab9af40f13f721b5f13539d87484098\",\r\n \"plmnIdList\": [\r\n \"460-00\",\r\n \"460-01\"\r\n ],\r\n \"perfReq\": {\r\n \"perfReqEmbbList \": [\r\n {\r\n \"activityFactor\": 50\r\n }\r\n ]\r\n },\r\n \"maxNumberofUEs\": 200, \r\n \"coverageAreaTAList\": [ \r\n \"1\",\r\n \"2\",\r\n \"3\",\r\n \"4\"\r\n ],\r\n \"latency\": 2,\r\n \"resourceSharingLevel\": \"non-shared\" \r\n }"
83 when(mockExecution.getVariable("sliceProfile")).thenReturn(sliceProfile)
84 when(mockExecution.getVariable("serviceType")).thenReturn("5g")
85 when(mockExecution.getVariable("networkServiceName")).thenReturn("5g_embb")
86 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
87 when(mockExecution.getVariable("networkServiceModelUuid")).thenReturn("12345")
89 DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
90 allocateNssi.prepareServiceOrderRequest(mockExecution)
92 Mockito.verify(mockExecution, times(1)).setVariable(eq("serviceOrderRequest"), captor.capture())
93 String value = captor.getValue()
98 void testRetrieveServiceCharacteristicsAsKeyValue() {
100 String sliceProfile = "{\r\n \"snssaiList\": [ \r\n \"001-100001\"\r\n ],\r\n \"sliceProfileId\": \"ab9af40f13f721b5f13539d87484098\",\r\n \"plmnIdList\": [\r\n \"460-00\",\r\n \"460-01\"\r\n ],\r\n \"perfReq\": {\r\n \"perfReqEmbbList \": [\r\n {\r\n \"activityFactor\": 50\r\n }\r\n ]\r\n },\r\n \"maxNumberofUEs\": 200, \r\n \"coverageAreaTAList\": [ \r\n \"1\",\r\n \"2\",\r\n \"3\",\r\n \"4\"\r\n ],\r\n \"latency\": 2,\r\n \"resourceSharingLevel\": \"non-shared\" \r\n }"
101 Map<String, Object> ServiceCharacteristicValue = new LinkedHashMap<>()
102 Map<String, Object> ServiceCharacteristicValueObject = new LinkedHashMap<>()
103 ServiceCharacteristicValueObject.put("serviceCharacteristicValue","001-100001")
104 ServiceCharacteristicValue.put("name", "snssai")
105 ServiceCharacteristicValue.put("value", ServiceCharacteristicValueObject)
107 List expectedList= new ArrayList()
108 expectedList.add(ServiceCharacteristicValue)
110 ObjectMapper objectMapper = new ObjectMapper()
111 Map<String, Object> serviceCharacteristic = objectMapper.readValue(sliceProfile, Map.class);
113 DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
114 List characteristicList=allocateNssi.retrieveServiceCharacteristicsAsKeyValue(serviceCharacteristic)
116 assertEquals(expectedList, characteristicList)