Merge 'origin/casablanca' into master
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / CreateSDNCNetworkResourceTest.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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 com.github.tomakehurst.wiremock.junit.WireMockRule
24 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
25 import org.junit.Rule
26 import org.junit.Test
27 import org.mockito.MockitoAnnotations
28 import org.onap.so.bpmn.common.recipe.ResourceInput
29 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
30
31 import static org.mockito.Mockito.*
32 /**
33  * Copyright 2018 ZTE Corporation.
34  *
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
38  *
39  *     http://www.apache.org/licenses/LICENSE-2.0
40  *
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.
46  */
47 class CreateSDNCNetworkResourceTest extends GroovyTestCase {
48
49     @Rule
50     public WireMockRule wireMockRule = new WireMockRule(8090)
51
52     String Prefix = "CRESDNCRES_"
53     String sdncAdapterWorkflowResponse
54
55     void init() {
56         MockitoAnnotations.initMocks(this)
57         sdncAdapterWorkflowResponse = """
58                                                 <sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
59                                                 <sdncadapterworkflow:response-data>
60                             <CallbackHeader>
61                                 <RequestId>726420e0-3962-4bf2-9655-aac82fc7055e</RequestId>
62                                 <ResponseCode>200</ResponseCode>
63                                 <ResponseMessage>OK</ResponseMessage>
64                             </CallbackHeader>
65                             <RequestData xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">&lt;output xmlns="org:onap:sdnc:northbound:generic-resource"&gt;&lt;response-message&gt;&lt;/response-message&gt;&lt;ack-final-indicator&gt;Y&lt;/ack-final-indicator&gt;&lt;svc-request-id&gt;726420e0-3962-4bf2-9655-aac82fc7055e&lt;/svc-request-id&gt;&lt;network-response-information&gt;&lt;instance-id&gt;9fa732b8-2c54-4eba-926d-464d18c07474&lt;/instance-id&gt;&lt;object-path&gt;restconf/config/GENERIC-RESOURCE-API:services/service/a99deffb-12e2-4656-8cf2-2d2a996d0f52/service-data/networks/network/9fa732b8-2c54-4eba-926d-464d18c07474/network-data/&lt;/object-path&gt;&lt;/network-response-information&gt;&lt;response-code&gt;200&lt;/response-code&gt;&lt;service-response-information&gt;&lt;instance-id&gt;a99deffb-12e2-4656-8cf2-2d2a996d0f52&lt;/instance-id&gt;&lt;/service-response-information&gt;&lt;/output&gt;</RequestData>
66                         </sdncadapterworkflow:response-data>
67                                                 </sdncadapterworkflow:SDNCAdapterWorkflowResponse>"""
68
69     }
70
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" +
87                 "\t},\n" +
88                 "\t\"resourceModelInfo\": {\n" +
89                 "\t\t\"modelName\": \"" +
90                 modelName +
91                 "\",\n" +
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" +
98                 "\t},\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" +
104                 "}"
105         ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
106         return resourceInputObj
107     }
108
109     @Test
110     void testAfterCreateSDNCCall() {
111         init()
112         checkGetInstanceId(getResInputObj("SotnFc-wan-connection"))
113         checkGetInstanceId(getResInputObj("SOTNConnectivity"))
114         checkGetInstanceId(getResInputObj("SDWANConnectivity"))
115     }
116
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)
128     }
129
130     private getInstanceId() {
131         def response = new XmlSlurper().parseText(sdncAdapterWorkflowResponse)
132         def instanceId = response."response-data"."RequestData"."output"."network-response-information"."instance-id"
133         return instanceId
134     }
135 }