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