6b15407dd0199827b48f1a5a368d6dda31d2e9b3
[so.git] /
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.*
24
25 import org.junit.Before
26 import org.junit.Test
27 import org.mockito.ArgumentCaptor
28 import org.mockito.Captor
29 import org.mockito.Mockito
30 import com.fasterxml.jackson.databind.ObjectMapper
31
32 import static org.mockito.Mockito.when
33 import static org.mockito.Mockito.times
34 import static org.mockito.Mockito.eq
35
36 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
37 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
38
39 class DoAllocateCoreNonSharedSliceTest extends MsoGroovyTest {
40
41     @Before
42     void init() throws IOException {
43         super.init("DoAllocateCoreNonSharedSlice")
44     }
45
46     @Captor
47     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
48
49     @Test
50     public void testPreProcessRequest() {
51
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"
59         }"""
60
61                 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}"""
62
63         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("123456")
64         when(mockExecution.getVariable("networkServiceModelInfo")).thenReturn(networkServiceModelInfo)
65
66                 when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
67
68         DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
69         allocateNssi.preProcessRequest(mockExecution)
70
71         Mockito.verify(mockExecution, times(1)).setVariable(eq("networkServiceModelUuid"), captor.capture())
72         captor.getValue()
73         assertEquals("b666119e-4400-47c6-a0c1-bbe050a33b47", captor.getValue())
74
75         Mockito.verify(mockExecution, times(1)).setVariable(eq("networkServiceName"), captor.capture())
76         assertEquals("5GC-eMBB", captor.getValue())
77
78         Mockito.verify(mockExecution, times(1)).setVariable(eq("orchestrationStatus"), captor.capture())
79         assertEquals("created", captor.getValue())
80
81         Mockito.verify(mockExecution, times(5)).setVariable(captor.capture() as String, captor.capture())
82     }
83
84     @Test
85     void testPrepareServiceOrderRequest() {
86
87         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    }"
88         when(mockExecution.getVariable("sliceProfile")).thenReturn(sliceProfile)
89         when(mockExecution.getVariable("serviceType")).thenReturn("5g")
90         when(mockExecution.getVariable("networkServiceName")).thenReturn("5g_embb")
91         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
92         when(mockExecution.getVariable("networkServiceModelUuid")).thenReturn("12345")
93
94         DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
95         allocateNssi.prepareServiceOrderRequest(mockExecution)
96
97         Mockito.verify(mockExecution, times(1)).setVariable(eq("serviceOrderRequest"), captor.capture())
98         String value = captor.getValue()
99         assertNotNull(value)
100     }
101
102     @Test
103     void testRetrieveServiceCharacteristicsAsKeyValue() {
104
105         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    }"
106         Map<String, Object> ServiceCharacteristicValue = new LinkedHashMap<>()
107         Map<String, Object> ServiceCharacteristicValueObject = new LinkedHashMap<>()
108         ServiceCharacteristicValueObject.put("serviceCharacteristicValue","001-100001")
109         ServiceCharacteristicValue.put("name", "snssai")
110         ServiceCharacteristicValue.put("value", ServiceCharacteristicValueObject)
111
112         List expectedList= new ArrayList()
113         expectedList.add(ServiceCharacteristicValue)
114
115         ObjectMapper objectMapper = new ObjectMapper()
116         Map<String, Object> serviceCharacteristic = objectMapper.readValue(sliceProfile, Map.class);
117
118         DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
119         List characteristicList=allocateNssi.retrieveServiceCharacteristicsAsKeyValue(serviceCharacteristic)
120
121         assertEquals(expectedList, characteristicList)
122     }
123 }