9c98c01b91bdea6a288310d587b365985c9ebb04
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / DoDeleteVnfTest.java
1 /*
2  * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
3  */
4 /*- 
5  * ============LICENSE_START======================================================= 
6  * OPENECOMP - MSO 
7  * ================================================================================ 
8  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. 
9  * ================================================================================ 
10  * Licensed under the Apache License, Version 2.0 (the "License"); 
11  * you may not use this file except in compliance with the License. 
12  * You may obtain a copy of the License at 
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0 
15  * 
16  * Unless required by applicable law or agreed to in writing, software 
17  * distributed under the License is distributed on an "AS IS" BASIS, 
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
19  * See the License for the specific language governing permissions and 
20  * limitations under the License. 
21  * ============LICENSE_END========================================================= 
22  */ 
23
24 package org.openecomp.mso.bpmn.infrastructure;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockDeleteGenericVnf;
28 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;
29 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
30
31 import java.util.HashMap;
32 import java.util.Map;
33 import java.util.UUID;
34
35 import org.camunda.bpm.engine.test.Deployment;
36 import org.junit.Assert;
37 import org.junit.Test;
38 import org.openecomp.mso.bpmn.common.BPMNUtil;
39 import org.openecomp.mso.bpmn.common.WorkflowTest;
40
41 /**
42  * Please describe the DeleteVnfInfra.java class
43  *
44  */
45 public class DoDeleteVnfTest extends WorkflowTest {
46
47         
48         @Test
49         @Deployment(resources = {"subprocess/GenericGetVnf.bpmn", "subprocess/GenericDeleteVnf.bpmn", "subprocess/DoDeleteVnf.bpmn"})
50         public void testDoDeleteVnf_success() throws Exception{
51                 
52                 MockGetGenericVnfByIdWithDepth("testVnfId123", 1, "GenericFlows/getGenericVnfByNameResponse.xml");
53                 MockDeleteGenericVnf("testVnfId123", "testReVer123");
54                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
55                 
56                 String businessKey = UUID.randomUUID().toString();
57                 Map<String, Object> variables = new HashMap<String, Object>();
58                 setVariables(variables);
59                 invokeSubProcess("DoDeleteVnf", businessKey, variables);
60                 // Disabled until SDNC support is there
61 //              injectSDNCCallbacks(callbacks, "assign");               
62 //              injectSDNCCallbacks(callbacks, "activate");
63
64                 waitForProcessEnd(businessKey, 10000);
65                                 
66                 Assert.assertTrue(isProcessEnded(businessKey));
67                 String found = BPMNUtil.getVariable(processEngineRule, "DoDeleteVnf", "GENGV_FoundIndicator") ;
68                 String inUse = BPMNUtil.getVariable(processEngineRule, "DoDeleteVnf", "DoDVNF_vnfInUse");
69                 String workflowException = BPMNUtil.getVariable(processEngineRule, "DoDeleteVnf", "WorkflowException");
70
71                 assertEquals("true", found);
72                 assertEquals("false", inUse);
73                 assertEquals(null, workflowException);
74         }
75
76         @Test
77         @Deployment(resources = {"subprocess/GenericGetVnf.bpmn", "subprocess/GenericDeleteVnf.bpmn", "subprocess/DoDeleteVnf.bpmn"})
78         public void testDeleteVnfInfra_success_vnfNotFound() throws Exception{
79
80                 MockDeleteGenericVnf("testVnfId123", "testReVer123", 404);
81                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
82                 
83                 String businessKey = UUID.randomUUID().toString();
84                 Map<String, Object> variables = new HashMap<String, Object>();
85                 setVariables(variables);
86
87                 invokeSubProcess("DoDeleteVnf", businessKey, variables);
88                 // Disabled until SDNC support is there
89 //              injectSDNCCallbacks(callbacks, "assign");               
90 //              injectSDNCCallbacks(callbacks, "activate");
91
92                 waitForProcessEnd(businessKey, 10000);
93                 
94                 Assert.assertTrue(isProcessEnded(businessKey));
95                 String found = BPMNUtil.getVariable(processEngineRule, "DoDeleteVnf", "GENGV_FoundIndicator") ;
96                 String inUse = BPMNUtil.getVariable(processEngineRule, "DoDeleteVnf", "DoDVNF_vnfInUse");
97                 String workflowException = BPMNUtil.getVariable(processEngineRule, "DoDeleteVnf", "WorkflowException");
98
99                 assertEquals("false", found);
100                 assertEquals("false", inUse);
101                 assertEquals(null, workflowException);
102         }
103
104         @Test
105         @Deployment(resources = {"subprocess/GenericGetVnf.bpmn", "subprocess/GenericDeleteVnf.bpmn", "subprocess/DoDeleteVnf.bpmn"})
106         public void testDeleteVnfInfra_error_vnfInUse() throws Exception{
107
108                 MockGetGenericVnfByIdWithDepth("testVnfId123", 1, "GenericFlows/getGenericVnfResponse_hasRelationships.xml");
109                 MockDeleteGenericVnf("testVnfId123", "testReVer123");
110                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
111
112                 String businessKey = UUID.randomUUID().toString();
113                 Map<String, Object> variables = new HashMap<String, Object>();
114                 setVariables(variables);
115
116                 invokeSubProcess("DoDeleteVnf", businessKey, variables);
117 //              Disabled until SDNC support is there
118 //              injectSDNCCallbacks(callbacks, "assign");               
119 //              injectSDNCCallbacks(callbacks, "activate");
120
121                 waitForProcessEnd(businessKey, 10000);
122                 
123                 Assert.assertTrue(isProcessEnded(businessKey));
124
125                 String found = BPMNUtil.getVariable(processEngineRule, "DoDeleteVnf", "GENGV_FoundIndicator") ;
126                 String inUse = BPMNUtil.getVariable(processEngineRule, "DoDeleteVnf", "DoDVNF_vnfInUse");
127                 String workflowException = BPMNUtil.getVariable(processEngineRule, "DoDeleteVnf", "WorkflowException");
128                 String exWfex = "WorkflowException[processKey=DoDeleteVnf,errorCode=5000,errorMessage=Can't Delete Generic Vnf. Generic Vnf is still in use.]";
129
130                 assertEquals("true", found);
131                 assertEquals("true", inUse);
132                 assertEquals(exWfex, workflowException);
133         }
134
135         private void setVariables(Map<String, Object> variables) {
136                 variables.put("mso-request-id", "123");
137                 variables.put("isDebugLogEnabled", "true");             
138                 variables.put("vnfId","testVnfId123");
139         }
140 }