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