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