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