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