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