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