2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 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 static org.mockito.Mockito.*
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.ProcessEngineServices
27 import org.camunda.bpm.engine.RepositoryService
28 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
29 import org.camunda.bpm.engine.repository.ProcessDefinition
30 import org.camunda.bpm.engine.runtime.Execution
31 import org.junit.Before
34 import org.junit.runner.RunWith
35 import org.mockito.MockitoAnnotations
36 import org.mockito.runners.MockitoJUnitRunner
37 import org.onap.so.bpmn.common.scripts.MsoUtils
38 import org.onap.so.bpmn.core.WorkflowException
39 import org.onap.so.bpmn.common.scripts.ExceptionUtil
42 import com.github.tomakehurst.wiremock.junit.WireMockRule
44 @RunWith(MockitoJUnitRunner.class)
45 class SacleCustomE2EServiceInstanceTest{
47 public WireMockRule wireMockRule = new WireMockRule(8090);
49 String Prefix="CRESI_"
50 ExceptionUtil exceptionUtil = new ExceptionUtil()
51 String globalSubscriberId="test_custormer"
52 String requestDescription = "request description for test"
53 def utils = new MsoUtils()
55 String jsonIncomingRequest = """{"service":{
56 "serviceType":"example-service-type",
57 "globalSubscriberId":"test_custormer",
60 "resourceInstanceId":"ns111",
61 "scaleType":"SCALE_NS",
63 "scaleNsByStepsData":{
65 "aspectId":"TIC_EDGE_HW",
66 "scalingDirection":"UP"
71 "resourceInstanceId":"ns333",
72 "scaleType":"SCALE_NS",
74 "scaleNsByStepsData":{
76 "aspectId":"TIC_EDGE_HW",
77 "scalingDirection":"UP"
81 "serviceInstanceName":"XXXX"
83 "operationId":"0a5b1651-c56e-4263-8c26-c8f8a6ef72d8"
86 String xmlMsoCompletionRequest = """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
87 xmlns:ns="http://org.onap/so/request/types/v1"
88 xmlns:w1aaan0="http://org.onap/so/infra/vnf-request/v1">
89 <w1aaan0:request-info>
90 <w1aaan0:request-id>56c881ad-6c9d-4b79-aacc-401e5640b47f</w1aaan0:request-id>
91 <w1aaan0:action>SCALE</w1aaan0:action>
92 <w1aaan0:source>null</w1aaan0:source>
93 </w1aaan0:request-info>
94 <status-message>Service Instance was scaled successfully.</status-message>
95 <serviceInstanceId>56c881ad-6c9d-4b79-aacc-401e5640b47f</serviceInstanceId>
96 <mso-bpel-name>ScaleGenericALaCarteServiceInstance</mso-bpel-name>
97 </aetgt:MsoCompletionRequest>"""
99 String requestInfo = """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
100 <request-id>56c881ad-6c9d-4b79-aacc-401e5640b47f</request-id>
101 <action>SCALE</action>
102 <source>null</source>
105 String payload ="""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
106 xmlns:ns="http://org.onap.so/requestsdb">
109 <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
110 <serviceId>56c881ad-6c9d-4b79-aacc-401e5640b47f</serviceId>
111 <operationId>0a5b1651-c56e-4263-8c26-c8f8a6ef72d8</operationId>
112 <operationType>SCALE</operationType>
114 <result>processing</result>
115 <operationContent>Prepare service scaling</operationContent>
116 <progress>0</progress>
118 </ns:updateServiceOperationStatus>
120 </soapenv:Envelope>"""
125 MockitoAnnotations.initMocks(this)
129 public void preProcessRequestTest() {
130 println "************ preProcessRequest_Payload ************* "
131 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
133 // Initialize prerequisite variables
134 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
135 when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
137 when(mockExecution.getVariable("mso-request-id")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
138 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
140 ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
141 scaleCustomE2EServiceInstance.preProcessRequest(mockExecution)
143 verify(mockExecution).setVariable("globalSubscriberId", globalSubscriberId)
144 verify(mockExecution).setVariable("prefix", Prefix)
145 verify(mockExecution).setVariable("requestDescription", requestDescription)
149 public void sendSyncResponseTest() {
150 println "************ sendSyncResponse ************* "
151 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
153 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
154 when(mockExecution.getVariable("operationId")).thenReturn("3338b250-e995-4782-8936-081b66ba4dbf")
155 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
157 ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
158 scaleCustomE2EServiceInstance.sendSyncResponse(mockExecution)
160 verify(mockExecution).setVariable("sentSyncResponse", true)
164 public void prepareCompletionRequestTest() {
165 println "************ prepareCompletionRequest ************* "
166 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
168 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
169 when(mockExecution.getVariable("msoRequestId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
170 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
172 ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
173 scaleCustomE2EServiceInstance.prepareCompletionRequest(mockExecution)
175 verify(mockExecution).setVariable("CompleteMsoProcessRequest", xmlMsoCompletionRequest)
180 public void prepareInitServiceOperationStatusTest() {
181 println "************ prepareInitServiceOperationStatus ************* "
182 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
184 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
185 //when(mockExecution.getVariable("serviceInstanceName")).thenReturn("XXXX")
186 when(mockExecution.getVariable("operationId")).thenReturn("0a5b1651-c56e-4263-8c26-c8f8a6ef72d8")
188 ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
189 scaleCustomE2EServiceInstance.prepareInitServiceOperationStatus(mockExecution)
191 payload = utils.formatXml(payload)
192 verify(mockExecution).setVariable("CVFMI_updateServiceOperStatusRequest", payload)