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.assertNotNull
24 import static org.junit.Assert.assertEquals
26 import org.junit.Before
28 import org.mockito.ArgumentCaptor
29 import org.mockito.Captor
30 import org.mockito.Mockito
31 import com.fasterxml.jackson.databind.ObjectMapper
33 import static org.mockito.Mockito.when
34 import static org.mockito.Mockito.times
35 import static org.mockito.Mockito.eq
37 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
38 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
40 class DoAllocateCoreNonSharedSliceTest extends MsoGroovyTest {
43 void init() throws IOException {
44 super.init("DoAllocateCoreNonSharedSlice")
48 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
51 public void testPreProcessRequest() {
53 String networkServiceModelInfo="""{
55 "modelName" : "vfw_cnf_service_2310 Service Proxy",
56 "modelUuid" : "35386eb0-b673-48c5-9757-45ecfc506bf8",
57 "modelInvariantUuid" : "b048d7bc-8bfd-4950-aea5-22b1aaf5d76b",
58 "modelVersion" : "1.0",
59 "modelCustomizationUuid" : "82f4db76-e7ad-47eb-b5e3-661683f14de6",
60 "modelInstanceName" : "vfw_cnf_service_2310_proxy 0"
62 "toscaNodeType" : "org.openecomp.nodes.vfw_cnf_service_2310_proxy",
63 "description" : "A Proxy for Service vfw_cnf_service_2310",
64 "sourceModelUuid" : "f3666c56-744e-4055-9f4a-0726460898e0"
67 String sliceParams= """{\r\n\t\"sliceProfile\": {\r\n\t\t\"snssaiList\": [\r\n\t\t\t\"001-100001\"\r\n\t\t],\r\n\t\t\"sliceProfileId\": \"ab9af40f13f721b5f13539d87484098\",\r\n\t\t\"plmnIdList\": [\r\n\t\t\t\"460-00\",\r\n\t\t\t\"460-01\"\r\n\t\t],\r\n\t\t\"perfReq\": {\r\n\t\t\t\"perfReqEmbbList \": [{\r\n\t\t\t\t\"activityFactor\": 50\r\n\t\t\t}]\r\n\t\t},\r\n\t\t\"maxNumberofUEs\": 200,\r\n\t\t\"coverageAreaTAList\": [\r\n\t\t\t\"1\",\r\n\t\t\t\"2\",\r\n\t\t\t\"3\",\r\n\t\t\t\"4\"\r\n\t\t],\r\n\t\t\"latency\": 2,\r\n\t\t\"resourceSharingLevel\": \"non-shared\"\r\n\t},\r\n\t\"endPoints\": [{\r\n\t\t\"IpAdress\": \"\",\r\n\t\t\"LogicalLinkId\": \"\",\r\n\t\t\"nextHopInfo\": \"\"\r\n\t}],\r\n\t\"nsiInfo\": {\r\n\t\t\"nsiId\": \"NSI-M-001-HDBNJ-NSMF-01-A-ZX\",\r\n\t\t\"nsiName\": \"eMBB-001\"\r\n\t},\r\n\t\"scriptName\": \"AN1\"\r\n}"""
69 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("123456")
70 when(mockExecution.getVariable("networkServiceModelInfo")).thenReturn(networkServiceModelInfo)
72 when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
74 DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
75 allocateNssi.preProcessRequest(mockExecution)
77 Mockito.verify(mockExecution, times(1)).setVariable(eq("networkServiceModelUuid"), captor.capture())
79 assertEquals("f3666c56-744e-4055-9f4a-0726460898e0", captor.getValue())
81 Mockito.verify(mockExecution, times(1)).setVariable(eq("networkServiceName"), captor.capture())
82 assertEquals("vfw_cnf_service_2310", captor.getValue())
84 Mockito.verify(mockExecution, times(1)).setVariable(eq("orchestrationStatus"), captor.capture())
85 assertEquals("created", captor.getValue())
87 Mockito.verify(mockExecution, times(5)).setVariable(captor.capture() as String, captor.capture())
91 void testPrepareServiceOrderRequest() {
93 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 }"
94 when(mockExecution.getVariable("sliceProfile")).thenReturn(sliceProfile)
95 when(mockExecution.getVariable("serviceType")).thenReturn("5g")
96 when(mockExecution.getVariable("networkServiceName")).thenReturn("5g_embb")
97 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
98 when(mockExecution.getVariable("networkServiceModelUuid")).thenReturn("12345")
99 when(mockExecution.getVariable("vnfInstanceName")).thenReturn("vf00")
101 DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
102 allocateNssi.prepareServiceOrderRequest(mockExecution)
104 Mockito.verify(mockExecution, times(1)).setVariable(eq("serviceOrderRequest"), captor.capture())
105 String value = captor.getValue()
110 void testRetrieveServiceCharacteristicsAsKeyValue() {
112 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 }"
113 Map<String, Object> ServiceCharacteristicValue = new LinkedHashMap<>()
114 Map<String, Object> ServiceCharacteristicValueObject = new LinkedHashMap<>()
115 ServiceCharacteristicValueObject.put("serviceCharacteristicValue","001-100001")
116 ServiceCharacteristicValue.put("name", "vf00_snssai")
117 ServiceCharacteristicValue.put("value", ServiceCharacteristicValueObject)
119 List expectedList= new ArrayList()
120 expectedList.add(ServiceCharacteristicValue)
122 ObjectMapper objectMapper = new ObjectMapper()
123 Map<String, Object> serviceCharacteristic = objectMapper.readValue(sliceProfile, Map.class);
125 DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
126 List characteristicList=allocateNssi.retrieveServiceCharacteristicsAsKeyValue(mockExecution, serviceCharacteristic)
127 assertEquals(expectedList, characteristicList)