e2942c9db5cfeec7e746d2580575a2ba0f503694
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / CreateAAIVfModuleVolumeGroupTest.java
1 /*- \r
2  * ============LICENSE_START======================================================= \r
3  * OPENECOMP - MSO \r
4  * ================================================================================ \r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. \r
6  * ================================================================================ \r
7  * Licensed under the Apache License, Version 2.0 (the "License"); \r
8  * you may not use this file except in compliance with the License. \r
9  * You may obtain a copy of the License at \r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0 \r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software \r
14  * distributed under the License is distributed on an "AS IS" BASIS, \r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \r
16  * See the License for the specific language governing permissions and \r
17  * limitations under the License. \r
18  * ============LICENSE_END========================================================= \r
19  */ \r
20 \r
21 package org.openecomp.mso.bpmn.common;\r
22 \r
23 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithPriority;\r
24 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetVfModuleId;\r
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutVfModuleIdNoResponse;\r
26 \r
27 import java.io.IOException;\r
28 import java.util.HashMap;\r
29 import java.util.Map;\r
30 import java.util.UUID;\r
31 \r
32 import org.camunda.bpm.engine.test.Deployment;\r
33 import org.junit.Assert;\r
34 import org.junit.Test;\r
35 import org.openecomp.mso.bpmn.mock.FileUtil;\r
36 \r
37 /**\r
38  * Unit tests for CreateAAIVfModuleVolumeGroup.bpmn.\r
39  */\r
40 public class CreateAAIVfModuleVolumeGroupTest extends WorkflowTest {\r
41                 \r
42         /**\r
43          * Test the happy path through the flow.\r
44          */\r
45         @Test   \r
46         @Deployment(resources = {\r
47                         "subprocess/CreateAAIVfModuleVolumeGroup.bpmn"\r
48                 })\r
49         public void happyPath() throws IOException {\r
50                 \r
51                 logStart();\r
52                 \r
53                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml"); \r
54                 MockGetGenericVnfByIdWithPriority("skask", "lukewarm", 200, "VfModularity/VfModule-lukewarm.xml", 2);\r
55                 MockPutVfModuleIdNoResponse("skask", "PCRF", "lukewarm");\r
56                 \r
57                 String businessKey = UUID.randomUUID().toString();\r
58                 Map<String, Object> variables = new HashMap<String, Object>();\r
59                 variables.put("mso-request-id", "999-99-9999");\r
60                 variables.put("isDebugLogEnabled","true");\r
61                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);\r
62                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);\r
63                 \r
64                 Assert.assertTrue(isProcessEnded(businessKey));\r
65                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponse");\r
66                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponseCode");\r
67                 System.out.println("Subflow response code: " + responseCode);\r
68                 System.out.println("Subflow response: " + response);\r
69                 Assert.assertEquals(200, responseCode.intValue());\r
70                 \r
71                 logEnd();\r
72         }\r
73 \r
74         /**\r
75          * Test the case where the GET to AAI returns a 404.\r
76          */\r
77         @Test   \r
78         @Deployment(resources = {\r
79                         "subprocess/CreateAAIVfModuleVolumeGroup.bpmn"\r
80                 })\r
81         public void badGet() throws IOException {\r
82                 \r
83                 logStart();\r
84                 \r
85                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml"); \r
86                 MockGetVfModuleId("skask", ".*", "VfModularity/VfModule-supercool.xml", 404);\r
87                 \r
88                 String businessKey = UUID.randomUUID().toString();\r
89                 Map<String, Object> variables = new HashMap<String, Object>();\r
90                 variables.put("mso-request-id", "999-99-9999");\r
91                 variables.put("isDebugLogEnabled","true");\r
92                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);\r
93                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);\r
94                 \r
95                 Assert.assertTrue(isProcessEnded(businessKey));\r
96                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_getVfModuleResponse");\r
97                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_getVfModuleResponseCode");\r
98                 System.out.println("Subflow response code: " + responseCode);\r
99                 System.out.println("Subflow response: " + response);\r
100                 Assert.assertEquals(404, responseCode.intValue());\r
101                 \r
102                 logEnd();\r
103         }\r
104 \r
105         /**\r
106          * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.\r
107          */\r
108         @Test   \r
109         @Deployment(resources = {\r
110                         "subprocess/CreateAAIVfModuleVolumeGroup.bpmn"\r
111                 })\r
112         public void badPatch() throws IOException {\r
113                 \r
114                 logStart();\r
115                 \r
116                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml"); \r
117                 MockGetVfModuleId("skask", "lukewarm", "VfModularity/VfModule-lukewarm.xml", 200);\r
118 \r
119                 String businessKey = UUID.randomUUID().toString();\r
120                 Map<String, Object> variables = new HashMap<String, Object>();\r
121                 variables.put("mso-request-id", "999-99-9999");\r
122                 variables.put("isDebugLogEnabled","true");\r
123                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);\r
124                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);\r
125                 \r
126                 Assert.assertTrue(isProcessEnded(businessKey));\r
127                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponse");\r
128                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponseCode");\r
129                 System.out.println("Subflow response code: " + responseCode);\r
130                 System.out.println("Subflow response: " + response);\r
131                 Assert.assertEquals(404, responseCode.intValue());\r
132                 \r
133                 logEnd();\r
134         }\r
135 }\r
136 \r