5G core nssmf - Allocate api
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DoAllocateCoreNonSharedSliceTest.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import static org.junit.Assert.assertNotNull
24 import static org.junit.Assert.assertEquals
25
26 import org.junit.Before
27 import org.junit.Test
28 import org.mockito.ArgumentCaptor
29 import org.mockito.Captor
30 import org.mockito.Mockito
31 import com.fasterxml.jackson.databind.ObjectMapper
32
33 import static org.mockito.Mockito.when
34 import static org.mockito.Mockito.times
35 import static org.mockito.Mockito.eq
36
37 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
38 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
39
40 class DoAllocateCoreNonSharedSliceTest extends MsoGroovyTest {
41
42     @Before
43     void init() throws IOException {
44         super.init("DoAllocateCoreNonSharedSlice")
45     }
46
47     @Captor
48     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
49
50     @Test
51     public void testPreProcessRequest() {
52
53         String networkServiceModelInfo="""{
54                         "modelInfo"                : {
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"
61                 },
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"
65                 }"""
66
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\"endPoint\": {\r\n\t\t\"ipAdress\": \"\",\r\n\t\t\"logicalInterfaceId\": \"\",\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}"""
68
69         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("123456")
70         when(mockExecution.getVariable("networkServiceModelInfo")).thenReturn(networkServiceModelInfo)
71
72                 when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
73
74         DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
75         allocateNssi.preProcessRequest(mockExecution)
76
77         Mockito.verify(mockExecution, times(1)).setVariable(eq("networkServiceModelUuid"), captor.capture())
78         captor.getValue()
79         assertEquals("f3666c56-744e-4055-9f4a-0726460898e0", captor.getValue())
80
81         Mockito.verify(mockExecution, times(1)).setVariable(eq("networkServiceName"), captor.capture())
82         assertEquals("vfw_cnf_service_2310", captor.getValue())
83
84         Mockito.verify(mockExecution, times(1)).setVariable(eq("orchestrationStatus"), captor.capture())
85         assertEquals("created", captor.getValue())
86
87         Mockito.verify(mockExecution, times(5)).setVariable(captor.capture() as String, captor.capture())
88     }
89
90     @Test
91     void testPrepareServiceOrderRequest() {
92
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")
100
101         DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
102         allocateNssi.prepareServiceOrderRequest(mockExecution)
103
104         Mockito.verify(mockExecution, times(1)).setVariable(eq("serviceOrderRequest"), captor.capture())
105         String value = captor.getValue()
106         assertNotNull(value)
107     }
108
109     @Test
110     void testRetrieveServiceCharacteristicsAsKeyValue() {
111
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)
118
119         List expectedList= new ArrayList()
120         expectedList.add(ServiceCharacteristicValue)
121
122         ObjectMapper objectMapper = new ObjectMapper()
123         Map<String, Object> serviceCharacteristic = objectMapper.readValue(sliceProfile, Map.class);
124
125         //provide mock vnfInstance name
126         when(mockExecution.getVariable("vnfInstanceName")).thenReturn("vf00")
127         DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
128         List characteristicList=allocateNssi.retrieveServiceCharacteristicsAsKeyValue(mockExecution, serviceCharacteristic)
129         assertEquals(expectedList, characteristicList)
130     }
131 }