2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License")
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
24 import org.junit.Before
26 import org.mockito.ArgumentCaptor
27 import org.mockito.Captor
28 import org.mockito.Mockito
29 import org.onap.aaiclient.client.aai.AAIObjectType
30 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
31 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
32 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
33 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
34 import org.onap.so.beans.nsmf.oof.TemplateInfo
35 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
36 import org.onap.so.bpmn.common.scripts.OofUtils
38 import static org.junit.Assert.assertNotNull
39 import static org.junit.Assert.assertEquals
40 import static org.mockito.ArgumentMatchers.eq
41 import static org.mockito.Mockito.*
43 class DoAllocateTnNssiTest extends MsoGroovyTest {
45 void init() throws IOException {
46 super.init("DoAllocateTnNssiTest")
50 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
53 void testPreProcessRequest() {
54 when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
55 when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback")
56 when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71")
57 when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6")
58 //when(mockExecution.getVariable("serviceInstanceID")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7")
59 //when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
60 when(mockExecution.getVariable("operationType")).thenReturn("opTypeTest")
61 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
62 when(mockExecution.getVariable("servicename")).thenReturn("5G-test")
63 when(mockExecution.getVariable("networkType")).thenReturn("5G-network")
64 when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G-service")
65 when(mockExecution.getVariable("nsiId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
66 when(mockExecution.getVariable("jobId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
67 when(mockExecution.getVariable("sliceParams")).thenReturn(mockSliceParams())
69 TnAllocateNssi obj = new TnAllocateNssi()
70 obj.preProcessRequest(mockExecution)
71 Mockito.verify(mockExecution, times(1)).setVariable(eq("sliceServiceInstanceId"), captor.capture())
72 String sliceServiceInstanceId = captor.getValue()
73 assertNotNull(sliceServiceInstanceId)
77 void testCreateServiceInstance() {
78 when(mockExecution.getVariable("sliceServiceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
79 when(mockExecution.getVariable("sliceServiceInstanceName")).thenReturn("5G-service")
80 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
81 when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G")
82 when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71")
83 when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6")
84 when(mockExecution.getVariable("sliceProfile")).thenReturn(mockSliceProfile())
86 // JsonUtils jsonUtil = new JsonUtils()
87 // String sliceProfile = jsonUtil.getJsonValue(mockSliceParams(), "sliceProfile")
88 // when(mockExecution.getVariable("sliceProfile")).thenReturn(sliceProfile)
90 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5ad89cf9-0569-4a93-9306-d8324321e2be"))
91 DoCreateTnNssiInstance obj = spy(DoCreateTnNssiInstance.class)
92 when(obj.getAAIClient()).thenReturn(client)
94 obj.createServiceInstance(mockExecution)
98 private String mockSliceParams() {
104 "sliceProfileId": "ab9af40f13f721b5f13539d87484098",
111 "coverageAreaTAList": [
115 "resourceSharingLevel": "non-shared"
117 "transportSliceNetworks": [
121 "transportEndpointA": "tranportEp_ID_XXX",
122 "transportEndpointB": "tranportEp_ID_YYY"
125 "transportEndpointA": "tranportEp_ID_AAA",
126 "transportEndpointB": "tranportEp_ID_BBB"
133 "transportEndpointA": "tranportEp_ID_CCC",
134 "transportEndpointB": "tranportEp_ID_DDD"
137 "transportEndpointA": "tranportEp_ID_EEE",
138 "transportEndpointB": "tranportEp_ID_FFF"
144 "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX",
145 "nsiName": "eMBB-001"
149 return expect.replaceAll("\\\\s+", "")
152 private String mockSliceProfile() {
157 "sliceProfileId": "ab9af40f13f721b5f13539d87484098",
164 "coverageAreaTAList": [
168 "resourceSharingLevel": "non-shared"
170 return expect.replaceAll("\\\\s+", "")
174 void testPrepareOofSelection() {
175 when(mockExecution.getVariable("msoRequestId")).thenReturn("10dad82d-4bd9-467a-b113-5f8ea7eaae3c")
176 when(mockExecution.getVariable("modelUuid")).thenReturn("e2eb2fe3-92a7-447b-8582-077db5cd0862")
177 when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("22e6ce80-a55f-4171-a457-a7ecb1865669")
178 when(mockExecution.getVariable("tnModelName")).thenReturn("Tn_ONAP_internal_BH")
179 when(mockExecution.getVariable("mso.adapters.oof.timeout")).thenReturn("")
180 TnAllocateNssi obj = spy(TnAllocateNssi.class)
181 OofUtils oofUtils = spy(OofUtils.class)
182 String requestId = "10dad82d-4bd9-467a-b113-5f8ea7eaae3c"
183 String nsstInfo = "\"{\"UUID\":\"e2eb2fe3-92a7-447b-8582-077db5cd0862\",\"invariantUUID\":\"22e6ce80-a55f-4171-a457-a7ecb1865669\",\"name\":\"Tn_ONAP_internal_BH\"}"
184 String messageType = "NSSISelectionResponse"
185 String sliceProfile = "{\"maxBandwidth\":3000,\"sliceProfileId\":\"ab9af40f13f721b5f13539d87484098\",\"latency\":10,\"snssaiList\":[\"001-100001\"],\"pLMNIdList\":[\"460-00\",\"460-01\"],\"perfReq\":{},\"coverageAreaTAList\":[],\"resourceSharingLevel\":\"shared\"}}"
186 Integer timeout = 600
188 when(oofUtils.buildSelectNSSIRequest(requestId, nsstInfo as TemplateInfo, messageType, sliceProfile, timeout)).thenReturn("""
190 "apiPath": "/api/oof/selection/nssi/v1",
191 "requestDetails": "{\\"requestInfo\\":{\\"transactionId\\":\\"10dad82d-4bd9-467a-b113-5f8ea7eaae3c\\",\\"requestId\\":\\"10dad82d-4bd9-467a-b113-5f8ea7eaae3c\\",\\"callbackUrl\\":\\"http://so-oof-adapter.onap:8090/so/adapters/oof/callback/v1/NSSISelectionResponse/10dad82d-4bd9-467a-b113-5f8ea7eaae3c\\",\\"sourceId\\":\\"SO\\",\\"timeout\\":600,\\"numSolutions\\":1},\\"NSSTInfo\\":{\\"UUID\\":\\"e2eb2fe3-92a7-447b-8582-077db5cd0862\\",\\"invariantUUID\\":\\"22e6ce80-a55f-4171-a457-a7ecb1865669\\",\\"name\\":\\"Tn_ONAP_internal_BH\\"},\\"sliceProfile\\":{\\"maxBandwidth\\":3000,\\"sliceProfileId\\":\\"ab9af40f13f721b5f13539d87484098\\",\\"latency\\":10,\\"snssaiList\\":[\\"001-100001\\"],\\"pLMNIdList\\":[\\"460-00\\",\\"460-01\\"],\\"perfReq\\":{},\\"coverageAreaTAList\\":[],\\"resourceSharingLevel\\":\\"shared\\"}}"
192 }""".replaceAll("\\\\s+", ""))
193 obj.prepareOofSelection(mockExecution)
194 verify(mockExecution, times(1)).setVariable(eq("nssiSelection_oofRequest"), captor.capture())
195 String nssiSelection_oofRequest = captor.getValue()
196 assertNotNull(nssiSelection_oofRequest)
200 void testprocessOofSelection() {
201 when(mockExecution.getVariable("nssiSelection_oofRequest")).thenReturn("""
203 "requestId": "a727643a-bf89-4fd9-b33c-b7bdda18c2b7",
204 "transactionId": "a727643a-bf89-4fd9-b33c-b7bdda18c2b7",
205 "requestStatus": "completed",
209 "UUID": "e2eb2fe3-92a7-447b-8582-077db5cd0862",
210 "invariantUUID": "22e6ce80-a55f-4171-a457-a7ecb1865669",
211 "NSSIName": "nssi_tnservice12",
212 "NSSIId": "fe26a924-3845-4001-b84e-a439a27a88c0"
215 }""".replaceAll("\\\\s+", ""))
216 TnAllocateNssi obj = spy(TnAllocateNssi.class)
217 ArrayList<String> solution = new ArrayList<>()
218 assertEquals(1, solution.size())
219 verify(mockExecution, times(1)).setVariable(eq("isOofTnNssiSelected"), captor.capture())
220 String isOofTnNssiSelected = captor.getValue()
221 assertEquals("true", isOofTnNssiSelected)