1eddf66b862ef76168ab62a2fce4fee68a80f49b
[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         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("123456")
62         when(mockExecution.getVariable("networkServiceModelInfo")).thenReturn(networkServiceModelInfo)
63
64         DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
65         allocateNssi.preProcessRequest(mockExecution)
66
67         Mockito.verify(mockExecution, times(1)).setVariable(eq("networkServiceModelUuid"), captor.capture())
68         captor.getValue()
69         assertEquals("b666119e-4400-47c6-a0c1-bbe050a33b47", captor.getValue())
70
71         Mockito.verify(mockExecution, times(1)).setVariable(eq("networkServiceName"), captor.capture())
72         assertEquals("5GC-eMBB", captor.getValue())
73
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())
77     }
78
79     @Test
80     void testPrepareServiceOrderRequest() {
81
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")
88
89         DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
90         allocateNssi.prepareServiceOrderRequest(mockExecution)
91
92         Mockito.verify(mockExecution, times(1)).setVariable(eq("serviceOrderRequest"), captor.capture())
93         String value = captor.getValue()
94         assertNotNull(value)
95     }
96
97     @Test
98     void testRetrieveServiceCharacteristicsAsKeyValue() {
99
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)
106
107         List expectedList= new ArrayList()
108         expectedList.add(ServiceCharacteristicValue)
109
110         ObjectMapper objectMapper = new ObjectMapper()
111         Map<String, Object> serviceCharacteristic = objectMapper.readValue(sliceProfile, Map.class);
112
113         DoAllocateCoreNonSharedSlice allocateNssi = new DoAllocateCoreNonSharedSlice()
114         List characteristicList=allocateNssi.retrieveServiceCharacteristicsAsKeyValue(serviceCharacteristic)
115
116         assertEquals(expectedList, characteristicList)
117     }
118 }