[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / PrepareUpdateAAIVfModuleTest.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * OPENECOMP - MSO 
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.openecomp.mso.bpmn.common;
22
23 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;
24 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
26
27 import java.io.IOException;
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.util.UUID;
31
32 import org.camunda.bpm.engine.test.Deployment;
33 import org.junit.Assert;
34 import org.junit.Test;
35 import org.openecomp.mso.bpmn.core.WorkflowException;
36 import org.openecomp.mso.bpmn.mock.FileUtil;
37
38 /**
39  * Unit tests for PrepareUpdateAAIVfModule.bpmn.
40  */
41 public class PrepareUpdateAAIVfModuleTest extends WorkflowTest {
42         
43         /**
44          * Test the happy path through the flow.
45          */
46         @Test   
47         @Deployment(resources = {
48                         "subprocess/PrepareUpdateAAIVfModule.bpmn"
49                 })
50         public void happyPath() throws IOException {
51                 
52                 logStart();
53                 
54                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml"); 
55                 
56                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
57                 MockPutGenericVnf("/skask/vf-modules/vf-module/supercool", "PCRF", 200);
58                 
59                 String businessKey = UUID.randomUUID().toString();
60                 Map<String, Object> variables = new HashMap<String, Object>();
61                 variables.put("mso-request-id", "999-99-9999");
62                 variables.put("isDebugLogEnabled","true");
63                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
64                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
65                 
66                 Assert.assertTrue(isProcessEnded(businessKey));
67                 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponse");
68                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponseCode");
69                 System.out.println("Subflow response code: " + responseCode);
70                 System.out.println("Subflow response: " + response);
71                 Assert.assertEquals(200, responseCode.intValue());
72                 String heatStackId = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_heatStackId");
73                 System.out.println("Ouput heat-stack-id:" + heatStackId);
74                 Assert.assertEquals("slowburn", heatStackId);
75                 
76                 logEnd();
77         }
78         
79         /**
80          * Test the case where the GET to AAI returns a 404.
81          */
82         @Test   
83         @Deployment(resources = {
84                         "subprocess/PrepareUpdateAAIVfModule.bpmn"
85                 })
86         public void badGet() throws IOException {
87                 
88                 logStart();
89                 
90                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml"); 
91                 MockGetGenericVnfById_404("skask[?]depth=1");
92                 
93                 String businessKey = UUID.randomUUID().toString();
94                 Map<String, Object> variables = new HashMap<String, Object>();          
95                 variables.put("mso-request-id", "999-99-9999");
96                 variables.put("isDebugLogEnabled","true");
97                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
98                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
99                 
100                 Assert.assertTrue(isProcessEnded(businessKey));
101                 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_getVnfResponse");
102                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_getVnfResponseCode");
103                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
104                 System.out.println("Subflow response code: " + responseCode);
105                 System.out.println("Subflow response: " + response);
106                 Assert.assertEquals(404, responseCode.intValue());
107                 Assert.assertNotNull(workflowException);
108                 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
109                 
110                 logEnd();
111         }
112         
113         /**
114          * Test the case where the validation of the VF Module fails.
115          */
116         @Test   
117         @Deployment(resources = {
118                         "subprocess/PrepareUpdateAAIVfModule.bpmn"
119                 })
120         public void failValidation1() throws IOException {
121                 
122                 logStart();
123                 
124                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "lukewarm");
125                 
126                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
127                 
128                 String businessKey = UUID.randomUUID().toString();
129                 Map<String, Object> variables = new HashMap<String, Object>();          
130                 variables.put("mso-request-id", "999-99-9999");
131                 variables.put("isDebugLogEnabled","true");
132                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
133                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
134                 
135                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
136                 Assert.assertNotNull(workflowException);
137                 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
138                 Assert.assertTrue(workflowException.getErrorMessage().startsWith("VF Module validation error: Orchestration"));
139                 
140                 logEnd();
141         }
142         
143         /**
144          * Test the case where the validation of the VF Module fails.
145          */
146         @Test   
147         @Deployment(resources = {
148                         "subprocess/PrepareUpdateAAIVfModule.bpmn"
149                 })
150         public void failValidation2() throws IOException {
151                 
152                 logStart();
153                 
154                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml").replaceFirst("supercool", "notsocool");
155                 
156                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");              
157                 
158                 String businessKey = UUID.randomUUID().toString();
159                 Map<String, Object> variables = new HashMap<String, Object>();          
160                 variables.put("mso-request-id", "999-99-9999");
161                 variables.put("isDebugLogEnabled","true");
162                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
163                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
164                         
165                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
166                 Assert.assertNotNull(workflowException);
167                 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
168                 Assert.assertTrue(workflowException.getErrorMessage().startsWith("VF Module validation error: VF Module"));
169                 
170                 logEnd();
171         }
172
173         /**
174          * Test the case where the GET to AAI is successful, but the subsequent PUT returns 404.
175          */
176         @Test   
177         @Deployment(resources = {
178                         "subprocess/PrepareUpdateAAIVfModule.bpmn"
179                 })
180         public void badPut() throws IOException {
181                 
182                 logStart();
183                 
184                 String prepareUpdateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/PrepareUpdateAAIVfModuleRequest.xml"); 
185                 
186                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");
187                         
188                 String businessKey = UUID.randomUUID().toString();
189                 Map<String, Object> variables = new HashMap<String, Object>();          
190                 variables.put("mso-request-id", "999-99-9999");
191                 variables.put("isDebugLogEnabled","true");
192                 variables.put("PrepareUpdateAAIVfModuleRequest", prepareUpdateAAIVfModuleRequest);
193                 invokeSubProcess("PrepareUpdateAAIVfModule", businessKey, variables);
194                 
195                 Assert.assertTrue(isProcessEnded(businessKey));
196                 String response = (String) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponse");
197                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "PUAAIVfMod_updateVfModuleResponseCode");
198                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
199                 System.out.println("Subflow response code: " + responseCode);
200                 System.out.println("Subflow response: " + response);
201                 Assert.assertEquals(404, responseCode.intValue());
202                 Assert.assertNotNull(workflowException);
203                 System.out.println("Subflow WorkflowException error message: " + workflowException.getErrorMessage());
204                 
205                 logEnd();
206         }
207 }
208