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