2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import com.github.tomakehurst.wiremock.junit.WireMockRule
24 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
27 import org.mockito.MockitoAnnotations
28 import org.onap.so.bpmn.common.recipe.ResourceInput
29 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
31 import static org.mockito.Mockito.*
33 * Copyright 2018 ZTE Corporation.
35 * Licensed under the Apache License, Version 2.0 (the "License");
36 * you may not use this file except in compliance with the License.
37 * You may obtain a copy of the License at
39 * http://www.apache.org/licenses/LICENSE-2.0
41 * Unless required by applicable law or agreed to in writing, software
42 * distributed under the License is distributed on an "AS IS" BASIS,
43 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44 * See the License for the specific language governing permissions and
45 * limitations under the License.
47 class CreateSDNCNetworkResourceTest extends GroovyTestCase {
50 public WireMockRule wireMockRule = new WireMockRule(8090)
52 String Prefix = "CRESDNCRES_"
53 String sdncAdapterWorkflowResponse
56 MockitoAnnotations.initMocks(this)
57 sdncAdapterWorkflowResponse = """
58 <sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
59 <sdncadapterworkflow:response-data>
61 <RequestId>726420e0-3962-4bf2-9655-aac82fc7055e</RequestId>
62 <ResponseCode>200</ResponseCode>
63 <ResponseMessage>OK</ResponseMessage>
65 <RequestData xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><output xmlns="org:onap:sdnc:northbound:generic-resource"><response-message></response-message><ack-final-indicator>Y</ack-final-indicator><svc-request-id>726420e0-3962-4bf2-9655-aac82fc7055e</svc-request-id><network-response-information><instance-id>9fa732b8-2c54-4eba-926d-464d18c07474</instance-id><object-path>restconf/config/GENERIC-RESOURCE-API:services/service/a99deffb-12e2-4656-8cf2-2d2a996d0f52/service-data/networks/network/9fa732b8-2c54-4eba-926d-464d18c07474/network-data/</object-path></network-response-information><response-code>200</response-code><service-response-information><instance-id>a99deffb-12e2-4656-8cf2-2d2a996d0f52</instance-id></service-response-information></output></RequestData>
66 </sdncadapterworkflow:response-data>
67 </sdncadapterworkflow:SDNCAdapterWorkflowResponse>"""
71 private ResourceInput getResInputObj(String modelName) {
72 String resourceInput = "{\n" +
73 "\t\"resourceInstanceName\": \"SotnFc-wan-connection_wanconnection-37\",\n" +
74 "\t\"resourceInstanceDes\": null,\n" +
75 "\t\"globalSubscriberId\": \"sdwandemo\",\n" +
76 "\t\"serviceType\": \"CCVPN\",\n" +
77 "\t\"operationId\": \"df3387b5-4fbf-41bd-82a0-13a955ac178a\",\n" +
78 "\t\"serviceModelInfo\": {\n" +
79 "\t\t\"modelName\": \"WanConnectionSvc03\",\n" +
80 "\t\t\"modelUuid\": \"198b066c-0771-4157-9594-1824adfdda7e\",\n" +
81 "\t\t\"modelInvariantUuid\": \"43fb5165-7d03-4009-8951-a8f45d3f0148\",\n" +
82 "\t\t\"modelVersion\": \"1.0\",\n" +
83 "\t\t\"modelCustomizationUuid\": \"\",\n" +
84 "\t\t\"modelCustomizationName\": \"\",\n" +
85 "\t\t\"modelInstanceName\": \"\",\n" +
86 "\t\t\"modelType\": \"\"\n" +
88 "\t\"resourceModelInfo\": {\n" +
89 "\t\t\"modelName\": \"" +
92 "\t\t\"modelUuid\": \"6a0bf88b-343c-415b-88c1-6f73702452c4\",\n" +
93 "\t\t\"modelInvariantUuid\": \"50bc3415-2e01-4e50-a9e1-ec9584599bb3\",\n" +
94 "\t\t\"modelCustomizationUuid\": \"b205d620-84bd-4058-afa0-e3aeee8bb712\",\n" +
95 "\t\t\"modelCustomizationName\": \"\",\n" +
96 "\t\t\"modelInstanceName\": \"SotnFc-wan-connection 0\",\n" +
97 "\t\t\"modelType\": \"\"\n" +
99 "\t\"resourceInstancenUuid\": null,\n" +
100 "\t\"resourceParameters\": \"{\\n\\\"locationConstraints\\\":[],\\n\\\"requestInputs\\\":{\\\"sotnfcspecwanconnection0_route-objective-function\\\":null,\\\"sotnfcspecwanconnection0_colorAware\\\":null,\\\"3rdctlspecwanconnection0_thirdPartyAdaptorRpc\\\":null,\\\"sotnfcspecwanconnection0_couplingFlag\\\":null,\\\"sotnfcspecwanconnection0_pbs\\\":null,\\\"3rdctlspecwanconnection0_thirdPartySdncId\\\":null,\\\"sotnfcspecwanconnection0_cbs\\\":null,\\\"3rdctlspecwanconnection0_thirdpartySdncName\\\":null,\\\"sotnfcspecwanconnection0_total-size\\\":null,\\\"3rdctlspecwanconnection0_templateFileName\\\":\\\"sotn_create_zte_template.json\\\",\\\"fcwanconnection0_type\\\":null,\\\"sotnfcspecwanconnection0_cir\\\":null,\\\"fcwanconnection0_uuid\\\":null,\\\"sotnfcspecwanconnection0_diversity-policy\\\":null,\\\"nf_naming\\\":true,\\\"multi_stage_design\\\":false,\\\"availability_zone_max_count\\\":1,\\\"3rdctlspecwanconnection0_restapiUrl\\\":\\\"http://10.80.80.21:8443/restconf/operations/ZTE-API-ConnectivityService:create-connectivity-service\\\",\\\"max_instances\\\":null,\\\"sotnfcspecwanconnection0_reroute\\\":null,\\\"fcwanconnection0_name\\\":null,\\\"sotnfcspecwanconnection0_dualLink\\\":null,\\\"min_instances\\\":null,\\\"sotnfcspecwanconnection0_pir\\\":null,\\\"sotnfcspecwanconnection0_service-type\\\":null}\\n}\",\n" +
101 "\t\"operationType\": \"createInstance\",\n" +
102 "\t\"serviceInstanceId\": \"ffa07ae4-f820-45af-9439-1416b3bc1d39\",\n" +
103 "\t\"requestsInputs\": \"{\\r\\n\\t\\\"service\\\": {\\r\\n\\t\\t\\\"name\\\": \\\"wanconnection-37\\\",\\r\\n\\t\\t\\\"description\\\": \\\"deafe\\\",\\r\\n\\t\\t\\\"serviceInvariantUuid\\\": \\\"43fb5165-7d03-4009-8951-a8f45d3f0148\\\",\\r\\n\\t\\t\\\"serviceUuid\\\": \\\"198b066c-0771-4157-9594-1824adfdda7e\\\",\\r\\n\\t\\t\\\"globalSubscriberId\\\": \\\"sdwandemo\\\",\\r\\n\\t\\t\\\"serviceType\\\": \\\"CCVPN\\\",\\r\\n\\t\\t\\\"parameters\\\": {\\r\\n\\t\\t\\t\\\"resources\\\": [\\r\\n\\t\\t\\t],\\r\\n\\t\\t\\t\\\"requestInputs\\\": {\\r\\n\\t\\t\\t\\t\\\"sotnfcwanconnection0_3rdctlspecwanconnection0_restapiUrl\\\": \\\"http://10.80.80.21:8443/restconf/operations/ZTE-API-ConnectivityService:create-connectivity-service\\\",\\r\\n\\t\\t\\t\\t\\\"sotnfcwanconnection0_3rdctlspecwanconnection0_templateFileName\\\": \\\"sotn_create_zte_template.json\\\",\\r\\n\\t\\t\\t\\t\\\"sdwanfcwanconnection0_3rdctlspecwanconnection0_restapiUrl\\\": \\\"http://10.80.80.21:8443/restconf/operations/ZTE-API-ConnectivityService:create-connectivity-service\\\",\\r\\n\\t\\t\\t\\t\\\"sdwanfcwanconnection0_3rdctlspecwanconnection0_templateFileName\\\": \\\"sdwan_create_zte_template.json\\\"\\r\\n\\t\\t\\t}\\r\\n\\t\\t}\\r\\n\\t}\\r\\n}\"\n" +
105 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
106 return resourceInputObj
110 void testAfterCreateSDNCCall() {
112 checkGetInstanceId(getResInputObj("SotnFc-wan-connection"))
113 checkGetInstanceId(getResInputObj("SOTNConnectivity"))
114 checkGetInstanceId(getResInputObj("SDWANConnectivity"))
117 private void checkGetInstanceId(ResourceInput input) {
118 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
119 when(mockExecution.getVariable(Prefix + "sdncCreateReturnCode")).thenReturn("200")
120 when(mockExecution.getVariable(Prefix + "SuccessIndicator")).thenReturn("false")
121 when(mockExecution.getVariable("isActivateRequired")).thenReturn("true")
122 when(mockExecution.getVariable("CRENWKI_createSDNCResponse")).thenReturn(sdncAdapterWorkflowResponse)
123 when(mockExecution.getVariable(Prefix + "resourceInput")).thenReturn(input.toString())
124 CreateSDNCNetworkResource createSDNCNetworkResource = new CreateSDNCNetworkResource()
125 createSDNCNetworkResource.afterCreateSDNCCall(mockExecution)
126 def instanceId = getInstanceId()
127 verify(mockExecution).setVariable("networkInstanceId", instanceId)
130 private getInstanceId() {
131 def response = new XmlSlurper().parseText(sdncAdapterWorkflowResponse)
132 def instanceId = response."response-data"."RequestData"."output"."network-response-information"."instance-id"