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