4edaf7d21fac6c59b9e23b642bd9e22e803c02ad
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / vcpe / DoDeleteAllottedResourceBRGIT.java
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.vcpe;
22
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.onap.so.bpmn.common.BPMNUtil;
26 import org.onap.so.bpmn.mock.FileUtil;
27
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.util.UUID;
31
32 import static org.junit.Assert.*;
33 import static org.onap.so.bpmn.mock.StubResponseAAI.*;
34 import static org.onap.so.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
35 import static org.onap.so.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
36
37
38 public class DoDeleteAllottedResourceBRGIT extends AbstractTestBase {
39
40         private static final String PROCNAME = "DoDeleteAllottedResourceBRG";
41         private final CallbackSet callbacks = new CallbackSet();
42         
43         public DoDeleteAllottedResourceBRGIT() {
44                 callbacks.put("deactivate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
45                 callbacks.put("deactivateNF", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallbackNotFound.xml"));
46                 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
47                 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
48         }
49         
50         @Test
51         public void testDoDeleteAllottedResourceBRG_Success() {
52                 logStart();
53                 MockQueryAllottedResourceById(ARID, "GenericFlows/getARUrlById.xml");
54                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml");
55                 MockPatchAllottedResource(CUST, SVC, INST, ARID);
56                 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
57                 mockSDNCAdapter(200);
58                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
59                 
60                 String businessKey = UUID.randomUUID().toString();
61                 Map<String, Object> variables = new HashMap<>();
62                 setVariablesSuccess(variables);
63                 
64                 invokeSubProcess(PROCNAME, businessKey, variables);
65                 
66                 injectSDNCCallbacks(callbacks, "deactivate");
67                 injectSDNCCallbacks(callbacks, "delete");
68                 injectSDNCCallbacks(callbacks, "unassign");
69
70                 waitForProcessEnd(businessKey, 10000);
71                 
72                 Assert.assertTrue(isProcessEnded(businessKey));
73                 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
74                 System.out.println("workflowException:\n" + workflowException);
75                 assertNull(workflowException);
76                 logEnd();
77         }
78         
79         @Test
80         public void testDoDeleteAllottedResourceBRG_ARNotInSDNC() {
81                 logStart();
82                 MockQueryAllottedResourceById(ARID, "GenericFlows/getARUrlById.xml");
83                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml");
84                 MockPatchAllottedResource(CUST, SVC, INST, ARID);
85                 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
86                 mockSDNCAdapter(200);
87                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
88                 
89                 String businessKey = UUID.randomUUID().toString();
90                 Map<String, Object> variables = new HashMap<>();
91                 setVariablesSuccess(variables);
92
93                 variables.put("failNotFound", "false");
94                 
95                 invokeSubProcess(PROCNAME, businessKey, variables);
96                 
97                 injectSDNCCallbacks(callbacks, "deactivateNF");
98
99                 waitForProcessEnd(businessKey, 10000);
100                 
101                 Assert.assertTrue(isProcessEnded(businessKey));
102                 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, VAR_WFEX);
103                 System.out.println("workflowException:\n" + workflowException);
104                 assertNull(workflowException);
105                 logEnd();
106         }
107         
108         
109         @Test
110         public void testDoDeleteAllottedResourceBRG_SubProcessError() throws Exception {
111                 logStart();
112                 MockQueryAllottedResourceById(ARID, "GenericFlows/getARUrlById.xml");
113                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoDeleteAllottedResourceBRG/arGetById.xml");
114                 MockPatchAllottedResource(CUST, SVC, INST, ARID);
115                 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
116                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
117
118                 mockSDNCAdapter(500);
119                 
120                 Map<String, Object> variables = new HashMap<>();
121                 setVariablesSuccess(variables);
122
123                 String processId = invokeSubProcess(PROCNAME, variables);
124
125
126                 BPMNUtil.waitForWorkflowToFinish(processEngine,processId);
127
128                 Assert.assertTrue(isProcessEndedByProcessInstanceId(processId));
129                 String workflowException = BPMNUtil.getVariable(processEngine, PROCNAME, "WorkflowException",processId);
130                 System.out.println("workflowException:\n" + workflowException);
131                 assertNotNull(workflowException);
132                 logEnd();
133         }
134
135         private void setVariablesSuccess(Map<String, Object> variables) {
136                 variables.put("isDebugLogEnabled", "true");
137                 variables.put("failNotFound", "true");
138                 variables.put("msoRequestId", "testRequestId1");
139                 variables.put("mso-request-id", "requestId");
140                 variables.put("allottedResourceId", ARID);
141                 variables.put("serviceInstanceId", DEC_INST);
142                 variables.put("parentServiceInstanceId", DEC_PARENT_INST);
143         }
144
145 }