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