Merge changes I4e542ffd,Ibb86da2d
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / groovy / org / openecomp / mso / bpmn / vcpe / scripts / DoCreateAllottedResourceTXCTest.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 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>sii</") >= 0)
305                 assertTrue(result.indexOf("<parent-service-instance-id>psii</") >= 0)
306                 assertTrue(result.indexOf("<subscription-service-type>sst</") >= 0)
307                 assertTrue(result.indexOf("<global-customer-id>gci</") >= 0)
308                 assertTrue(result.indexOf("<sdncadapter:CallbackUrl>scu</") >= 0)
309                 assertTrue(result.indexOf("<request-id>mri</") >= 0)
310                 assertTrue(result.indexOf("<model-invariant-uuid/>") >= 0)
311                 assertTrue(result.indexOf("<model-uuid/>") >= 0)
312                 assertTrue(result.indexOf("<model-customization-uuid/>") >= 0)
313                 assertTrue(result.indexOf("<model-version/>") >= 0)
314                 assertTrue(result.indexOf("<model-name/>") >= 0)
315         }
316         
317         @Test
318         // @Ignore
319         public void buildSDNCRequest_Ex() {
320                 ExecutionEntity mex = setupMock()
321                 initBuildSDNCRequest(mex)
322                 
323                 when(mex.getVariable("allottedResourceId")).thenThrow(new RuntimeException("expected exception"))
324                 
325                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
326                 
327                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.buildSDNCRequest(mex, "myact", "myreq") }))
328         }
329         
330         
331         // ***** preProcessSDNCAssign *****
332         
333         @Test
334         // @Ignore
335         public void preProcessSDNCAssign() {
336                 ExecutionEntity mex = setupMock()
337                 def map = setupMap(mex)
338                 def data = initPreProcessSDNC(mex)
339                                         
340                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
341                 DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex)
342                 
343                 def req = map.get("sdncAssignRequest")
344                 assertNotNull(req)
345                 
346                 assertEquals(data, map.get("rollbackData"))
347                 
348                 def rbreq = data.get(Prefix, "sdncAssignRollbackReq")
349                 
350                 assertTrue(req.indexOf("<sdncadapter:SvcAction>assign</") >= 0)
351                 assertTrue(req.indexOf("<request-action>CreateTunnelXConnInstance</") >= 0)
352                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
353                 
354                 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>unassign</") >= 0)
355                 assertTrue(rbreq.indexOf("<request-action>DeleteTunnelXConnInstance</") >= 0)
356                 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
357         }
358         
359         @Test
360         // @Ignore
361         public void preProcessSDNCAssign_BpmnError() {
362                 ExecutionEntity mex = setupMock()
363                 initPreProcessSDNC(mex)
364                 
365                 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
366                                         
367                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
368                 
369                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) }))
370         }
371         
372         @Test
373         // @Ignore
374         public void preProcessSDNCAssign_Ex() {
375                 ExecutionEntity mex = setupMock()
376                 initPreProcessSDNC(mex)
377                 
378                 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
379                                         
380                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
381                 
382                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCAssign(mex) }))
383         }
384         
385         
386         // ***** preProcessSDNCCreate *****
387         
388         @Test
389         // @Ignore
390         public void preProcessSDNCCreate() {
391                 ExecutionEntity mex = setupMock()
392                 def map = setupMap(mex)
393                 def data = initPreProcessSDNC(mex)
394                                         
395                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
396                 DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex)
397                 
398                 def req = map.get("sdncCreateRequest")
399                 assertNotNull(req)
400                 
401                 assertEquals(data, map.get("rollbackData"))
402                 
403                 def rbreq = data.get(Prefix, "sdncCreateRollbackReq")
404                 
405                 assertTrue(req.indexOf("<sdncadapter:SvcAction>create</") >= 0)
406                 assertTrue(req.indexOf("<request-action>CreateTunnelXConnInstance</") >= 0)
407                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
408                 
409                 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>delete</") >= 0)
410                 assertTrue(rbreq.indexOf("<request-action>DeleteTunnelXConnInstance</") >= 0)
411                 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
412                 
413         }
414         
415         @Test
416         // @Ignore
417         public void preProcessSDNCCreate_BpmnError() {
418                 ExecutionEntity mex = setupMock()
419                 initPreProcessSDNC(mex)
420                 
421                 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
422                                         
423                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
424                 
425                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) }))
426         }
427         
428         @Test
429         // @Ignore
430         public void preProcessSDNCCreate_Ex() {
431                 ExecutionEntity mex = setupMock()
432                 initPreProcessSDNC(mex)
433                 
434                 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
435                                         
436                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
437                 
438                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCCreate(mex) }))
439         }
440         
441         
442         // ***** preProcessSDNCActivate *****
443         
444         @Test
445         // @Ignore
446         public void preProcessSDNCActivate() {
447                 ExecutionEntity mex = setupMock()
448                 def map = setupMap(mex)
449                 def data = initPreProcessSDNC(mex)
450                                         
451                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
452                 DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex)
453                 
454                 def req = map.get("sdncActivateRequest")
455                 assertNotNull(req)
456                 
457                 assertEquals(data, map.get("rollbackData"))
458                 
459                 def rbreq = data.get(Prefix, "sdncActivateRollbackReq")
460                 
461                 assertTrue(req.indexOf("<sdncadapter:SvcAction>activate</") >= 0)
462                 assertTrue(req.indexOf("<request-action>CreateTunnelXConnInstance</") >= 0)
463                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
464                 
465                 assertTrue(rbreq.indexOf("<sdncadapter:SvcAction>deactivate</") >= 0)
466                 assertTrue(rbreq.indexOf("<request-action>DeleteTunnelXConnInstance</") >= 0)
467                 assertTrue(rbreq.indexOf("<sdncadapter:RequestId>") >= 0)
468                 
469         }
470         
471         @Test
472         // @Ignore
473         public void preProcessSDNCActivate_BpmnError() {
474                 ExecutionEntity mex = setupMock()
475                 initPreProcessSDNC(mex)
476                 
477                 when(mex.getVariable("rollbackData")).thenThrow(new BpmnError("expected exception"))
478                                         
479                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
480                 
481                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) }))
482         }
483         
484         @Test
485         // @Ignore
486         public void preProcessSDNCActivate_Ex() {
487                 ExecutionEntity mex = setupMock()
488                 initPreProcessSDNC(mex)
489                 
490                 when(mex.getVariable("rollbackData")).thenThrow(new RuntimeException("expected exception"))
491                                         
492                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
493                 
494                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCActivate(mex) }))
495         }
496         
497         
498         // ***** validateSDNCResp *****
499         
500         @Test
501         // @Ignore
502         public void validateSDNCResp() {
503                 ExecutionEntity mex = setupMock()
504                 def map = setupMap(mex)
505                 def data = initValidateSDNCResp(mex)
506                 def resp = initValidateSDNCResp_Resp()
507                 
508                 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
509                 
510                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
511                 
512                 DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create")
513                 
514                 verify(mex).getVariable("WorkflowException")
515                 verify(mex).getVariable("SDNCA_SuccessIndicator")
516                 verify(mex).getVariable("rollbackData")
517                 
518                 assertEquals(data, map.get("rollbackData"))
519                 
520                 assertEquals("true", data.get(Prefix, "rollback" +  "SDNCcreate"))
521                 
522         }
523         
524         @Test
525         // @Ignore
526         public void validateSDNCResp_Get() {
527                 ExecutionEntity mex = setupMock()
528                 def data = initValidateSDNCResp(mex)
529                 def resp = initValidateSDNCResp_Resp()
530                 
531                 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(true)
532                 
533                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
534                 
535                 DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "get")
536                 
537                 verify(mex).getVariable("WorkflowException")
538                 verify(mex).getVariable("SDNCA_SuccessIndicator")
539                 
540                 verify(mex, never()).getVariable("rollbackData")
541         }
542         
543         @Test
544         // @Ignore
545         public void validateSDNCResp_Unsuccessful() {
546                 ExecutionEntity mex = setupMock()
547                 initValidateSDNCResp(mex)
548                 def resp = initValidateSDNCResp_Resp()
549                 
550                 // unsuccessful
551                 when(mex.getVariable(Prefix+"sdncResponseSuccess")).thenReturn(false)
552                 
553                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
554                 
555                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") }))
556         }
557         
558         @Test
559         // @Ignore
560         public void validateSDNCResp_BpmnError() {
561                 ExecutionEntity mex = setupMock()
562                 initValidateSDNCResp(mex)
563                 def resp = initValidateSDNCResp_Resp()
564                 
565                 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
566                 
567                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
568                 
569                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") }))
570         }
571         
572         @Test
573         // @Ignore
574         public void validateSDNCResp_Ex() {
575                 ExecutionEntity mex = setupMock()
576                 initValidateSDNCResp(mex)
577                 def resp = initValidateSDNCResp_Resp()
578                 
579                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
580                 
581                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
582                 
583                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.validateSDNCResp(mex, resp, "create") }))
584         }
585         
586         
587         // ***** preProcessSDNCGet *****
588         
589         @Test
590         // @Ignore
591         public void preProcessSDNCGet_FoundAR() {
592                 ExecutionEntity mex = setupMock()
593                 def map = setupMap(mex)
594                 initPreProcessSDNCGet(mex)
595                                         
596                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
597                 DoCreateAllottedResourceTXC.preProcessSDNCGet(mex)
598                 
599                 String req = map.get("sdncGetRequest")
600                 
601                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
602                 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
603                 assertTrue(req.indexOf("<sdncadapter:SvcOperation>arlink</") >= 0)
604                 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
605                 
606         }
607         
608         @Test
609         // @Ignore
610         public void preProcessSDNCGet_NotFoundAR() {
611                 ExecutionEntity mex = setupMock()
612                 def map = setupMap(mex)
613                 initPreProcessSDNCGet(mex)
614                 
615                 when(mex.getVariable("foundActiveAR")).thenReturn(false)
616                                         
617                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
618                 DoCreateAllottedResourceTXC.preProcessSDNCGet(mex)
619                 
620                 String req = map.get("sdncGetRequest")
621                 
622                 assertTrue(req.indexOf("<sdncadapter:RequestId>") >= 0)
623                 assertTrue(req.indexOf("<sdncadapter:SvcInstanceId>sii</") >= 0)
624                 assertTrue(req.indexOf("<sdncadapter:SvcOperation>assignlink</") >= 0)
625                 assertTrue(req.indexOf("<sdncadapter:CallbackUrl>myurl</") >= 0)
626                 
627         }
628         
629         @Test
630         // @Ignore
631         public void preProcessSDNCGet_Ex() {
632                 ExecutionEntity mex = setupMock()
633                 initPreProcessSDNCGet(mex)
634                 
635                 when(mex.getVariable("foundActiveAR")).thenThrow(new RuntimeException("expected exception"))
636                 
637                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
638                 
639                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.preProcessSDNCGet(mex) }))
640         }
641         
642         
643         // ***** updateAaiAROrchStatus *****
644         
645         @Test
646         // @Ignore
647         public void updateAaiAROrchStatus() {
648                 MockPatchAllottedResource(CUST, SVC, INST, ARID)
649                 
650                 ExecutionEntity mex = setupMock()
651                 initUpdateAaiAROrchStatus(mex)
652                                         
653                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
654                 DoCreateAllottedResourceTXC.updateAaiAROrchStatus(mex, "success")
655         }
656         
657         
658         // ***** generateOutputs *****
659         
660         @Test
661         // @Ignore
662         public void generateOutputs() {
663                 ExecutionEntity mex = setupMock()
664                 def txctop = FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/SDNCTopologyQueryCallback.xml")
665                 
666                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
667                 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn(txctop)
668                 
669                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
670                 DoCreateAllottedResourceTXC.generateOutputs(mex)
671                 
672                 verify(mex).setVariable("allotedResourceName", "namefromrequest")
673                 verify(mex).setVariable("vni", "my-vni")
674                 verify(mex).setVariable("vgmuxBearerIP", "my-bearer-ip")
675                 verify(mex).setVariable("vgmuxLanIP", "my-lan-ip")
676                 
677         }
678         
679         @Test
680         // @Ignore
681         public void generateOutputs_BadXml() {
682                 ExecutionEntity mex = setupMock()
683                 
684                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
685                 when(mex.getVariable("enhancedCallbackRequestData")).thenReturn("invalid xml")
686                 
687                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
688                 DoCreateAllottedResourceTXC.generateOutputs(mex)
689                 
690                 verify(mex, never()).setVariable(anyString(), anyString())
691                 
692         }
693         
694         @Test
695         // @Ignore
696         public void generateOutputs_BpmnError() {
697                 ExecutionEntity mex = setupMock()
698                 
699                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
700                 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new BpmnError("expected exception"))
701                 
702                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
703                 
704                 DoCreateAllottedResourceTXC.generateOutputs(mex)
705                 verify(mex, never()).setVariable(anyString(), anyString())
706                 
707         }
708         
709         @Test
710         // @Ignore
711         public void generateOutputs_Ex() {
712                 ExecutionEntity mex = setupMock()
713                 
714                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
715                 when(mex.getVariable("enhancedCallbackRequestData")).thenThrow(new RuntimeException("expected exception"))
716                 
717                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
718                 
719                 DoCreateAllottedResourceTXC.generateOutputs(mex)
720                 verify(mex, never()).setVariable(anyString(), anyString())
721                 
722         }
723         
724         
725         // ***** preProcessRollback *****
726         
727         @Test
728         // @Ignore
729         public void preProcessRollback() {
730                 ExecutionEntity mex = setupMock()
731                 WorkflowException wfe = mock(WorkflowException.class)
732                 
733                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
734                 when(mex.getVariable("WorkflowException")).thenReturn(wfe)
735                 
736                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
737                 DoCreateAllottedResourceTXC.preProcessRollback(mex)
738                 
739                 verify(mex).setVariable("prevWorkflowException", wfe)
740                 
741         }
742         
743         @Test
744         // @Ignore
745         public void preProcessRollback_NotWFE() {
746                 ExecutionEntity mex = setupMock()
747                 
748                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
749                 when(mex.getVariable("WorkflowException")).thenReturn("I'm not a WFE")
750                 
751                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
752                 DoCreateAllottedResourceTXC.preProcessRollback(mex)
753                 
754 //                      verify(mex, never()).setVariable("prevWorkflowException", any())
755                 
756         }
757         
758         @Test
759         // @Ignore
760         public void preProcessRollback_BpmnError() {
761                 ExecutionEntity mex = setupMock()
762                 
763                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
764                 when(mex.getVariable("WorkflowException")).thenThrow(new BpmnError("expected exception"))
765                 
766                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
767                 
768                 DoCreateAllottedResourceTXC.preProcessRollback(mex)
769                 
770         }
771         
772         @Test
773         // @Ignore
774         public void preProcessRollback_Ex() {
775                 ExecutionEntity mex = setupMock()
776                 
777                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
778                 when(mex.getVariable("WorkflowException")).thenThrow(new RuntimeException("expected exception"))
779                 
780                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
781                 
782                 DoCreateAllottedResourceTXC.preProcessRollback(mex)
783                 
784         }
785         
786         
787         // ***** postProcessRollback *****
788         
789         @Test
790         // @Ignore
791         public void postProcessRollback() {
792                 ExecutionEntity mex = setupMock()
793                 WorkflowException wfe = mock(WorkflowException.class)
794                 
795                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
796                 when(mex.getVariable("prevWorkflowException")).thenReturn(wfe)
797                 
798                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
799                 DoCreateAllottedResourceTXC.postProcessRollback(mex)
800                 
801                 verify(mex).setVariable("WorkflowException", wfe)
802                 verify(mex).setVariable("rollbackData", null)
803                 
804         }
805         
806         @Test
807         // @Ignore
808         public void postProcessRollback_NotWFE() {
809                 ExecutionEntity mex = setupMock()
810                 
811                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
812                 when(mex.getVariable("prevWorkflowException")).thenReturn("I'm not a WFE")
813                 
814                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
815                 DoCreateAllottedResourceTXC.postProcessRollback(mex)
816                 
817 //                      verify(mex, never()).setVariable("WorkflowException", any())
818                 verify(mex).setVariable("rollbackData", null)
819                 
820         }
821         
822         @Test
823         // @Ignore
824         public void postProcessRollback_BpmnError() {
825                 ExecutionEntity mex = setupMock()
826                 
827                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
828                 when(mex.getVariable("prevWorkflowException")).thenThrow(new BpmnError("expected exception"))
829                 
830                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
831                 
832                 assertTrue(doBpmnError({ _ -> DoCreateAllottedResourceTXC.postProcessRollback(mex) }))
833                 verify(mex, never()).setVariable("rollbackData", null)
834                 
835         }
836         
837         @Test
838         // @Ignore
839         public void postProcessRollback_Ex() {
840                 ExecutionEntity mex = setupMock()
841                 
842                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
843                 when(mex.getVariable("prevWorkflowException")).thenThrow(new RuntimeException("expected exception"))
844                 
845                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
846                 
847                 DoCreateAllottedResourceTXC.postProcessRollback(mex)
848                 verify(mex, never()).setVariable("rollbackData", null)
849                 
850         }
851         
852         private boolean checkMissingPreProcessRequest(String fieldnm) {
853                 ExecutionEntity mex = setupMock()
854                 initPreProcess(mex)
855                                                                 
856                 DoCreateAllottedResourceTXC DoCreateAllottedResourceTXC = new DoCreateAllottedResourceTXC()
857                 
858                 when(mex.getVariable(fieldnm)).thenReturn("")
859                 
860                 return doBpmnError( { _ -> DoCreateAllottedResourceTXC.preProcessRequest(mex) })
861         }
862         
863         private void initPreProcess(ExecutionEntity mex) {
864                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
865                 when(mex.getVariable("URN_mso_workflow_sdncadapter_callback")).thenReturn("sdncurn")
866                 when(mex.getVariable("URN_mso_workflow_sdnc_replication_delay")).thenReturn("sdncdelay")
867                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
868                 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
869                 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("armi")
870                 when(mex.getVariable("brgWanMacAddress")).thenReturn("bwma")
871                 when(mex.getVariable("allottedResourceRole")).thenReturn("arr")
872                 when(mex.getVariable("allottedResourceType")).thenReturn("art")
873         }
874         
875         private void initGetAaiAR(ExecutionEntity mex) {
876                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
877                 when(mex.getVariable("allottedResourceType")).thenReturn("TXCt")
878                 when(mex.getVariable("allottedResourceRole")).thenReturn("TXCr")
879                 when(mex.getVariable("CSI_service")).thenReturn(FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXC/getAR.xml"))
880                 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
881                 when(mex.getVariable("aaiAROrchStatus")).thenReturn("Active")
882         }
883         
884         private initCreateAaiAr(ExecutionEntity mex) {                          
885                 when(mex.getVariable("disableRollback")).thenReturn(45)
886                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
887                 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
888                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
889                 when(mex.getVariable("allottedResourceId")).thenReturn(ARID)
890                 when(mex.getVariable("URN_aai_endpoint")).thenReturn(aaiUriPfx)
891                 when(mex.getVariable("URN_mso_workflow_global_default_aai_namespace")).thenReturn(urnProps.get("mso.workflow.global.default.aai.namespace"))
892                 when(mex.getVariable("PSI_resourceLink")).thenReturn(aaiUriPfx + "/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST)
893                 when(mex.getVariable("allottedResourceType")).thenReturn("TXCt")
894                 when(mex.getVariable("allottedResourceRole")).thenReturn("TXCr")
895                 when(mex.getVariable("CSI_resourceLink")).thenReturn(aaiUriPfx+"/aai/v9/mycsi")
896                 when(mex.getVariable("allottedResourceModelInfo")).thenReturn("""
897                                 {
898                                         "modelInvariantUuid":"modelinvuuid",
899                                         "modelUuid":"modeluuid",
900                                         "modelCustomizationUuid":"modelcustuuid"
901                                 }
902                         """)
903         }
904         
905         private initBuildSDNCRequest(ExecutionEntity mex) {
906                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
907                 when(mex.getVariable("allottedResourceId")).thenReturn("ari")
908                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
909                 when(mex.getVariable("parentServiceInstanceId")).thenReturn("psii")
910                 when(mex.getVariable("subscriptionServiceType")).thenReturn("sst")
911                 when(mex.getVariable("globalCustomerId")).thenReturn("gci")
912                 when(mex.getVariable("sdncCallbackUrl")).thenReturn("scu")
913                 when(mex.getVariable("msoRequestId")).thenReturn("mri")
914         }
915         
916         private RollbackData initPreProcessSDNC(ExecutionEntity mex) {
917                 def data = new RollbackData()
918                 
919                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
920                 when(mex.getVariable("rollbackData")).thenReturn(data)
921                 
922                 return data
923         }
924         
925         private initPreProcessSDNCGet(ExecutionEntity mex) {
926                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
927                 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
928                 when(mex.getVariable("foundActiveAR")).thenReturn(true)
929                 when(mex.getVariable("aaiARGetResponse")).thenReturn("<selflink>arlink</selflink>")
930                 when(mex.getVariable("sdncAssignResponse")).thenReturn("<response-data>&lt;object-path&gt;assignlink&lt;/object-path&gt;</response-data>")
931                 when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
932                 when(mex.getVariable("sdncCallbackUrl")).thenReturn("myurl")
933         }
934         
935         private RollbackData initValidateSDNCResp(ExecutionEntity mex) {
936                 def data = new RollbackData()
937                 
938                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
939                 when(mex.getVariable("prefix")).thenReturn(Prefix)
940                 when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn(true)
941                 when(mex.getVariable("rollbackData")).thenReturn(data)
942                 
943                 return data
944         }
945         
946         private String initValidateSDNCResp_Resp() {
947                 return "<response-data>&lt;response-code&gt;200&lt;/response-code&gt;</response-data>"
948         }
949         
950         private initUpdateAaiAROrchStatus(ExecutionEntity mex) {
951                 when(mex.getVariable(DBGFLAG)).thenReturn("true")
952                 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)
953         }\r
954                 \r
955 }