[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / UpdateAAIVfModuleTest.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.MockGetGenericVnfById;
24 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithPriority;
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
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.mock.FileUtil;
37
38 /**
39  * Unit tests for UpdateAAIVfModuleTest.bpmn.
40  */
41 public class UpdateAAIVfModuleTest extends WorkflowTest {
42                 
43         /**
44          * Test the happy path through the flow.
45          */
46         @Test   
47         @Deployment(resources = {
48                         "subprocess/UpdateAAIVfModule.bpmn"
49                 })
50         public void happyPath() throws IOException {
51                 logStart();
52                 
53                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml"); 
54                 MockGetGenericVnfByIdWithPriority("/skask/vf-modules/vf-module/supercool", 200, "VfModularity/VfModule-supercool.xml");
55                 MockPutGenericVnf("/skask/vf-modules/vf-module/supercool", "PCRF", 200);
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("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);
62                 invokeSubProcess("UpdateAAIVfModule", businessKey, variables);
63                 
64                 Assert.assertTrue(isProcessEnded(businessKey));
65                 String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponse");
66                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_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/UpdateAAIVfModule.bpmn"
80                 })
81         public void badGet() throws IOException {
82                 
83                 logStart();
84                 
85                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml"); 
86                 MockGetGenericVnfById("/skask/vf-modules/vf-module/.*", "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("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);
93                 invokeSubProcess("UpdateAAIVfModule", businessKey, variables);
94                 
95                 Assert.assertTrue(isProcessEnded(businessKey));
96                 String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_getVfModuleResponse");
97                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_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/UpdateAAIVfModule.bpmn"
111                 })
112         public void badPut() throws IOException {
113                 
114                 logStart();
115                 
116                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml"); 
117                 MockGetGenericVnfById_404("/skask/vf-modules/vf-module/supercool");
118                 MockGetGenericVnfById("/skask/vf-modules/vf-module/supercool", "VfModularity/VfModule-supercool.xml", 200);
119                 
120                 String businessKey = UUID.randomUUID().toString();
121                 Map<String, Object> variables = new HashMap<String, Object>();
122                 variables.put("mso-request-id", "999-99-9999");
123                 variables.put("isDebugLogEnabled","true");
124                 variables.put("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);
125                 invokeSubProcess("UpdateAAIVfModule", businessKey, variables);
126                 
127                 Assert.assertTrue(isProcessEnded(businessKey));
128                 String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponse");
129                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponseCode");
130                 System.out.println("Subflow response code: " + responseCode);
131                 System.out.println("Subflow response: " + response);
132                 Assert.assertEquals(404, responseCode.intValue());
133                 
134                 logEnd();
135         }
136 }
137