3dd2ac957c902bd345d43393de512c4a5f4e8d57
[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  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License"); 
10  * you may not use this file except in compliance with the License. 
11  * You may obtain a copy of the License at 
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0 
14  * 
15  * Unless required by applicable law or agreed to in writing, software 
16  * distributed under the License is distributed on an "AS IS" BASIS, 
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
18  * See the License for the specific language governing permissions and 
19  * limitations under the License. 
20  * ============LICENSE_END========================================================= 
21  */ 
22
23 package org.onap.so.bpmn.common;
24
25 import static org.onap.so.bpmn.mock.StubResponseAAI.MockAAIVfModuleBadPatch;
26 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetGenericVnfById;
27 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithPriority;
28 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetGenericVnfById_404;
29 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPatchVfModuleId;
30 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
31
32 import java.io.IOException;
33 import java.util.HashMap;
34 import java.util.Map;
35 import java.util.UUID;
36
37 import org.camunda.bpm.engine.test.Deployment;
38 import org.junit.Assert;
39 import org.junit.Ignore;
40 import org.junit.Test;
41 import org.onap.so.BaseIntegrationTest;
42 import org.onap.so.bpmn.mock.FileUtil;
43 import org.onap.so.logger.MsoLogger;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47 /**
48  * Unit tests for UpdateAAIVfModuleTest.bpmn.
49  */
50
51 public class UpdateAAIVfModuleIT extends BaseIntegrationTest {
52         
53         Logger logger = LoggerFactory.getLogger(CreateAAIVfModuleIT.class);
54         
55                 
56         /**
57          * Test the happy path through the flow.
58          */
59         @Test   
60         
61         public void happyPath() throws IOException {
62                 logStart();
63                 
64                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml"); 
65                 MockGetGenericVnfByIdWithPriority("/skask/vf-modules/vf-module/supercool", 200, "VfModularity/VfModule-supercool.xml");
66                 MockPutGenericVnf("/skask/vf-modules/vf-module/supercool", "PCRF", 200);
67                 MockPatchVfModuleId("skask", "supercool");
68                 
69                 String businessKey = UUID.randomUUID().toString();
70                 Map<String, Object> variables = new HashMap<>();
71                 variables.put("mso-request-id", UUID.randomUUID().toString());
72                 variables.put("isDebugLogEnabled","true");
73                 variables.put("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);
74                 invokeSubProcess("UpdateAAIVfModule", businessKey, variables);
75                 
76                 Assert.assertTrue(isProcessEnded(businessKey));
77                 String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponse");
78                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponseCode");
79                 logger.debug("Subflow response code: {}", responseCode);
80                 logger.debug("Subflow response: {}", response);
81                 Assert.assertEquals(200, responseCode.intValue());
82                 
83                 logEnd();
84         }
85
86         /**
87          * Test the case where the GET to AAI returns a 404.
88          */
89         @Test   
90         
91         public void badGet() throws IOException {
92                 
93                 logStart();
94                 
95                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml"); 
96                 MockGetGenericVnfById("/skask/vf-modules/vf-module/.*", "VfModularity/VfModule-supercool.xml", 404);
97                 
98                 String businessKey = UUID.randomUUID().toString();
99                 Map<String, Object> variables = new HashMap<>();
100                 variables.put("mso-request-id", UUID.randomUUID().toString());
101                 variables.put("isDebugLogEnabled","true");
102                 variables.put("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);
103                 invokeSubProcess("UpdateAAIVfModule", businessKey, variables);
104                 
105                 Assert.assertTrue(isProcessEnded(businessKey));
106                 String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_getVfModuleResponse");
107                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_getVfModuleResponseCode");
108                 logger.debug("Subflow response code: {}", responseCode);
109                 logger.debug("Subflow response: {}", response);
110                 Assert.assertEquals(404, responseCode.intValue());
111                 
112                 logEnd();
113         }
114
115         /**
116          * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.
117          */
118         @Test   
119         
120         public void badPatch() throws IOException {
121                 
122                 logStart();
123                 
124                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml"); 
125                 MockGetGenericVnfById_404("/skask/vf-modules/vf-module/supercool");
126                 MockGetGenericVnfById("/skask/vf-modules/vf-module/supercool", "VfModularity/VfModule-supercool.xml", 200);
127                 MockAAIVfModuleBadPatch("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/skask/vf-modules/vf-module/supercool", 404);
128                 
129                 String businessKey = UUID.randomUUID().toString();
130                 Map<String, Object> variables = new HashMap<>();
131                 variables.put("mso-request-id", UUID.randomUUID().toString());
132                 variables.put("isDebugLogEnabled","true");
133                 variables.put("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);
134                 invokeSubProcess("UpdateAAIVfModule", businessKey, variables);
135                 
136                 Assert.assertTrue(isProcessEnded(businessKey));
137                 String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponse");
138                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponseCode");
139                 logger.debug("Subflow response code: {}", responseCode);
140                 logger.debug("Subflow response: {}", response);
141                 Assert.assertEquals(404, responseCode.intValue());
142                 
143                 logEnd();
144         }
145 }
146