1573c8f7579ab06682516e542bca350af4ba18ac
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / UpdateAAIGenericVnfTest.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.MockGetGenericVnfByIdWithDepth;\r
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;\r
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchGenericVnf;\r
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf;\r
28 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf_Bad;\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.core.WorkflowException;\r
39 import org.openecomp.mso.bpmn.mock.FileUtil;\r
40 \r
41 /**\r
42  * Unit tests for UpdateAAIGenericVnf bpmn.\r
43  */\r
44 public class UpdateAAIGenericVnfTest extends WorkflowTest {\r
45                 \r
46         /**\r
47          * Test the happy path through the flow.\r
48          */\r
49         @Test   \r
50         @Deployment(resources = {\r
51                         "subprocess/UpdateAAIGenericVnf.bpmn"\r
52                 })\r
53         public void happyPath() throws IOException {\r
54                 logStart();\r
55                 \r
56                 String updateAAIGenericVnfRequest =     FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml"); \r
57                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");\r
58                 MockPutGenericVnf("/skask", 200);\r
59                 MockPatchGenericVnf("skask");\r
60                 \r
61                 String businessKey = UUID.randomUUID().toString();\r
62                 Map<String, Object> variables = new HashMap<String, Object>();\r
63                 variables.put("mso-request-id", "999-99-9999");\r
64                 variables.put("isDebugLogEnabled","true");\r
65                 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);\r
66                 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);\r
67                 \r
68                 Assert.assertTrue(isProcessEnded(businessKey));\r
69                 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponse");\r
70                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponseCode");\r
71                 System.out.println("Subflow response code: " + responseCode);\r
72                 System.out.println("Subflow response: " + response);\r
73                 Assert.assertEquals(200, responseCode.intValue());\r
74                 \r
75                 logEnd();\r
76         }\r
77 \r
78         /**\r
79          * Test the happy path through the flow.\r
80          */\r
81         @Test   \r
82         @Deployment(resources = {\r
83                         "subprocess/UpdateAAIGenericVnf.bpmn"\r
84                 })\r
85         public void personaMismatch() throws IOException {\r
86                 \r
87                 logStart();\r
88                 \r
89                 String updateAAIGenericVnfRequest =     FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml"); \r
90                 updateAAIGenericVnfRequest = updateAAIGenericVnfRequest.replaceFirst("introvert", "extrovert");\r
91                 \r
92                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");\r
93                 \r
94                 String businessKey = UUID.randomUUID().toString();\r
95                 Map<String, Object> variables = new HashMap<String, Object>();\r
96                 variables.put("mso-request-id", "999-99-9999");\r
97                 variables.put("isDebugLogEnabled","true");\r
98                 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);\r
99                 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);\r
100                 \r
101                 Assert.assertTrue(isProcessEnded(businessKey));\r
102                 WorkflowException workflowException = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");\r
103                 System.out.println("Workflow Exception: " + workflowException);\r
104                 Assert.assertNotNull(workflowException);\r
105                 \r
106                 logEnd();\r
107         }\r
108 \r
109         /**\r
110          * Test the case where the GET to AAI returns a 404.\r
111          */\r
112         @Test   \r
113         @Deployment(resources = {\r
114                         "subprocess/UpdateAAIGenericVnf.bpmn"\r
115                 })\r
116         public void badGet() throws IOException {\r
117                 \r
118                 logStart();\r
119                 \r
120                 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml"); \r
121                 \r
122                 MockGetGenericVnfById_404("skask[?]depth=1");\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("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);\r
129                 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);\r
130                 \r
131                 Assert.assertTrue(isProcessEnded(businessKey));\r
132                 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_getGenericVnfResponse");\r
133                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_getGenericVnfResponseCode");\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
142          * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.\r
143          */\r
144         @Test   \r
145         @Deployment(resources = {\r
146                         "subprocess/UpdateAAIGenericVnf.bpmn"\r
147                 })\r
148         public void badPatch() throws IOException {\r
149                 \r
150                 logStart();\r
151                 \r
152                 String updateAAIGenericVnfRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIGenericVnfRequest.xml"); \r
153                 \r
154                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");\r
155                 MockPutGenericVnf_Bad("skask", 404);\r
156                 MockAAIVfModuleBadPatch("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/skask", 404);\r
157                 \r
158                 String businessKey = UUID.randomUUID().toString();\r
159                 Map<String, Object> variables = new HashMap<String, Object>();\r
160                 variables.put("mso-request-id", "999-99-9999");\r
161                 variables.put("isDebugLogEnabled","true");\r
162                 variables.put("UpdateAAIGenericVnfRequest", updateAAIGenericVnfRequest);\r
163                 invokeSubProcess("UpdateAAIGenericVnf", businessKey, variables);\r
164                 \r
165                 Assert.assertTrue(isProcessEnded(businessKey));\r
166                 String response = (String) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponse");\r
167                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIGenVnf_updateGenericVnfResponseCode");\r
168                 System.out.println("Subflow response code: " + responseCode);\r
169                 System.out.println("Subflow response: " + response);\r
170                 Assert.assertEquals(404, responseCode.intValue());\r
171                 \r
172                 logEnd();\r
173         }\r
174 }\r
175 \r