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