b78c5b8aad1f5bd5651018d49679470a3ec6b01f
[so.git] /
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 import java.io.IOException;
30 import java.util.HashMap;
31 import java.util.Map;
32 import java.util.UUID;
33 import org.junit.Assert;
34 import org.junit.Test;
35 import org.onap.so.BaseIntegrationTest;
36 import org.onap.so.bpmn.mock.FileUtil;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 /**
41  * Unit tests for CreateAAIVfModuleVolumeGroup.bpmn.
42  */
43
44 public class CreateAAIVfModuleVolumeGroupIT extends BaseIntegrationTest {
45
46     Logger logger = LoggerFactory.getLogger(CreateAAIVfModuleVolumeGroupIT.class);
47
48     /**
49      * Test the happy path through the flow.
50      */
51     @Test
52     public void happyPath() throws IOException {
53
54         logStart();
55
56         String updateAAIVfModuleRequest =
57                 FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml");
58         MockGetGenericVnfByIdWithPriority(wireMockServer, "skask", "lukewarm", 200,
59                 "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 =
88                 FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml");
89         MockGetVfModuleId(wireMockServer, "skask", ".*", "VfModularity/VfModule-supercool.xml", 404);
90
91         String businessKey = UUID.randomUUID().toString();
92         Map<String, Object> variables = new HashMap<>();
93         variables.put("mso-request-id", "999-99-9999");
94         variables.put("isDebugLogEnabled", "true");
95         variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
96         invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
97         Assert.assertTrue(isProcessEnded(businessKey));
98         String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_getVfModuleResponse");
99         Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_getVfModuleResponseCode");
100         logger.debug("Subflow response code: {}", responseCode);
101         logger.debug("Subflow response: {}", response);
102         Assert.assertEquals(404, responseCode.intValue());
103
104         logEnd();
105     }
106
107     /**
108      * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.
109      */
110     @Test
111     public void badPatch() throws IOException {
112
113         logStart();
114
115         String updateAAIVfModuleRequest =
116                 FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml");
117         MockGetVfModuleId(wireMockServer, "skask", "lukewarm", "VfModularity/VfModule-lukewarm.xml", 200);
118         MockPutVfModuleId(wireMockServer, "skask", "lukewarm", 404);
119
120         String businessKey = UUID.randomUUID().toString();
121         Map<String, Object> variables = new HashMap<>();
122         variables.put("mso-request-id", "999-99-9999");
123         variables.put("isDebugLogEnabled", "true");
124         variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
125         invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
126
127         Assert.assertTrue(isProcessEnded(businessKey));
128         String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponse");
129         Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponseCode");
130         logger.debug("Subflow response code: {}", responseCode);
131         logger.debug("Subflow response: {}", response);
132         Assert.assertEquals(404, responseCode.intValue());
133
134         logEnd();
135     }
136 }
137