d081fcc7f6d47513d87f7b35b85ddc0e52806a53
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / UpdateAAIVfModuleTest.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.MockAAIVfModuleBadPatch;\r
24 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById;\r
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithPriority;\r
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;\r
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchVfModuleId;\r
28 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf;\r
29 \r
30 import java.io.IOException;\r
31 import java.util.HashMap;\r
32 import java.util.Map;\r
33 import java.util.UUID;\r
34 \r
35 import org.camunda.bpm.engine.test.Deployment;\r
36 import org.junit.Assert;\r
37 import org.junit.Test;\r
38 import org.openecomp.mso.bpmn.mock.FileUtil;\r
39 \r
40 /**\r
41  * Unit tests for UpdateAAIVfModuleTest.bpmn.\r
42  */\r
43 public class UpdateAAIVfModuleTest extends WorkflowTest {\r
44                 \r
45         /**\r
46          * Test the happy path through the flow.\r
47          */\r
48         @Test   \r
49         @Deployment(resources = {\r
50                         "subprocess/UpdateAAIVfModule.bpmn"\r
51                 })\r
52         public void happyPath() throws IOException {\r
53                 logStart();\r
54                 \r
55                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml"); \r
56                 MockGetGenericVnfByIdWithPriority("/skask/vf-modules/vf-module/supercool", 200, "VfModularity/VfModule-supercool.xml");\r
57                 MockPutGenericVnf("/skask/vf-modules/vf-module/supercool", "PCRF", 200);\r
58                 MockPatchVfModuleId("skask", "supercool");\r
59                 \r
60                 String businessKey = UUID.randomUUID().toString();\r
61                 Map<String, Object> variables = new HashMap<String, Object>();\r
62                 variables.put("mso-request-id", "999-99-9999");\r
63                 variables.put("isDebugLogEnabled","true");\r
64                 variables.put("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);\r
65                 invokeSubProcess("UpdateAAIVfModule", businessKey, variables);\r
66                 \r
67                 Assert.assertTrue(isProcessEnded(businessKey));\r
68                 String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponse");\r
69                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponseCode");\r
70                 System.out.println("Subflow response code: " + responseCode);\r
71                 System.out.println("Subflow response: " + response);\r
72                 Assert.assertEquals(200, responseCode.intValue());\r
73                 \r
74                 logEnd();\r
75         }\r
76 \r
77         /**\r
78          * Test the case where the GET to AAI returns a 404.\r
79          */\r
80         @Test   \r
81         @Deployment(resources = {\r
82                         "subprocess/UpdateAAIVfModule.bpmn"\r
83                 })\r
84         public void badGet() throws IOException {\r
85                 \r
86                 logStart();\r
87                 \r
88                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml"); \r
89                 MockGetGenericVnfById("/skask/vf-modules/vf-module/.*", "VfModularity/VfModule-supercool.xml", 404);\r
90                 \r
91                 String businessKey = UUID.randomUUID().toString();\r
92                 Map<String, Object> variables = new HashMap<String, Object>();\r
93                 variables.put("mso-request-id", "999-99-9999");\r
94                 variables.put("isDebugLogEnabled","true");\r
95                 variables.put("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);\r
96                 invokeSubProcess("UpdateAAIVfModule", businessKey, variables);\r
97                 \r
98                 Assert.assertTrue(isProcessEnded(businessKey));\r
99                 String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_getVfModuleResponse");\r
100                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_getVfModuleResponseCode");\r
101                 System.out.println("Subflow response code: " + responseCode);\r
102                 System.out.println("Subflow response: " + response);\r
103                 Assert.assertEquals(404, responseCode.intValue());\r
104                 \r
105                 logEnd();\r
106         }\r
107 \r
108         /**\r
109          * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.\r
110          */\r
111         @Test   \r
112         @Deployment(resources = {\r
113                         "subprocess/UpdateAAIVfModule.bpmn"\r
114                 })\r
115         public void badPatch() throws IOException {\r
116                 \r
117                 logStart();\r
118                 \r
119                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml"); \r
120                 MockGetGenericVnfById_404("/skask/vf-modules/vf-module/supercool");\r
121                 MockGetGenericVnfById("/skask/vf-modules/vf-module/supercool", "VfModularity/VfModule-supercool.xml", 200);\r
122                 MockAAIVfModuleBadPatch("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/skask/vf-modules/vf-module/supercool", 404);\r
123                 \r
124                 String businessKey = UUID.randomUUID().toString();\r
125                 Map<String, Object> variables = new HashMap<String, Object>();\r
126                 variables.put("mso-request-id", "999-99-9999");\r
127                 variables.put("isDebugLogEnabled","true");\r
128                 variables.put("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);\r
129                 invokeSubProcess("UpdateAAIVfModule", businessKey, variables);\r
130                 \r
131                 Assert.assertTrue(isProcessEnded(businessKey));\r
132                 String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponse");\r
133                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponseCode");\r
134                 System.out.println("Subflow response code: " + responseCode);\r
135                 System.out.println("Subflow response: " + response);\r
136                 Assert.assertEquals(404, responseCode.intValue());\r
137                 \r
138                 logEnd();\r
139         }\r
140 }\r
141 \r