diff options
author | hyu2010 <henry.yu1@huawei.com> | 2020-09-07 18:07:25 -0400 |
---|---|---|
committer | hyu2010 <henry.yu1@huawei.com> | 2020-09-15 21:21:22 -0400 |
commit | c2110d59a01f3343a42cf55045bf67e456c2f182 (patch) | |
tree | 606150d795cd28469204e4fe35c13016ad89fe19 /bpmn/so-bpmn-infrastructure-common/src/test/groovy | |
parent | 78be30206872dbf2907a42d5070b197536d4a9c2 (diff) |
Implementation of TN NSSMF WF on SO
(1) Workflow of Allocate TN NSSI
(2) Workflow of Deallocate TN NSSI
(3) Workflow of Activate and Deactivate TN NSSI
(4) Workflow of Modify TN NSSI
NOTE:
1. The full implementation of TN NSSMF consists of two layers:
(1) The TN Sice definition layer, which is an orchestration
layer that provides the NBI of TN NSSMF to its consumers
(i.e., it concerns the "what" question), and (2) the TN slice
realization layer, which is responsible for the actual network
configurations of TN slicing (i.e., the "how" question). The first
layer is done on the SO (i.e., this changeset), while the 2nd
layer is implemented on the SDNC. That's why this changeset is
relatively simple, since the "real work" is done by the SDNC.
2. This changeset depends on the common NSSMF WF
(https://gerrit.onap.org/r/c/so/+/111477)
Issue-ID: SO-2959
Signed-off-by: hyu2010 <henry.yu1@huawei.com>
Change-Id: I9d4e77b7706d28fb4133ddca0ff1d6e307be613d
Signed-off-by: hyu2010 <henry.yu1@huawei.com>
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/test/groovy')
4 files changed, 654 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateTnNssiTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateTnNssiTest.groovy new file mode 100644 index 0000000000..93557a48cf --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateTnNssiTest.groovy @@ -0,0 +1,178 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + # + # Licensed under the Apache License, Version 2.0 (the "License") + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.onap.so.bpmn.common.scripts.MsoGroovyTest + +import static org.junit.Assert.assertNotNull +import static org.mockito.ArgumentMatchers.eq +import static org.mockito.Mockito.* + +class DoActivateTnNssiTest extends MsoGroovyTest { + @Before + void init() throws IOException { + super.init("DoActivateTnNssiTest") + } + + @Captor + static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Test + void testPreProcessRequest() { + when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82") + when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback") + when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71") + when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6") + when(mockExecution.getVariable("serviceInstanceID")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7") + when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0") + when(mockExecution.getVariable("operationType")).thenReturn("opTypeTest") + when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer") + when(mockExecution.getVariable("servicename")).thenReturn("5G-test") + when(mockExecution.getVariable("networkType")).thenReturn("5G-network") + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G-service") + when(mockExecution.getVariable("nsiId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56") + when(mockExecution.getVariable("jobId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") + when(mockExecution.getVariable("operationType")).thenReturn("activateInstance") + when(mockExecution.getVariable("sliceParams")).thenReturn(mockSliceParams()) + + DoActivateTnNssi obj = new DoActivateTnNssi() + obj.preProcessRequest(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("sliceServiceInstanceId"), captor.capture()) + String sliceServiceInstanceId = captor.getValue() + assertNotNull(sliceServiceInstanceId) + } + + @Test + void testPreprocessSdncRequest() { + when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82") + when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback") + when(mockExecution.getVariable("sliceServiceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be") + when(mockExecution.getVariable("sliceServiceInstanceName")).thenReturn("5G-service") + when(mockExecution.getVariable("actionType")).thenReturn("activate") + when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer") + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G") + when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71") + when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6") + when(mockExecution.getVariable("sliceParams")).thenReturn(mockSliceParams()) + when(mockExecution.getVariable("serviceModelInfo")).thenReturn(mockServiceModelInfo()) +// JsonUtils jsonUtil = new JsonUtils() +// String sliceProfile = jsonUtil.getJsonValue(mockSliceParams(), "sliceProfile") +// when(mockExecution.getVariable("sliceProfile")).thenReturn(sliceProfile) + + DoActivateTnNssi obj = spy(DoActivateTnNssi.class) + + obj.preprocessSdncActOrDeactTnNssiRequest(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("TNNSSMF_SDNCRequest"), captor.capture()) + String request = captor.getValue() + assertNotNull(request) + } + + + private String mockSliceParams() { + String expect = """{ + "sliceProfile": { + "snssaiList": [ + "001-100001" + ], + "sliceProfileId": "ab9af40f13f721b5f13539d87484098", + "plmnIdList": [ + "460-00", + "460-01" + ], + "perfReq": { + }, + "coverageAreaTAList": [ + ], + "latency": 2, + "maxBandwidth": 100, + "resourceSharingLevel": "non-shared" + }, + "transportSliceNetworks": [ + { + "connectionLinks": [ + { + "transportEndpointA": "tranportEp_ID_XXX", + "transportEndpointB": "tranportEp_ID_YYY" + }, + { + "transportEndpointA": "tranportEp_ID_AAA", + "transportEndpointB": "tranportEp_ID_BBB" + } + ] + }, + { + "connectionLinks": [ + { + "transportEndpointA": "tranportEp_ID_CCC", + "transportEndpointB": "tranportEp_ID_DDD" + }, + { + "transportEndpointA": "tranportEp_ID_EEE", + "transportEndpointB": "tranportEp_ID_FFF" + } + ] + } + ], + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + "scriptName": "AN1" + }""" + return expect.replaceAll("\\\\s+", "") + } + + private String mockSliceProfile() { + String expect = """{ + "snssaiList": [ + "001-100001" + ], + "sliceProfileId": "ab9af40f13f721b5f13539d87484098", + "plmnIdList": [ + "460-00", + "460-01" + ], + "perfReq": { + }, + "coverageAreaTAList": [ + ], + "latency": 2, + "maxBandwidth": 100, + "resourceSharingLevel": "non-shared" + }""" + return expect.replaceAll("\\\\s+", "") + } + + private String mockServiceModelInfo() { + String expect = """{ + "modelInvariantUuid":"f85cbcc0-ad74-45d7-a5a1-17c8744fdb71", + "modelUuid":"36a3a8ea-49a6-4ac8-b06c-89a54544b9b6", + "modelVersion":"" + }""" + return expect.replaceAll("\\\\s+", "") + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateTnNssiTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateTnNssiTest.groovy new file mode 100644 index 0000000000..33110b6e5b --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateTnNssiTest.groovy @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + # + # Licensed under the Apache License, Version 2.0 (the "License") + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.onap.aaiclient.client.aai.AAIObjectType +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.so.bpmn.common.scripts.MsoGroovyTest + +import static org.junit.Assert.assertNotNull +import static org.mockito.ArgumentMatchers.eq +import static org.mockito.Mockito.* + +class DoAllocateTnNssiTest extends MsoGroovyTest { + @Before + void init() throws IOException { + super.init("DoAllocateTnNssiTest") + } + + @Captor + static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Test + void testPreProcessRequest() { + when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82") + when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback") + when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71") + when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6") + //when(mockExecution.getVariable("serviceInstanceID")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7") + //when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0") + when(mockExecution.getVariable("operationType")).thenReturn("opTypeTest") + when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer") + when(mockExecution.getVariable("servicename")).thenReturn("5G-test") + when(mockExecution.getVariable("networkType")).thenReturn("5G-network") + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G-service") + when(mockExecution.getVariable("nsiId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56") + when(mockExecution.getVariable("jobId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") + when(mockExecution.getVariable("sliceParams")).thenReturn(mockSliceParams()) + + TnAllocateNssi obj = new TnAllocateNssi() + obj.preProcessRequest(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("sliceServiceInstanceId"), captor.capture()) + String sliceServiceInstanceId = captor.getValue() + assertNotNull(sliceServiceInstanceId) + } + + @Test + void testCreateServiceInstance() { + when(mockExecution.getVariable("sliceServiceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be") + when(mockExecution.getVariable("sliceServiceInstanceName")).thenReturn("5G-service") + when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer") + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G") + when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71") + when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6") + when(mockExecution.getVariable("sliceProfile")).thenReturn(mockSliceProfile()) + +// JsonUtils jsonUtil = new JsonUtils() +// String sliceProfile = jsonUtil.getJsonValue(mockSliceParams(), "sliceProfile") +// when(mockExecution.getVariable("sliceProfile")).thenReturn(sliceProfile) + + AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be") + DoCreateTnNssiInstance obj = spy(DoCreateTnNssiInstance.class) + when(obj.getAAIClient()).thenReturn(client) + + obj.createServiceInstance(mockExecution) + } + + + private String mockSliceParams() { + String expect = """{ + "sliceProfile": { + "snssaiList": [ + "001-100001" + ], + "sliceProfileId": "ab9af40f13f721b5f13539d87484098", + "plmnIdList": [ + "460-00", + "460-01" + ], + "perfReq": { + }, + "coverageAreaTAList": [ + ], + "latency": 2, + "maxBandwidth": 100, + "resourceSharingLevel": "non-shared" + }, + "transportSliceNetworks": [ + { + "connectionLinks": [ + { + "transportEndpointA": "tranportEp_ID_XXX", + "transportEndpointB": "tranportEp_ID_YYY" + }, + { + "transportEndpointA": "tranportEp_ID_AAA", + "transportEndpointB": "tranportEp_ID_BBB" + } + ] + }, + { + "connectionLinks": [ + { + "transportEndpointA": "tranportEp_ID_CCC", + "transportEndpointB": "tranportEp_ID_DDD" + }, + { + "transportEndpointA": "tranportEp_ID_EEE", + "transportEndpointB": "tranportEp_ID_FFF" + } + ] + } + ], + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + "scriptName": "AN1" + }""" + return expect.replaceAll("\\\\s+", "") + } + + private String mockSliceProfile() { + String expect = """{ + "snssaiList": [ + "001-100001" + ], + "sliceProfileId": "ab9af40f13f721b5f13539d87484098", + "plmnIdList": [ + "460-00", + "460-01" + ], + "perfReq": { + }, + "coverageAreaTAList": [ + ], + "latency": 2, + "maxBandwidth": 100, + "resourceSharingLevel": "non-shared" + }""" + return expect.replaceAll("\\\\s+", "") + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssiTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssiTest.groovy new file mode 100644 index 0000000000..eac79a9473 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssiTest.groovy @@ -0,0 +1,135 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + # + # Licensed under the Apache License, Version 2.0 (the "License") + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.onap.aaiclient.client.aai.AAIObjectType +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.so.bpmn.common.scripts.MsoGroovyTest + +import static org.junit.Assert.assertNotNull +import static org.mockito.ArgumentMatchers.eq +import static org.mockito.Mockito.* + +class DoDeallocateTnNssiTest extends MsoGroovyTest { + @Before + void init() throws IOException { + super.init("DeallocateTnNssiTest") + } + + @Captor + static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Test + void testPreProcessRequest() { + when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82") + when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback") + when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71") + when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6") + when(mockExecution.getVariable("serviceInstanceID")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7") + when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0") + when(mockExecution.getVariable("operationType")).thenReturn("opTypeTest") + when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer") + when(mockExecution.getVariable("servicename")).thenReturn("5G-test") + when(mockExecution.getVariable("networkType")).thenReturn("5G-network") + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G-service") + when(mockExecution.getVariable("nsiId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56") + when(mockExecution.getVariable("jobId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") + when(mockExecution.getVariable("sliceParams")).thenReturn(""" + { + "sliceProfile": { + "snssaiList": [ + "001-100001" + ], + "sliceProfileId": "ab9af40f13f721b5f13539d87484098", + "plmnIdList": [ + "460-00", + "460-01" + ], + "perfReq": { + }, + "coverageAreaTAList": [ + ], + "latency": 2, + "maxBandwidth": 100, + "resourceSharingLevel": "non-shared" + }, + "transportSliceNetworks": [ + { + "connectionLinks": [ + { + "transportEndpointA": "tranportEp_ID_XXX", + "transportEndpointB": "tranportEp_ID_YYY" + }, + { + "transportEndpointA": "tranportEp_ID_AAA", + "transportEndpointB": "tranportEp_ID_BBB" + } + ] + }, + { + "connectionLinks": [ + { + "transportEndpointA": "tranportEp_ID_CCC", + "transportEndpointB": "tranportEp_ID_DDD" + }, + { + "transportEndpointA": "tranportEp_ID_EEE", + "transportEndpointB": "tranportEp_ID_FFF" + } + ] + } + ], + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + "scriptName": "AN1" + }""".replaceAll("\\\\s+", "")) + + DoDeallocateTnNssi runScript = new DoDeallocateTnNssi() + runScript.preProcessRequest(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("sliceServiceInstanceId"), captor.capture()) + String sliceServiceInstanceId = captor.getValue() + assertNotNull(sliceServiceInstanceId) + } + + @Test + void testDeleteServiceInstance() { + when(mockExecution.getVariable("serviceInstanceID")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be") + when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer") + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G") + + AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be") + DoDeallocateTnNssi obj = spy(DoDeallocateTnNssi.class) + when(obj.getAAIClient()).thenReturn(client) + doNothing().when(client).delete(serviceInstanceUri) + + obj.deleteServiceInstance(mockExecution) + Mockito.verify(client, times(1)).delete(serviceInstanceUri) + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssiTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssiTest.groovy new file mode 100644 index 0000000000..bbbec3bb46 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssiTest.groovy @@ -0,0 +1,174 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + # + # Licensed under the Apache License, Version 2.0 (the "License") + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.onap.aaiclient.client.aai.AAIObjectType +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.so.bpmn.common.scripts.MsoGroovyTest + +import static org.junit.Assert.assertNotNull +import static org.mockito.ArgumentMatchers.eq +import static org.mockito.Mockito.* + +class DoModifyTnNssiTest extends MsoGroovyTest { + @Before + void init() throws IOException { + super.init("DoModifyTnNssiTest") + } + + @Captor + static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Test + void testPreProcessRequest() { + when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82") + when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback") + when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71") + when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6") + when(mockExecution.getVariable("serviceInstanceID")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7") + when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0") + when(mockExecution.getVariable("operationType")).thenReturn("opTypeTest") + when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer") + when(mockExecution.getVariable("servicename")).thenReturn("5G-test") + when(mockExecution.getVariable("networkType")).thenReturn("5G-network") + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G-service") + when(mockExecution.getVariable("nsiId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56") + when(mockExecution.getVariable("jobId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4") + when(mockExecution.getVariable("operationType")).thenReturn("activateInstance") + when(mockExecution.getVariable("sliceParams")).thenReturn(mockSliceParams()) + + DoModifyTnNssi obj = new DoModifyTnNssi() + obj.preProcessRequest(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("sliceServiceInstanceId"), captor.capture()) + String sliceServiceInstanceId = captor.getValue() + assertNotNull(sliceServiceInstanceId) + } + + @Test + void testUpdateServiceInstance() { + when(mockExecution.getVariable("sliceServiceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be") + when(mockExecution.getVariable("sliceServiceInstanceName")).thenReturn("5G-service") + when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer") + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G") + when(mockExecution.getVariable("sliceProfileId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2b1") + when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71") + when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6") + when(mockExecution.getVariable("sliceProfile")).thenReturn(mockSliceProfile()) + + AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5GCustomer", "5G", "5ad89cf9-0569-4a93-9306-d8324321e2be") + DoModifyTnNssi obj = spy(DoModifyTnNssi.class) + when(obj.getAAIClient()).thenReturn(client) + + obj.updateServiceInstance(mockExecution) + } + + + private String mockSliceParams() { + String expect = """{ + "sliceProfile": { + "snssaiList": [ + "001-100001" + ], + "sliceProfileId": "ab9af40f13f721b5f13539d87484098", + "plmnIdList": [ + "460-00", + "460-01" + ], + "perfReq": { + }, + "coverageAreaTAList": [ + ], + "latency": 2, + "maxBandwidth": 100, + "resourceSharingLevel": "non-shared" + }, + "transportSliceNetworks": [ + { + "connectionLinks": [ + { + "transportEndpointA": "tranportEp_ID_XXX", + "transportEndpointB": "tranportEp_ID_YYY" + }, + { + "transportEndpointA": "tranportEp_ID_AAA", + "transportEndpointB": "tranportEp_ID_BBB" + } + ] + }, + { + "connectionLinks": [ + { + "transportEndpointA": "tranportEp_ID_CCC", + "transportEndpointB": "tranportEp_ID_DDD" + }, + { + "transportEndpointA": "tranportEp_ID_EEE", + "transportEndpointB": "tranportEp_ID_FFF" + } + ] + } + ], + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + "scriptName": "AN1" + }""" + return expect.replaceAll("\\\\s+", "") + } + + private String mockSliceProfile() { + String expect = """{ + "snssaiList": [ + "001-100001" + ], + "sliceProfileId": "ab9af40f13f721b5f13539d87484098", + "plmnIdList": [ + "460-00", + "460-01" + ], + "perfReq": { + }, + "coverageAreaTAList": [ + ], + "latency": 2, + "maxBandwidth": 100, + "resourceSharingLevel": "non-shared" + }""" + return expect.replaceAll("\\\\s+", "") + } + + private String mockServiceModelInfo() { + String expect = """{ + "modelInvariantUuid":"f85cbcc0-ad74-45d7-a5a1-17c8744fdb71", + "modelUuid":"36a3a8ea-49a6-4ac8-b06c-89a54544b9b6", + "modelVersion":"" + }""" + return expect.replaceAll("\\\\s+", "") + } +} |