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