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