Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / groovy / org / openecomp / mso / bpmn / vcpe / scripts / DoCreateAllottedResourceTXCTest.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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 package org.openecomp.mso.bpmn.vcpe.scripts
21
22
23 import org.camunda.bpm.engine.ProcessEngineServices
24 import org.camunda.bpm.engine.RepositoryService
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.camunda.bpm.engine.repository.ProcessDefinition
27 import org.junit.Before
28 import org.junit.BeforeClass
29 import org.junit.Rule
30 import org.junit.Test
31 import org.junit.Ignore
32 import org.mockito.MockitoAnnotations
33 import org.camunda.bpm.engine.delegate.BpmnError
34 import org.openecomp.mso.bpmn.core.WorkflowException
35 import org.openecomp.mso.bpmn.mock.FileUtil
36
37 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
38 import static com.github.tomakehurst.wiremock.client.WireMock.put
39 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor
40 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching
41 import static org.junit.Assert.*;
42 import static org.mockito.Mockito.*
43 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource
44 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchAllottedResource
45 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutAllottedResource
46 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutAllottedResource_500
47
48 import java.util.Map
49
50 import org.openecomp.mso.bpmn.core.RollbackData
51 import org.openecomp.mso.bpmn.vcpe.scripts.MapSetter
52
53 import com.github.tomakehurst.wiremock.junit.WireMockRule
54
55 class DoCreateAllottedResourceTXCTest extends GroovyTestBase {
56         
57         @Rule
58         public WireMockRule wireMockRule = new WireMockRule(PORT)
59
60         String Prefix = "DCARTXC_"
61
62         @BeforeClass
63         public static void setUpBeforeClass() {
64                 // nothing for now
65         }
66           
67     @Before
68         public void init()
69         {
70                 MockitoAnnotations.initMocks(this)
71         }
72         
73         public DoCreateAllottedResourceTXCTest() {
74                 super("DoCreateAllottedResourceTXC")
75         }
76         
77         
78         // ***** preProcessRequest *****
79                         
80         @Test
81         // @Ignore  
82         public void preProcessRequest() {
83                 ExecutionEntity mex = setupMock()
84                 initPreProcess(mex)
85                 
86                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
87                 DoCreateAllottedResourceTXC.preProcessRequest(mex)
88
89                 verify(mex).getVariable(DBGFLAG)
90                 verify(mex).setVariable("prefix", Prefix)
91                                 
92                 assertTrue(checkMissingPreProcessRequest("URN_mso_workflow_sdncadapter_callback"))
93                 assertTrue(checkMissingPreProcessRequest("URN_mso_workflow_sdnc_replication_delay"))
94                 assertTrue(checkMissingPreProcessRequest("serviceInstanceId"))
95                 assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId"))
96                 assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo"))
97                 assertTrue(checkMissingPreProcessRequest("brgWanMacAddress"))
98                 assertTrue(checkMissingPreProcessRequest("allottedResourceRole"))
99                 assertTrue(checkMissingPreProcessRequest("allottedResourceType"))
100         }
101         
102         
103         // ***** getAaiAR *****
104         
105         @Test
106         // @Ignore
107         public void getAaiAR() {
108                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml")
109                 
110                 ExecutionEntity mex = setupMock()
111                 initGetAaiAR(mex)
112                 
113                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
114                 DoCreateAllottedResourceTXC.getAaiAR(mex)
115                 
116                 verify(mex).setVariable("foundActiveAR", true)
117         }
118         
119         @Test
120         // @Ignore
121         public void getAaiAR_Duplicate() {
122                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml")
123                 
124                 ExecutionEntity mex = setupMock()
125                 initGetAaiAR(mex)
126                 
127                 // fail if duplicate
128                 when(mex.getVariable("failExists")).thenReturn("true")
129                 
130                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
131                 
132                 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXC.getAaiAR(mex) }))
133         }
134         
135         @Test
136         // @Ignore
137         public void getAaiAR_NotActive() {
138                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml")
139                 
140                 ExecutionEntity mex = setupMock()
141                 initGetAaiAR(mex)
142                 
143                 // not active
144                 when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active")
145                 
146                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
147                 
148                 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceTXC.getAaiAR(mex) }))
149         }
150         
151         @Test
152         // @Ignore
153         public void getAaiAR_NoStatus() {
154                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXC/getArTxc.xml")
155                 
156                 ExecutionEntity mex = setupMock()
157                 initGetAaiAR(mex)
158                 
159                 when(mex.getVariable("aaiAROrchStatus")).thenReturn(null)
160                 
161                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
162                 DoCreateAllottedResourceTXC.getAaiAR(mex)
163                 
164                 verify(mex, never()).setVariable("foundActiveAR", true)
165         }
166         
167         
168         // ***** createAaiAR *****
169         
170         @Test
171         // @Ignore
172         public void createAaiAR() {
173                 ExecutionEntity mex = setupMock()
174                 def map = setupMap(mex)
175                 initCreateAaiAr(mex)
176                 
177                 MockPutAllottedResource(CUST, SVC, INST, ARID)
178                 
179                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
180                 DoCreateAllottedResourceTXC.createAaiAR(mex)
181                 
182                 def data = map.get("rollbackData")
183                 assertNotNull(data)
184                 assertTrue(data instanceof RollbackData)
185                 
186                 assertEquals("45", data.get(Prefix, "disableRollback"))
187                 assertEquals("true", data.get(Prefix, "rollbackAAI"))
188                 assertEquals(ARID, data.get(Prefix, "allottedResourceId"))
189                 assertEquals("sii", data.get(Prefix, "serviceInstanceId"))
190                 assertEquals("psii", data.get(Prefix, "parentServiceInstanceId"))
191                 assertEquals(mex.getVariable("PSI_resourceLink")+"/allotted-resources/allotted-resource/"+ARID, data.get(Prefix, "aaiARPath"))
192         }
193         
194         @Test
195         // @Ignore
196         public void createAaiAR_NoArid_NoModelUuids() {
197                 ExecutionEntity mex = setupMock()
198                 def map = setupMap(mex)
199                 initCreateAaiAr(mex)
200                         
201                 // no allottedResourceId - will be generated
202                 
203                 when(mex.getVariable("allottedResourceId")).thenReturn(null)
204                 
205                 wireMockRule
206                         .stubFor(put(urlMatching("/aai/.*/allotted-resource/.*"))
207                                         .willReturn(aResponse()
208                                                 .withStatus(200)))
209                 
210                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
211                 DoCreateAllottedResourceTXC.createAaiAR(mex)
212                 
213                 def arid = map.get("allottedResourceId")
214                 assertNotNull(arid)
215                 assertFalse(arid.isEmpty())
216                 
217                 def data = map.get("rollbackData")
218                 assertNotNull(data)
219                 assertTrue(data instanceof RollbackData)
220                 
221                 assertEquals(arid, data.get(Prefix, "allottedResourceId"))
222         }
223         
224         @Test
225         // @Ignore
226         public void createAaiAR_MissingPsiLink() {
227                 ExecutionEntity mex = setupMock()
228                 initCreateAaiAr(mex)
229                 
230                 when(mex.getVariable("PSI_resourceLink")).thenReturn(null)
231                 
232                 MockPutAllottedResource(CUST, SVC, INST, ARID)
233                 
234                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
235                 
236                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) }))
237         }
238         
239         @Test
240         // @Ignore
241         public void createAaiAR_HttpFailed() {
242                 ExecutionEntity mex = setupMock()
243                 initCreateAaiAr(mex)
244                 
245                 MockPutAllottedResource_500(CUST, SVC, INST, ARID)
246                 
247                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
248                 
249                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) }))
250         }
251         
252         @Test
253         // @Ignore
254         public void createAaiAR_BpmnError() {
255                 ExecutionEntity mex = setupMock()
256                 initCreateAaiAr(mex)
257                 
258                 when(mex.getVariable("URN_aai_endpoint")).thenThrow(new BpmnError("expected exception"))
259                 
260                 MockPutAllottedResource(CUST, SVC, INST, ARID)
261                 
262                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
263                 
264                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) }))
265         }
266         
267         @Test
268         // @Ignore
269         public void createAaiAR_Ex() {
270                 ExecutionEntity mex = setupMock()
271                 initCreateAaiAr(mex)
272                 
273                 when(mex.getVariable("URN_aai_endpoint")).thenThrow(new RuntimeException("expected exception"))
274                 
275                 MockPutAllottedResource(CUST, SVC, INST, ARID)
276                 
277                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
278                 
279                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.createAaiAR(mex) }))
280         }
281         
282         
283         // ***** buildSDNCRequest *****
284         
285         @Test
286         // @Ignore
287         public void buildSDNCRequest() {
288                 ExecutionEntity mex = setupMock()
289                 initBuildSDNCRequest(mex)
290                 
291                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
292                 
293                 String result = DoCreateAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq")
294                 
295                 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
296                 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
297                 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
298                 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
299                 assertTrue(result.indexOf("<service-instance-id>sii</") >= 0)
300                 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
301                 assertTrue(result.indexOf("<subscription-service-type>sst</") >= 0)
302                 assertTrue(result.indexOf("<global-customer-id>gci</") >= 0)
303                 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
304                 assertTrue(result.indexOf("<request-id>mri</") >= 0)
305                 assertTrue(result.indexOf("<model-invariant-uuid/>") >= 0)
306                 assertTrue(result.indexOf("<model-uuid/>") >= 0)
307                 assertTrue(result.indexOf("<model-customization-uuid/>") >= 0)
308                 assertTrue(result.indexOf("<model-version/>") >= 0)
309                 assertTrue(result.indexOf("<model-name/>") >= 0)
310         }
311         
312         @Test
313         // @Ignore
314         public void buildSDNCRequest_Ex() {
315                 ExecutionEntity mex = setupMock()
316                 initBuildSDNCRequest(mex)
317                 
318                 when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception"))
319                 
320                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
321                 
322                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") }))
323         }
324         
325         
326         // ***** preProcessSDNCAssign *****
327         
328         @Test
329         // @Ignore
330         public void preProcessSDNCAssign() {
331                 ExecutionEntity mex = setupMock()
332                 def map = setupMap(mex)
333                 def data = initPreProcessSDNC(mex)
334                                         
335                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
336                 DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex)
337                 
338                 def req = map.get("sdncAssignRequest")
339                 assertNotNull(req)
340                 
341                 assertEquals(data, map.get("rollbackData"))
342                 
343                 def rbreq = data.get(Prefix, "sdncAssignRollbackReq")
344                 
345                 assertTrue(req.indexOf("<sdncadapter:SvcAction>assign</") >= 0)
346                 assertTrue(req.indexOf("<request-action>CreateTunnelXConnInstance</") >= 0)
347                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
348                 
349                 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>unassign</") >= 0)
350                 assertTrue(rbreq.indexOf("<request-action>DeleteTunnelXConnInstance</") >= 0)
351                 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
352         }
353         
354         @Test
355         // @Ignore
356         public void preProcessSDNCAssign_BpmnError() {
357                 ExecutionEntity mex = setupMock()
358                 initPreProcessSDNC(mex)
359                 
360                 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
361                                         
362                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
363                 
364                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) }))
365         }
366         
367         @Test
368         // @Ignore
369         public void preProcessSDNCAssign_Ex() {
370                 ExecutionEntity mex = setupMock()
371                 initPreProcessSDNC(mex)
372                 
373                 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
374                                         
375                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
376                 
377                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) }))
378         }
379         
380         
381         // ***** preProcessSDNCCreate *****
382         
383         @Test
384         // @Ignore
385         public void preProcessSDNCCreate() {
386                 ExecutionEntity mex = setupMock()
387                 def map = setupMap(mex)
388                 def data = initPreProcessSDNC(mex)
389                                         
390                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
391                 DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex)
392                 
393                 def req = map.get("sdncCreateRequest")
394                 assertNotNull(req)
395                 
396                 assertEquals(data, map.get("rollbackData"))
397                 
398                 def rbreq = data.get(Prefix, "sdncCreateRollbackReq")
399                 
400                 assertTrue(req.indexOf("<sdncadapter:SvcAction>create</") >= 0)
401                 assertTrue(req.indexOf("<request-action>CreateTunnelXConnInstance</") >= 0)
402                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
403                 
404                 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>delete</") >= 0)
405                 assertTrue(rbreq.indexOf("<request-action>DeleteTunnelXConnInstance</") >= 0)
406                 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
407                 
408         }
409         
410         @Test
411         // @Ignore
412         public void preProcessSDNCCreate_BpmnError() {
413                 ExecutionEntity mex = setupMock()
414                 initPreProcessSDNC(mex)
415                 
416                 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
417                                         
418                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
419                 
420                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) }))
421         }
422         
423         @Test
424         // @Ignore
425         public void preProcessSDNCCreate_Ex() {
426                 ExecutionEntity mex = setupMock()
427                 initPreProcessSDNC(mex)
428                 
429                 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
430                                         
431                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
432                 
433                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) }))
434         }
435         
436         
437         // ***** preProcessSDNCActivate *****
438         
439         @Test
440         // @Ignore
441         public void preProcessSDNCActivate() {
442                 ExecutionEntity mex = setupMock()
443                 def map = setupMap(mex)
444                 def data = initPreProcessSDNC(mex)
445                                         
446                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
447                 DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex)
448                 
449                 def req = map.get("sdncActivateRequest")
450                 assertNotNull(req)
451                 
452                 assertEquals(data, map.get("rollbackData"))
453                 
454                 def rbreq = data.get(Prefix, "sdncActivateRollbackReq")
455                 
456                 assertTrue(req.indexOf("<sdncadapter:SvcAction>activate</") >= 0)
457                 assertTrue(req.indexOf("<request-action>CreateTunnelXConnInstance</") >= 0)
458                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
459                 
460                 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>deactivate</") >= 0)
461                 assertTrue(rbreq.indexOf("<request-action>DeleteTunnelXConnInstance</") >= 0)
462                 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
463                 
464         }
465         
466         @Test
467         // @Ignore
468         public void preProcessSDNCActivate_BpmnError() {
469                 ExecutionEntity mex = setupMock()
470                 initPreProcessSDNC(mex)
471                 
472                 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
473                                         
474                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
475                 
476                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) }))
477         }
478         
479         @Test
480         // @Ignore
481         public void preProcessSDNCActivate_Ex() {
482                 ExecutionEntity mex = setupMock()
483                 initPreProcessSDNC(mex)
484                 
485                 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
486                                         
487                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
488                 
489                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) }))
490         }
491         
492         
493         // ***** validateSDNCResp *****
494         
495         @Test
496         // @Ignore
497         public void validateSDNCResp() {
498                 ExecutionEntity mex = setupMock()
499                 def map = setupMap(mex)
500                 def data = initValidateSDNCResp(mex)
501                 def resp = initValidateSDNCResp_Resp()
502                 
503                 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
504                 
505                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
506                 
507                 DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create")
508                 
509                 verify(mex).getVariable("WorkflowException")
510                 verify(mex).getVariable("SDNCA_SuccessIndicator")
511                 verify(mex).getVariable("rollbackData")
512                 
513                 assertEquals(data, map.get("rollbackData"))
514                 
515                 assertEquals("true", data.get(Prefix, "rollback" +  "SDNCcreate"))
516                 
517         }
518         
519         @Test
520         // @Ignore
521         public void validateSDNCResp_Get() {
522                 ExecutionEntity mex = setupMock()
523                 def data = initValidateSDNCResp(mex)
524                 def resp = initValidateSDNCResp_Resp()
525                 
526                 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
527                 
528                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
529                 
530                 DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "get")
531                 
532                 verify(mex).getVariable("WorkflowException")
533                 verify(mex).getVariable("SDNCA_SuccessIndicator")
534                 
535                 verify(mex, never()).getVariable("rollbackData")
536         }
537         
538         @Test
539         // @Ignore
540         public void validateSDNCResp_Unsuccessful() {
541                 ExecutionEntity mex = setupMock()
542                 initValidateSDNCResp(mex)
543                 def resp = initValidateSDNCResp_Resp()
544                 
545                 // unsuccessful
546                 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false)
547                 
548                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
549                 
550                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") }))
551         }
552         
553         @Test
554         // @Ignore
555         public void validateSDNCResp_BpmnError() {
556                 ExecutionEntity mex = setupMock()
557                 initValidateSDNCResp(mex)
558                 def resp = initValidateSDNCResp_Resp()
559                 
560                 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
561                 
562                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
563                 
564                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") }))
565         }
566         
567         @Test
568         // @Ignore
569         public void validateSDNCResp_Ex() {
570                 ExecutionEntity mex = setupMock()
571                 initValidateSDNCResp(mex)
572                 def resp = initValidateSDNCResp_Resp()
573                 
574                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
575                 
576                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
577                 
578                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") }))
579         }
580         
581         
582         // ***** preProcessSDNCGet *****
583         
584         @Test
585         // @Ignore
586         public void preProcessSDNCGet_FoundAR() {
587                 ExecutionEntity mex = setupMock()
588                 def map = setupMap(mex)
589                 initPreProcessSDNCGet(mex)
590                                         
591                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
592                 DoCreateAllottedResourceTXC.preProcessSDNCGet(mex)
593                 
594                 String req = map.get("sdncGetRequest")
595                 
596                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
597                 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
598                 assertTrue(req.indexOf("<sdncadapter:SvcOperation>arlink</") >= 0)
599                 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
600                 
601         }
602         
603         @Test
604         // @Ignore
605         public void preProcessSDNCGet_NotFoundAR() {
606                 ExecutionEntity mex = setupMock()
607                 def map = setupMap(mex)
608                 initPreProcessSDNCGet(mex)
609                 
610                 when(mex.getVariable("foundActiveAR")).thenReturn(false)
611                                         
612                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
613                 DoCreateAllottedResourceTXC.preProcessSDNCGet(mex)
614                 
615                 String req = map.get("sdncGetRequest")
616                 
617                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
618                 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
619                 assertTrue(req.indexOf("<sdncadapter:SvcOperation>assignlink</") >= 0)
620                 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
621                 
622         }
623         
624         @Test
625         // @Ignore
626         public void preProcessSDNCGet_Ex() {
627                 ExecutionEntity mex = setupMock()
628                 initPreProcessSDNCGet(mex)
629                 
630                 when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception"))
631                 
632                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
633                 
634                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCGet(mex) }))
635         }
636         
637         
638         // ***** updateAaiAROrchStatus *****
639         
640         @Test
641         // @Ignore
642         public void updateAaiAROrchStatus() {
643                 MockPatchAllottedResource(CUST, SVC, INST, ARID)
644                 
645                 ExecutionEntity mex = setupMock()
646                 initUpdateAaiAROrchStatus(mex)
647                                         
648                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
649                 DoCreateAllottedResourceTXC.updateAaiAROrchStatus(mex, "success")
650         }
651         
652         
653         // ***** generateOutputs *****
654         
655         @Test
656         // @Ignore
657         public void generateOutputs() {
658                 ExecutionEntity mex = setupMock()
659                 def txctop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/SDNCTopologyQueryCallback.xml")
660                 
661                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
662                 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(txctop)
663                 
664                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
665                 DoCreateAllottedResourceTXC.generateOutputs(mex)
666                 
667                 verify(mex).setVariable("allotedResourceName", "namefromrequest")
668                 verify(mex).setVariable("vni", "my-vni")
669                 verify(mex).setVariable("vgmuxBearerIP", "my-bearer-ip")
670                 verify(mex).setVariable("vgmuxLanIP", "my-lan-ip")
671                 
672         }
673         
674         @Test
675         // @Ignore
676         public void generateOutputs_BadXml() {
677                 ExecutionEntity mex = setupMock()
678                 
679                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
680                 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml")
681                 
682                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
683                 DoCreateAllottedResourceTXC.generateOutputs(mex)
684                 
685                 verify(mex, never()).setVariable(anyString(), anyString())
686                 
687         }
688         
689         @Test
690         // @Ignore
691         public void generateOutputs_BpmnError() {
692                 ExecutionEntity mex = setupMock()
693                 
694                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
695                 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception"))
696                 
697                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
698                 
699                 DoCreateAllottedResourceTXC.generateOutputs(mex)
700                 verify(mex, never()).setVariable(anyString(), anyString())
701                 
702         }
703         
704         @Test
705         // @Ignore
706         public void generateOutputs_Ex() {
707                 ExecutionEntity mex = setupMock()
708                 
709                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
710                 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception"))
711                 
712                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
713                 
714                 DoCreateAllottedResourceTXC.generateOutputs(mex)
715                 verify(mex, never()).setVariable(anyString(), anyString())
716                 
717         }
718         
719         
720         // ***** preProcessRollback *****
721         
722         @Test
723         // @Ignore
724         public void preProcessRollback() {
725                 ExecutionEntity mex = setupMock()
726                 WorkflowException wfe = mock(WorkflowException.class)
727                 
728                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
729                 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
730                 
731                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
732                 DoCreateAllottedResourceTXC.preProcessRollback(mex)
733                 
734                 verify(mex).setVariable("prevWorkflowException", wfe)
735                 
736         }
737         
738         @Test
739         // @Ignore
740         public void preProcessRollback_NotWFE() {
741                 ExecutionEntity mex = setupMock()
742                 
743                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
744                 when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE")
745                 
746                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
747                 DoCreateAllottedResourceTXC.preProcessRollback(mex)
748                 
749 //                      verify(mex, never()).setVariable("prevWorkflowException", any())
750                 
751         }
752         
753         @Test
754         // @Ignore
755         public void preProcessRollback_BpmnError() {
756                 ExecutionEntity mex = setupMock()
757                 
758                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
759                 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
760                 
761                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
762                 
763                 DoCreateAllottedResourceTXC.preProcessRollback(mex)
764                 
765         }
766         
767         @Test
768         // @Ignore
769         public void preProcessRollback_Ex() {
770                 ExecutionEntity mex = setupMock()
771                 
772                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
773                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
774                 
775                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
776                 
777                 DoCreateAllottedResourceTXC.preProcessRollback(mex)
778                 
779         }
780         
781         
782         // ***** postProcessRollback *****
783         
784         @Test
785         // @Ignore
786         public void postProcessRollback() {
787                 ExecutionEntity mex = setupMock()
788                 WorkflowException wfe = mock(WorkflowException.class)
789                 
790                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
791                 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
792                 
793                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
794                 DoCreateAllottedResourceTXC.postProcessRollback(mex)
795                 
796                 verify(mex).setVariable("WorkflowException", wfe)
797                 verify(mex).setVariable("rollbackData", null)
798                 
799         }
800         
801         @Test
802         // @Ignore
803         public void postProcessRollback_NotWFE() {
804                 ExecutionEntity mex = setupMock()
805                 
806                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
807                 when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE")
808                 
809                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
810                 DoCreateAllottedResourceTXC.postProcessRollback(mex)
811                 
812 //                      verify(mex, never()).setVariable("WorkflowException", any())
813                 verify(mex).setVariable("rollbackData", null)
814                 
815         }
816         
817         @Test
818         // @Ignore
819         public void postProcessRollback_BpmnError() {
820                 ExecutionEntity mex = setupMock()
821                 
822                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
823                 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
824                 
825                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
826                 
827                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.postProcessRollback(mex) }))
828                 verify(mex, never()).setVariable("rollbackData", null)
829                 
830         }
831         
832         @Test
833         // @Ignore
834         public void postProcessRollback_Ex() {
835                 ExecutionEntity mex = setupMock()
836                 
837                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
838                 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
839                 
840                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
841                 
842                 DoCreateAllottedResourceTXC.postProcessRollback(mex)
843                 verify(mex, never()).setVariable("rollbackData", null)
844                 
845         }
846         
847         private boolean checkMissingPreProcessRequest(String fieldnm) {
848                 ExecutionEntity mex = setupMock()
849                 initPreProcess(mex)
850                                                                 
851                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
852                 
853                 when(mex.getVariable(fieldnm)).thenReturn("")
854                 
855                 return doBpmnError( { _ -> DoCreateAllottedResourceTXC.preProcessRequest(mex) })
856         }
857         
858         private void initPreProcess(ExecutionEntity mex) {
859                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
860                 when(mex.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn("sdncurn")
861                 when(mex.getVariable("URN_mso_workflow_sdnc_replication_delay")).thenReturn("sdncdelay")
862                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
863                 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
864                 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi")
865                 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
866                 when(mex.getVariable("allottedResourceRole")).thenReturn("arr")
867                 when(mex.getVariable("allottedResourceType")).thenReturn("art")
868         }
869         
870         private void initGetAaiAR(ExecutionEntity mex) {
871                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
872                 when(mex.getVariable("allottedResourceType")).thenReturn("TXCt")
873                 when(mex.getVariable("allottedResourceRole")).thenReturn("TXCr")
874                 when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/getAR.xml"))
875                 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
876                 when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
877         }
878         
879         private initCreateAaiAr(ExecutionEntity mex) {                          
880                 when(mex.getVariable("disableRollback")).thenReturn(45)
881                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
882                 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
883                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
884                 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
885                 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
886                 when(mex.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn(urnProps.get("mso.workflow.global.default.aai.namespace"))
887                 when(mex.getVariable("PSI_resourceLink")).thenReturn(aaiUriPfx + "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST)
888                 when(mex.getVariable("allottedResourceType")).thenReturn("TXCt")
889                 when(mex.getVariable("allottedResourceRole")).thenReturn("TXCr")
890                 when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi")
891                 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
892                                 {
893                                         "modelInvariantUuid":"modelinvuuid",
894                                         "modelUuid":"modeluuid",
895                                         "modelCustomizationUuid":"modelcustuuid"
896                                 }
897                         """)
898         }
899         
900         private initBuildSDNCRequest(ExecutionEntity mex) {
901                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
902                 when(mex.getVariable("allottedResourceId")).thenReturn("ari")
903                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
904                 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
905                 when(mex.getVariable("subscriptionServiceType")).thenReturn("sst")
906                 when(mex.getVariable("globalCustomerId")).thenReturn("gci")
907                 when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu")
908                 when(mex.getVariable("msoRequestId")).thenReturn("mri")
909         }
910         
911         private RollbackData initPreProcessSDNC(ExecutionEntity mex) {
912                 def data = new RollbackData()
913                 
914                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
915                 when(mex.getVariable("rollbackData")).thenReturn(data)
916                 
917                 return data
918         }
919         
920         private initPreProcessSDNCGet(ExecutionEntity mex) {
921                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
922                 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
923                 when(mex.getVariable("foundActiveAR")).thenReturn(true)
924                 when(mex.getVariable("aaiARGetResponse")).thenReturn("<selflink>arlink</selflink>")
925                 when(mex.getVariable("sdncAssignResponse")).thenReturn("<response-data>&lt;object-path&gt;assignlink&lt;/object-path&gt;</response-data>")
926                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
927                 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
928         }
929         
930         private RollbackData initValidateSDNCResp(ExecutionEntity mex) {
931                 def data = new RollbackData()
932                 
933                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
934                 when(mex.getVariable("prefix")).thenReturn(Prefix)
935                 when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
936                 when(mex.getVariable("rollbackData")).thenReturn(data)
937                 
938                 return data
939         }
940         
941         private String initValidateSDNCResp_Resp() {
942                 return "<response-data>&lt;response-code&gt;200&lt;/response-code&gt;</response-data>"
943         }
944         
945         private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
946                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
947                 when(mex.getVariable("aaiARPath")).thenReturn(aaiUriPfx + "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID)
948         }
949                 
950 }