39a7e0c74b3b9a7eab333fe6356063a1f3e4049c
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / common / CreateAAIVfModuleVolumeGroupIT.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.MockGetGenericVnfByIdWithPriority;
26 import static org.onap.so.bpmn.mock.StubResponseAAI.MockGetVfModuleId;
27 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutVfModuleId;
28 import static org.onap.so.bpmn.mock.StubResponseAAI.MockPutVfModuleIdNoResponse;
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.junit.Assert;
36 import org.junit.Test;
37 import org.onap.so.BaseIntegrationTest;
38 import org.onap.so.bpmn.mock.FileUtil;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 /**
43  * Unit tests for CreateAAIVfModuleVolumeGroup.bpmn.
44  */
45
46 public class CreateAAIVfModuleVolumeGroupIT extends BaseIntegrationTest {
47
48         Logger logger = LoggerFactory.getLogger(CreateAAIVfModuleVolumeGroupIT.class);
49
50         /**
51          * Test the happy path through the flow.
52          */
53         @Test
54         public void happyPath() throws IOException {
55
56                 logStart();
57
58                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml");
59                 MockGetGenericVnfByIdWithPriority(wireMockServer, "skask", "lukewarm", 200, "VfModularity/VfModule-lukewarm.xml", 2);
60                 MockPutVfModuleIdNoResponse(wireMockServer, "skask", "PCRF", "lukewarm");
61
62                 String businessKey = UUID.randomUUID().toString();
63                 Map<String, Object> variables = new HashMap<>();
64                 variables.put("mso-request-id", "999-99-9999");
65                 variables.put("isDebugLogEnabled","true");
66                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
67                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
68
69                 Assert.assertTrue(isProcessEnded(businessKey));
70                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponse");
71                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponseCode");
72                 logger.debug("Subflow response code: {}", responseCode);
73                 logger.debug("Subflow response: {}", response);
74                 Assert.assertEquals(200, responseCode.intValue());
75
76                 logEnd();
77         }
78
79         /**
80          * Test the case where the GET to AAI returns a 404.
81          */
82         @Test
83         public void badGet() throws IOException {
84
85                 logStart();
86
87                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml");
88                 MockGetVfModuleId(wireMockServer, "skask", ".*", "VfModularity/VfModule-supercool.xml", 404);
89
90                 String businessKey = UUID.randomUUID().toString();
91                 Map<String, Object> variables = new HashMap<>();
92                 variables.put("mso-request-id", "999-99-9999");
93                 variables.put("isDebugLogEnabled","true");
94                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
95                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
96                 Assert.assertTrue(isProcessEnded(businessKey));
97                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_getVfModuleResponse");
98                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_getVfModuleResponseCode");
99                 logger.debug("Subflow response code: {}", responseCode);
100                 logger.debug("Subflow response: {}", response);
101                 Assert.assertEquals(404, responseCode.intValue());
102
103                 logEnd();
104         }
105
106         /**
107          * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.
108          */
109         @Test
110         public void badPatch() throws IOException {
111
112                 logStart();
113
114                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml");
115                 MockGetVfModuleId(wireMockServer, "skask", "lukewarm", "VfModularity/VfModule-lukewarm.xml", 200);
116                 MockPutVfModuleId(wireMockServer, "skask", "lukewarm", 404);
117
118                 String businessKey = UUID.randomUUID().toString();
119                 Map<String, Object> variables = new HashMap<>();
120                 variables.put("mso-request-id", "999-99-9999");
121                 variables.put("isDebugLogEnabled","true");
122                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
123                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
124
125                 Assert.assertTrue(isProcessEnded(businessKey));
126                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponse");
127                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponseCode");
128                 logger.debug("Subflow response code: {}", responseCode);
129                 logger.debug("Subflow response: {}", response);
130                 Assert.assertEquals(404, responseCode.intValue());
131
132                 logEnd();
133         }
134 }
135