Replaced all tabs with spaces in java and pom.xml
[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 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.mock.FileUtil;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 /**
45  * Unit tests for UpdateAAIVfModuleTest.bpmn.
46  */
47
48 public class UpdateAAIVfModuleIT extends BaseIntegrationTest {
49
50     Logger logger = LoggerFactory.getLogger(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 updateAAIVfModuleRequest =
62                 FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml");
63         MockGetGenericVnfByIdWithPriority(wireMockServer, "/skask/vf-modules/vf-module/supercool", 200,
64                 "VfModularity/VfModule-supercool.xml");
65         MockPutGenericVnf(wireMockServer, "/skask/vf-modules/vf-module/supercool", "PCRF", 200);
66         MockPatchVfModuleId(wireMockServer, "skask", "supercool");
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("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);
73         invokeSubProcess("UpdateAAIVfModule", businessKey, variables);
74
75         Assert.assertTrue(isProcessEnded(businessKey));
76         String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponse");
77         Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponseCode");
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 case where the GET to AAI returns a 404.
87      */
88     @Test
89
90     public void badGet() throws IOException {
91
92         logStart();
93
94         String updateAAIVfModuleRequest =
95                 FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml");
96         MockGetGenericVnfById(wireMockServer, "/skask/vf-modules/vf-module/.*", "VfModularity/VfModule-supercool.xml",
97                 404);
98
99         String businessKey = UUID.randomUUID().toString();
100         Map<String, Object> variables = new HashMap<>();
101         variables.put("mso-request-id", UUID.randomUUID().toString());
102         variables.put("isDebugLogEnabled", "true");
103         variables.put("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);
104         invokeSubProcess("UpdateAAIVfModule", businessKey, variables);
105
106         Assert.assertTrue(isProcessEnded(businessKey));
107         String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_getVfModuleResponse");
108         Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_getVfModuleResponseCode");
109         logger.debug("Subflow response code: {}", responseCode);
110         logger.debug("Subflow response: {}", response);
111         Assert.assertEquals(404, responseCode.intValue());
112
113         logEnd();
114     }
115
116     /**
117      * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.
118      */
119     @Test
120
121     public void badPatch() throws IOException {
122
123         logStart();
124
125         String updateAAIVfModuleRequest =
126                 FileUtil.readResourceFile("__files/VfModularity/UpdateAAIVfModuleRequest.xml");
127         MockGetGenericVnfById_404(wireMockServer, "/skask/vf-modules/vf-module/supercool");
128         MockGetGenericVnfById(wireMockServer, "/skask/vf-modules/vf-module/supercool",
129                 "VfModularity/VfModule-supercool.xml", 200);
130         MockAAIVfModuleBadPatch(wireMockServer,
131                 "/aai/v[0-9]+/network/generic-vnfs/generic-vnf/skask/vf-modules/vf-module/supercool", 404);
132
133         String businessKey = UUID.randomUUID().toString();
134         Map<String, Object> variables = new HashMap<>();
135         variables.put("mso-request-id", UUID.randomUUID().toString());
136         variables.put("isDebugLogEnabled", "true");
137         variables.put("UpdateAAIVfModuleRequest", updateAAIVfModuleRequest);
138         invokeSubProcess("UpdateAAIVfModule", businessKey, variables);
139
140         Assert.assertTrue(isProcessEnded(businessKey));
141         String response = (String) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponse");
142         Integer responseCode = (Integer) getVariableFromHistory(businessKey, "UAAIVfMod_updateVfModuleResponseCode");
143         logger.debug("Subflow response code: {}", responseCode);
144         logger.debug("Subflow response: {}", response);
145         Assert.assertEquals(404, responseCode.intValue());
146
147         logEnd();
148     }
149 }
150