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