[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / CreateAAIVfModuleVolumeGroupTest.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.MockGetGenericVnfByIdWithPriority;
24 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetVfModuleId;
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutVfModuleIdNoResponse;
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.mock.FileUtil;
36
37 /**
38  * Unit tests for CreateAAIVfModuleVolumeGroup.bpmn.
39  */
40 public class CreateAAIVfModuleVolumeGroupTest extends WorkflowTest {
41                 
42         /**
43          * Test the happy path through the flow.
44          */
45         @Test   
46         @Deployment(resources = {
47                         "subprocess/CreateAAIVfModuleVolumeGroup.bpmn"
48                 })
49         public void happyPath() throws IOException {
50                 
51                 logStart();
52                 
53                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml"); 
54                 MockGetGenericVnfByIdWithPriority("skask", "lukewarm", 200, "VfModularity/VfModule-lukewarm.xml", 2);
55                 MockPutVfModuleIdNoResponse("skask", "PCRF", "lukewarm");
56                 
57                 String businessKey = UUID.randomUUID().toString();
58                 Map<String, Object> variables = new HashMap<String, Object>();
59                 variables.put("mso-request-id", "999-99-9999");
60                 variables.put("isDebugLogEnabled","true");
61                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
62                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
63                 
64                 Assert.assertTrue(isProcessEnded(businessKey));
65                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponse");
66                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponseCode");
67                 System.out.println("Subflow response code: " + responseCode);
68                 System.out.println("Subflow response: " + response);
69                 Assert.assertEquals(200, responseCode.intValue());
70                 
71                 logEnd();
72         }
73
74         /**
75          * Test the case where the GET to AAI returns a 404.
76          */
77         @Test   
78         @Deployment(resources = {
79                         "subprocess/CreateAAIVfModuleVolumeGroup.bpmn"
80                 })
81         public void badGet() throws IOException {
82                 
83                 logStart();
84                 
85                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml"); 
86                 MockGetVfModuleId("skask", ".*", "VfModularity/VfModule-supercool.xml", 404);
87                 
88                 String businessKey = UUID.randomUUID().toString();
89                 Map<String, Object> variables = new HashMap<String, Object>();
90                 variables.put("mso-request-id", "999-99-9999");
91                 variables.put("isDebugLogEnabled","true");
92                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
93                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
94                 
95                 Assert.assertTrue(isProcessEnded(businessKey));
96                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_getVfModuleResponse");
97                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_getVfModuleResponseCode");
98                 System.out.println("Subflow response code: " + responseCode);
99                 System.out.println("Subflow response: " + response);
100                 Assert.assertEquals(404, responseCode.intValue());
101                 
102                 logEnd();
103         }
104
105         /**
106          * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.
107          */
108         @Test   
109         @Deployment(resources = {
110                         "subprocess/CreateAAIVfModuleVolumeGroup.bpmn"
111                 })
112         public void badPut() throws IOException {
113                 
114                 logStart();
115                 
116                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml"); 
117                 MockGetVfModuleId("skask", "lukewarm", "VfModularity/VfModule-lukewarm.xml", 200);
118                 
119                 String businessKey = UUID.randomUUID().toString();
120                 Map<String, Object> variables = new HashMap<String, Object>();
121                 variables.put("mso-request-id", "999-99-9999");
122                 variables.put("isDebugLogEnabled","true");
123                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
124                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
125                 
126                 Assert.assertTrue(isProcessEnded(businessKey));
127                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponse");
128                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponseCode");
129                 System.out.println("Subflow response code: " + responseCode);
130                 System.out.println("Subflow response: " + response);
131                 Assert.assertEquals(404, responseCode.intValue());
132                 
133                 logEnd();
134         }
135 }
136