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