Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DeleteGenericAlaCarteServiceInstanceTest.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import org.camunda.bpm.engine.ProcessEngineServices
24 import org.camunda.bpm.engine.RepositoryService
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.camunda.bpm.engine.repository.ProcessDefinition
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.junit.Before
29 import org.junit.Rule
30 import org.junit.Test
31 import org.mockito.MockitoAnnotations
32 import org.onap.so.bpmn.common.scripts.MsoUtils
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.onap.so.bpmn.common.scripts.VidUtils
36
37 import static org.junit.Assert.*;
38 import static org.mockito.Mockito.*
39
40 import com.github.tomakehurst.wiremock.junit.WireMockRule
41
42 class DeleteGenericAlaCarteServiceInstanceTest  {
43
44     @Rule
45     public WireMockRule wireMockRule = new WireMockRule(8090);
46
47     String Prefix="DELSI_"
48     def utils = new MsoUtils()
49                 JsonUtils jsonUtil = new JsonUtils()
50                 VidUtils vidUtils = new VidUtils()
51
52     String jsonIncomingRequest =
53             """{
54         "requestDetails": {
55         "modelInfo": {
56         "modelType": "service",
57         "modelInvariantId": "1de901ed-17af-4b03-bc1f-41659cfa27cb",
58         "modelVersionId": "ace39141-09ec-4068-b06d-ac6b23bdc6e0",
59         "modelName": "demoVLB",
60         "modelVersion": "1.0"
61         },
62         "cloudConfiguration" : {
63         "lcpCloudRegionId": "RegionOne",
64         "tenantId": "onap"
65         },
66         "subscriberInfo": {
67         "globalSubscriberId": "Demonstration",
68         "subscriberName": "Demonstration"
69         },
70         "requestInfo": {
71         "instanceName": "sample-instance-2",
72         "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",
73         "source": "VID",
74         "requestorId":"1234",
75         "suppressRollback": "false"
76         },
77         "requestParameters": {
78         "subscriptionServiceType": "vLB"
79         }
80         }
81         }"""
82
83             @Before
84                 public void init()
85                 {
86                         MockitoAnnotations.initMocks(this)
87                         
88                 }
89
90                 public void initializeVariables(DelegateExecution mockExecution) {
91                         
92                         verify(mockExecution).setVariable(Prefix + "Success", false)
93                         
94                         verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")
95                         verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")
96                         verify(mockExecution).setVariable(Prefix + "isSilentSuccess", false)
97                                 
98                 }
99                                 
100                 @Test
101                 //@Ignore  
102                 public void preProcessRequest() {
103                         
104                         println "************ preProcessRequest() ************* " 
105                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
106                         // Initialize prerequisite variables
107                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
108                         when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
109                         
110                         try {
111                 // preProcessRequest(DelegateExecution execution)
112                 DeleteGenericALaCarteServiceInstance deleteGenericALaCarteServiceInstance = new DeleteGenericALaCarteServiceInstance()
113                 deleteGenericALaCarteServiceInstance.preProcessRequest(mockExecution)
114
115                 verify(mockExecution).getVariable("isDebugLogEnabled")
116                 verify(mockExecution).setVariable("prefix", Prefix)
117
118                 initializeVariables(mockExecution)
119                 //verify(mockExecution).setVariable(Prefix + "Success", false)
120             }catch(Exception e){
121                 //ignore
122             }
123
124                 }
125 }