Merge "Adding Junit"
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / groovy / org / openecomp / mso / bpmn / vcpe / scripts / DoCreateAllottedResourceBRGTest.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 org.openecomp.mso.bpmn.core.RollbackData
49 import org.openecomp.mso.bpmn.vcpe.scripts.MapSetter
50
51 import com.github.tomakehurst.wiremock.junit.WireMockRule
52
53 class DoCreateAllottedResourceBRGTest extends GroovyTestBase {
54         
55         @Rule
56         public WireMockRule wireMockRule = new WireMockRule(PORT)
57
58         String Prefix = "DCARBRG_"
59
60         @BeforeClass
61         public static void setUpBeforeClass() {
62                 // nothing for now
63         }
64           
65     @Before
66         public void init()
67         {
68                 MockitoAnnotations.initMocks(this)
69         }
70         
71         public DoCreateAllottedResourceBRGTest() {
72                 super("DoCreateAllottedResourceBRG")
73         }
74         
75         
76         // ***** preProcessRequest *****
77                         
78         @Test
79 //      @Ignore  
80         public void preProcessRequest() {
81                 ExecutionEntity mex = setupMock()
82                 initPreProcess(mex)
83                 
84                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
85                 DoCreateAllottedResourceBRG.preProcessRequest(mex)
86
87                 verify(mex).getVariable(DBGFLAG)
88                 verify(mex).setVariable("prefix", Prefix)
89                                 
90                 assertTrue(checkMissingPreProcessRequest("URN_mso_workflow_sdncadapter_callback"))
91                 assertTrue(checkMissingPreProcessRequest("URN_mso_workflow_sdnc_replication_delay"))
92                 assertTrue(checkMissingPreProcessRequest("serviceInstanceId"))
93                 assertTrue(checkMissingPreProcessRequest("parentServiceInstanceId"))
94                 assertTrue(checkMissingPreProcessRequest("allottedResourceModelInfo"))
95                 assertTrue(checkMissingPreProcessRequest("vni"))
96                 assertTrue(checkMissingPreProcessRequest("vgmuxBearerIP"))
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/DoCreateAllottedResourceBRG/getArBrg.xml")
109                 
110                 ExecutionEntity mex = setupMock()
111                 initGetAaiAR(mex)
112                                 
113                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
114                 DoCreateAllottedResourceBRG.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/DoCreateAllottedResourceBRG/getArBrg.xml")
123                 
124                 ExecutionEntity mex = setupMock()
125                 initGetAaiAR(mex)
126                 
127                 // fail if duplicate
128                 when(mex.getVariable("failExists")).thenReturn("true")
129                 
130                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
131                 
132                 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) }))
133         }
134         
135         @Test
136 //      @Ignore
137         public void getAaiAR_NotActive() {
138                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
139                 
140                 ExecutionEntity mex = setupMock()
141                 initGetAaiAR(mex)
142                 
143                 // not active
144                 when(mex.getVariable("aaiAROrchStatus")).thenReturn("not-active")
145                 
146                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
147                 
148                 assertTrue(doBpmnError( { _ -> DoCreateAllottedResourceBRG.getAaiAR(mex) }))
149         }
150         
151         @Test
152 //      @Ignore
153         public void getAaiAR_NoStatus() {
154                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceBRG/getArBrg.xml")
155                 
156                 ExecutionEntity mex = setupMock()
157                 initGetAaiAR(mex)
158                 
159                 when(mex.getVariable("aaiAROrchStatus")).thenReturn(null)
160                 
161                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
162                 DoCreateAllottedResourceBRG.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                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
180                 DoCreateAllottedResourceBRG.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                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
211                 DoCreateAllottedResourceBRG.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                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
235                 
236                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.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                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
248                 
249                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.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                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
263                 
264                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.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                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
278                 
279                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.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                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
292                 
293                 String result = DoCreateAllottedResourceBRG.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("<brg-wan-mac-address>bwma</") >= 0)
306                 assertTrue(result.indexOf("<vni>myvni</") >= 0)
307                 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
308                 assertTrue(result.indexOf("<model-invariant-uuid>miu</") >= 0)
309                 assertTrue(result.indexOf("<model-uuid>mu</") >= 0)
310                 assertTrue(result.indexOf("<model-customization-uuid>mcu</") >= 0)
311                 assertTrue(result.indexOf("<model-version>mv</") >= 0)
312                 assertTrue(result.indexOf("<model-name>mn</") >= 0)
313         }
314         
315         @Test
316 //      @Ignore
317         public void buildSDNCRequest_EmptyModelInfo() {
318                 ExecutionEntity mex = setupMock()
319                 initBuildSDNCRequest(mex)
320                 
321                 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("{}")
322                 
323                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
324                 
325                 String result = DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq")
326                 
327                 assertTrue(result.indexOf("<sdncadapter:RequestId>myreq</") >= 0)
328                 assertTrue(result.indexOf("<sdncadapter:SvcAction>myact</") >= 0)
329                 assertTrue(result.indexOf("<allotted-resource-id>ari</") >= 0)
330                 assertTrue(result.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
331                 assertTrue(result.indexOf("<service-instance-id>sii</") >= 0)
332                 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
333                 assertTrue(result.indexOf("<subscription-service-type>sst</") >= 0)
334                 assertTrue(result.indexOf("<global-customer-id>gci</") >= 0)
335                 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
336                 assertTrue(result.indexOf("<request-id>mri</") >= 0)
337                 assertTrue(result.indexOf("<brg-wan-mac-address>bwma</") >= 0)
338                 assertTrue(result.indexOf("<vni>myvni</") >= 0)
339                 assertTrue(result.indexOf("<vgmux-bearer-ip>vbi</") >= 0)
340                 assertTrue(result.indexOf("<model-invariant-uuid/>") >= 0)
341                 assertTrue(result.indexOf("<model-uuid/>") >= 0)
342                 assertTrue(result.indexOf("<model-customization-uuid/>") >= 0)
343                 assertTrue(result.indexOf("<model-version/>") >= 0)
344                 assertTrue(result.indexOf("<model-name/>") >= 0)
345         }
346         
347         @Test
348 //      @Ignore
349         public void buildSDNCRequest_Ex() {
350                 ExecutionEntity mex = setupMock()
351                 initBuildSDNCRequest(mex)
352                 
353                 when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception"))
354                 
355                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
356                 
357                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.buildSDNCRequest(mex, "myact", "myreq") }))
358         }
359         
360         
361         // ***** preProcessSDNCAssign *****
362         
363         @Test
364 //      @Ignore
365         public void preProcessSDNCAssign() {
366                 ExecutionEntity mex = setupMock()
367                 def map = setupMap(mex)
368                 def data = initPreProcessSDNC(mex)
369                                         
370                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
371                 DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex)
372                 
373                 def req = map.get("sdncAssignRequest")
374                 assertNotNull(req)
375                 
376                 assertEquals(data, map.get("rollbackData"))
377                 
378                 def rbreq = data.get(Prefix, "sdncAssignRollbackReq")
379                 
380                 assertTrue(req.indexOf("<sdncadapter:SvcAction>assign</") >= 0)
381                 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
382                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
383                 
384                 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>unassign</") >= 0)
385                 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
386                 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
387         }
388         
389         @Test
390 //      @Ignore
391         public void preProcessSDNCAssign_BpmnError() {
392                 ExecutionEntity mex = setupMock()
393                 initPreProcessSDNC(mex)
394                 
395                 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
396                                         
397                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
398                 
399                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
400         }
401         
402         @Test
403 //      @Ignore
404         public void preProcessSDNCAssign_Ex() {
405                 ExecutionEntity mex = setupMock()
406                 initPreProcessSDNC(mex)
407                 
408                 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
409                                         
410                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
411                 
412                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCAssign(mex) }))
413         }
414         
415         
416         // ***** preProcessSDNCCreate *****
417         
418         @Test
419 //      @Ignore
420         public void preProcessSDNCCreate() {
421                 ExecutionEntity mex = setupMock()
422                 def map = setupMap(mex)
423                 def data = initPreProcessSDNC(mex)
424                                         
425                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
426                 DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex)
427                 
428                 def req = map.get("sdncCreateRequest")
429                 assertNotNull(req)
430                 
431                 assertEquals(data, map.get("rollbackData"))
432                 
433                 def rbreq = data.get(Prefix, "sdncCreateRollbackReq")
434                 
435                 assertTrue(req.indexOf("<sdncadapter:SvcAction>create</") >= 0)
436                 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
437                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
438                 
439                 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>delete</") >= 0)
440                 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
441                 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
442                 
443         }
444         
445         @Test
446 //      @Ignore
447         public void preProcessSDNCCreate_BpmnError() {
448                 ExecutionEntity mex = setupMock()
449                 initPreProcessSDNC(mex)
450                 
451                 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
452                                         
453                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
454                 
455                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
456         }
457         
458         @Test
459 //      @Ignore
460         public void preProcessSDNCCreate_Ex() {
461                 ExecutionEntity mex = setupMock()
462                 initPreProcessSDNC(mex)
463                 
464                 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
465                                         
466                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
467                 
468                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCCreate(mex) }))
469         }
470         
471         
472         // ***** preProcessSDNCActivate *****
473         
474         @Test
475 //      @Ignore
476         public void preProcessSDNCActivate() {
477                 ExecutionEntity mex = setupMock()
478                 def map = setupMap(mex)
479                 def data = initPreProcessSDNC(mex)
480                                         
481                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
482                 DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex)
483                 
484                 def req = map.get("sdncActivateRequest")
485                 assertNotNull(req)
486                 
487                 assertEquals(data, map.get("rollbackData"))
488                 
489                 def rbreq = data.get(Prefix, "sdncActivateRollbackReq")
490                 
491                 assertTrue(req.indexOf("<sdncadapter:SvcAction>activate</") >= 0)
492                 assertTrue(req.indexOf("<request-action>CreateBRGInstance</") >= 0)
493                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
494                 
495                 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>deactivate</") >= 0)
496                 assertTrue(rbreq.indexOf("<request-action>DeleteBRGInstance</") >= 0)
497                 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
498                 
499         }
500         
501         @Test
502 //      @Ignore
503         public void preProcessSDNCActivate_BpmnError() {
504                 ExecutionEntity mex = setupMock()
505                 initPreProcessSDNC(mex)
506                 
507                 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
508                                         
509                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
510                 
511                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
512         }
513         
514         @Test
515 //      @Ignore
516         public void preProcessSDNCActivate_Ex() {
517                 ExecutionEntity mex = setupMock()
518                 initPreProcessSDNC(mex)
519                 
520                 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
521                                         
522                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
523                 
524                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCActivate(mex) }))
525         }
526         
527         
528         // ***** validateSDNCResp *****
529         
530         @Test
531 //      @Ignore
532         public void validateSDNCResp() {
533                 ExecutionEntity mex = setupMock()
534                 def map = setupMap(mex)
535                 def data = initValidateSDNCResp(mex)
536                 def resp = initValidateSDNCResp_Resp()
537                 
538                 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
539                 
540                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
541                 
542                 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create")
543                 
544                 verify(mex).getVariable("WorkflowException")
545                 verify(mex).getVariable("SDNCA_SuccessIndicator")
546                 verify(mex).getVariable("rollbackData")
547                 
548                 assertEquals(data, map.get("rollbackData"))
549                 
550                 assertEquals("true", data.get(Prefix, "rollback" +  "SDNCcreate"))
551                 
552         }
553         
554         @Test
555 //      @Ignore
556         public void validateSDNCResp_Get() {
557                 ExecutionEntity mex = setupMock()
558                 def data = initValidateSDNCResp(mex)
559                 def resp = initValidateSDNCResp_Resp()
560                 
561                 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
562                 
563                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
564                 
565                 DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "get")
566                 
567                 verify(mex).getVariable("WorkflowException")
568                 verify(mex).getVariable("SDNCA_SuccessIndicator")
569                 
570                 verify(mex, never()).getVariable("rollbackData")
571         }
572         
573         @Test
574 //      @Ignore
575         public void validateSDNCResp_Unsuccessful() {
576                 ExecutionEntity mex = setupMock()
577                 initValidateSDNCResp(mex)
578                 def resp = initValidateSDNCResp_Resp()
579                 
580                 // unsuccessful
581                 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false)
582                 
583                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
584                 
585                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
586         }
587         
588         @Test
589 //      @Ignore
590         public void validateSDNCResp_BpmnError() {
591                 ExecutionEntity mex = setupMock()
592                 initValidateSDNCResp(mex)
593                 def resp = initValidateSDNCResp_Resp()
594                 
595                 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
596                 
597                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
598                 
599                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
600         }
601         
602         @Test
603 //      @Ignore
604         public void validateSDNCResp_Ex() {
605                 ExecutionEntity mex = setupMock()
606                 initValidateSDNCResp(mex)
607                 def resp = initValidateSDNCResp_Resp()
608                 
609                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
610                 
611                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
612                 
613                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.validateSDNCResp(mex, resp, "create") }))
614         }
615         
616         
617         // ***** preProcessSDNCGet *****
618         
619         @Test
620 //      @Ignore
621         public void preProcessSDNCGet_FoundAR() {
622                 ExecutionEntity mex = setupMock()
623                 def map = setupMap(mex)
624                 initPreProcessSDNCGet(mex)
625                                         
626                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
627                 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
628                 
629                 String req = map.get("sdncGetRequest")
630                 
631                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
632                 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
633                 assertTrue(req.indexOf("<sdncadapter:SvcOperation>arlink</") >= 0)
634                 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
635                 
636         }
637         
638         @Test
639 //      @Ignore
640         public void preProcessSDNCGet_NotFoundAR() {
641                 ExecutionEntity mex = setupMock()
642                 def map = setupMap(mex)
643                 initPreProcessSDNCGet(mex)
644                 
645                 when(mex.getVariable("foundActiveAR")).thenReturn(false)
646                                         
647                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
648                 DoCreateAllottedResourceBRG.preProcessSDNCGet(mex)
649                 
650                 String req = map.get("sdncGetRequest")
651                 
652                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
653                 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
654                 assertTrue(req.indexOf("<sdncadapter:SvcOperation>assignlink</") >= 0)
655                 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
656                 
657         }
658         
659         @Test
660 //      @Ignore
661         public void preProcessSDNCGet_Ex() {
662                 ExecutionEntity mex = setupMock()
663                 initPreProcessSDNCGet(mex)
664                 
665                 when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception"))
666                 
667                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
668                 
669                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.preProcessSDNCGet(mex) }))
670         }
671         
672         
673         // ***** updateAaiAROrchStatus *****
674         
675         @Test
676 //      @Ignore
677         public void updateAaiAROrchStatus() {
678                 MockPatchAllottedResource(CUST, SVC, INST, ARID)
679                 
680                 ExecutionEntity mex = setupMock()
681                 initUpdateAaiAROrchStatus(mex)
682                                         
683                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
684                 DoCreateAllottedResourceBRG.updateAaiAROrchStatus(mex, "success")
685         }
686         
687         
688         // ***** generateOutputs *****
689         
690         @Test
691 //      @Ignore
692         public void generateOutputs() {
693                 ExecutionEntity mex = setupMock()
694                 def brgtop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/SDNCTopologyQueryCallback.xml")
695                 
696                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
697                 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(brgtop)
698                 
699                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
700                 DoCreateAllottedResourceBRG.generateOutputs(mex)
701                 
702                 verify(mex).setVariable("allotedResourceName", "namefromrequest")
703                 
704         }
705         
706         @Test
707 //      @Ignore
708         public void generateOutputs_BadXml() {
709                 ExecutionEntity mex = setupMock()
710                 
711                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
712                 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml")
713                 
714                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
715                 DoCreateAllottedResourceBRG.generateOutputs(mex)
716                 
717                 verify(mex, never()).setVariable(anyString(), anyString())
718                 
719         }
720         
721         @Test
722 //      @Ignore
723         public void generateOutputs_BpmnError() {
724                 ExecutionEntity mex = setupMock()
725                 
726                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
727                 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception"))
728                 
729                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
730                 
731                 DoCreateAllottedResourceBRG.generateOutputs(mex)
732                 verify(mex, never()).setVariable(anyString(), anyString())
733                 
734         }
735         
736         @Test
737 //      @Ignore
738         public void generateOutputs_Ex() {
739                 ExecutionEntity mex = setupMock()
740                 
741                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
742                 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception"))
743                 
744                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
745                 
746                 DoCreateAllottedResourceBRG.generateOutputs(mex)
747                 verify(mex, never()).setVariable(anyString(), anyString())
748                 
749         }
750         
751         
752         // ***** preProcessRollback *****
753         
754         @Test
755 //      @Ignore
756         public void preProcessRollback() {
757                 ExecutionEntity mex = setupMock()
758                 WorkflowException wfe = mock(WorkflowException.class)
759                 
760                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
761                 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
762                 
763                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
764                 DoCreateAllottedResourceBRG.preProcessRollback(mex)
765                 
766                 verify(mex).setVariable("prevWorkflowException", wfe)
767                 
768         }
769         
770         @Test
771 //      @Ignore
772         public void preProcessRollback_NotWFE() {
773                 ExecutionEntity mex = setupMock()
774                 
775                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
776                 when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE")
777                 
778                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
779                 DoCreateAllottedResourceBRG.preProcessRollback(mex)
780                 
781 //                      verify(mex, never()).setVariable("prevWorkflowException", any())
782                 
783         }
784         
785         @Test
786 //      @Ignore
787         public void preProcessRollback_BpmnError() {
788                 ExecutionEntity mex = setupMock()
789                 
790                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
791                 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
792                 
793                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
794                 
795                 DoCreateAllottedResourceBRG.preProcessRollback(mex)
796                 
797         }
798         
799         @Test
800 //      @Ignore
801         public void preProcessRollback_Ex() {
802                 ExecutionEntity mex = setupMock()
803                 
804                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
805                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
806                 
807                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
808                 
809                 DoCreateAllottedResourceBRG.preProcessRollback(mex)
810                 
811         }
812         
813         
814         // ***** postProcessRollback *****
815         
816         @Test
817 //      @Ignore
818         public void postProcessRollback() {
819                 ExecutionEntity mex = setupMock()
820                 WorkflowException wfe = mock(WorkflowException.class)
821                 
822                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
823                 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
824                 
825                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
826                 DoCreateAllottedResourceBRG.postProcessRollback(mex)
827                 
828                 verify(mex).setVariable("WorkflowException", wfe)
829                 verify(mex).setVariable("rollbackData", null)
830                 
831         }
832         
833         @Test
834 //      @Ignore
835         public void postProcessRollback_NotWFE() {
836                 ExecutionEntity mex = setupMock()
837                 
838                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
839                 when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE")
840                 
841                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
842                 DoCreateAllottedResourceBRG.postProcessRollback(mex)
843                 
844 //                      verify(mex, never()).setVariable("WorkflowException", any())
845                 verify(mex).setVariable("rollbackData", null)
846                 
847         }
848         
849         @Test
850 //      @Ignore
851         public void postProcessRollback_BpmnError() {
852                 ExecutionEntity mex = setupMock()
853                 
854                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
855                 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
856                 
857                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
858                 
859                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceBRG.postProcessRollback(mex) }))
860                 verify(mex, never()).setVariable("rollbackData", null)
861                 
862         }
863         
864         @Test
865 //      @Ignore
866         public void postProcessRollback_Ex() {
867                 ExecutionEntity mex = setupMock()
868                 
869                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
870                 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
871                 
872                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
873                 
874                 DoCreateAllottedResourceBRG.postProcessRollback(mex)
875                 verify(mex, never()).setVariable("rollbackData", null)
876                 
877         }
878         
879         private boolean checkMissingPreProcessRequest(String fieldnm) {
880                 ExecutionEntity mex = setupMock()
881                 initPreProcess(mex)
882                                                                 
883                 DoCreateAllottedResourceBRG DoCreateAllottedResourceBRG = new DoCreateAllottedResourceBRG()
884                 
885                 when(mex.getVariable(fieldnm)).thenReturn("")
886                 
887                 return doBpmnError( { _ -> DoCreateAllottedResourceBRG.preProcessRequest(mex) })
888         }
889         
890         private void initPreProcess(ExecutionEntity mex) {
891                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
892                 when(mex.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn("sdncurn")
893                 when(mex.getVariable("URN_mso_workflow_sdnc_replication_delay")).thenReturn("sdncdelay")
894                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
895                 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
896                 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi")
897                 when(mex.getVariable("vni")).thenReturn("myvni")
898                 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
899                 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
900                 when(mex.getVariable("allottedResourceRole")).thenReturn("arr")
901                 when(mex.getVariable("allottedResourceType")).thenReturn("art")
902         }
903         
904         private void initGetAaiAR(ExecutionEntity mex) {
905                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
906                 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
907                 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
908                 when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceBRG/getAR.xml"))
909                 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
910                 when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
911         }
912         
913         private initCreateAaiAr(ExecutionEntity mex) {                          
914                 when(mex.getVariable("disableRollback")).thenReturn(45)
915                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
916                 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
917                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
918                 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
919                 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
920                 when(mex.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn(urnProps.get("mso.workflow.global.default.aai.namespace"))
921                 when(mex.getVariable("PSI_resourceLink")).thenReturn(aaiUriPfx + "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST)
922                 when(mex.getVariable("allottedResourceType")).thenReturn("BRGt")
923                 when(mex.getVariable("allottedResourceRole")).thenReturn("BRGr")
924                 when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi")
925                 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
926                                 {
927                                         "modelInvariantUuid":"modelinvuuid",
928                                         "modelUuid":"modeluuid",
929                                         "modelCustomizationUuid":"modelcustuuid"
930                                 }
931                         """)
932         }
933         
934         private initBuildSDNCRequest(ExecutionEntity mex) {
935                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
936                 when(mex.getVariable("allottedResourceId")).thenReturn("ari")
937                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
938                 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
939                 when(mex.getVariable("subscriptionServiceType")).thenReturn("sst")
940                 when(mex.getVariable("globalCustomerId")).thenReturn("gci")
941                 when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu")
942                 when(mex.getVariable("msoRequestId")).thenReturn("mri")
943                 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
944                 when(mex.getVariable("vni")).thenReturn("myvni")
945                 when(mex.getVariable("vgmuxBearerIP")).thenReturn("vbi")
946                 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
947                                 {
948                                         "modelInvariantUuid":"miu",
949                                         "modelUuid":"mu",
950                                         "modelCustomizationUuid":"mcu",
951                                         "modelVersion":"mv",
952                                         "modelName":"mn"
953                                 }
954                         """)
955         }
956         
957         private RollbackData initPreProcessSDNC(ExecutionEntity mex) {
958                 def data = new RollbackData()
959                 
960                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
961                 when(mex.getVariable("rollbackData")).thenReturn(data)
962                 
963                 return data
964         }
965         
966         private initPreProcessSDNCGet(ExecutionEntity mex) {
967                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
968                 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
969                 when(mex.getVariable("foundActiveAR")).thenReturn(true)
970                 when(mex.getVariable("aaiARGetResponse")).thenReturn("<selflink>arlink</selflink>")
971                 when(mex.getVariable("sdncAssignResponse")).thenReturn("<response-data>&lt;object-path&gt;assignlink&lt;/object-path&gt;</response-data>")
972                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
973                 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
974         }
975         
976         private RollbackData initValidateSDNCResp(ExecutionEntity mex) {
977                 def data = new RollbackData()
978                 
979                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
980                 when(mex.getVariable("prefix")).thenReturn(Prefix)
981                 when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
982                 when(mex.getVariable("rollbackData")).thenReturn(data)
983                 
984                 return data
985         }
986         
987         private String initValidateSDNCResp_Resp() {
988                 return "<response-data>&lt;response-code&gt;200&lt;/response-code&gt;</response-data>"
989         }
990         
991         private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
992                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
993                 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)
994         }
995                 
996 }