Containerization feature of SO
[so.git] / adapters / mso-openstack-adapters / src / test / java / org / onap / so / adapters / vnf / MsoVnfPluginAdapterImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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.adapters.vnf;
22
23 import org.apache.http.HttpStatus;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.ExpectedException;
27 import org.onap.so.adapters.vnf.exceptions.VnfException;
28 import org.onap.so.entity.MsoRequest;
29 import org.onap.so.openstack.beans.VnfRollback;
30 import org.springframework.beans.factory.annotation.Autowired;
31
32 import javax.xml.ws.Holder;
33 import java.util.HashMap;
34 import java.util.Map;
35
36 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
37 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
38 import static com.github.tomakehurst.wiremock.client.WireMock.get;
39 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
40 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
41 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
42 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_404;
43 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
44
45 public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils {
46
47     @Rule
48     public ExpectedException expectedException = ExpectedException.none();
49
50     @Autowired
51     MsoVnfPluginAdapterImpl msoVnfPluginAdapter;
52
53     String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
54
55     @Test
56     public void createVfModule_ModelCustUuidIsNull() throws Exception {
57         expectedException.expect(VnfException.class);
58         MsoRequest msoRequest = getMsoRequest();
59         Map<String, String> map = new HashMap<>();
60         map.put("key1", "value1");
61         msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
62                 "volumeGroupHeatStackId|1", "baseVfHeatStackId", null, map,
63                 Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
64                 new Holder<VnfRollback>());
65     }
66
67     @Test
68     public void createVfModule_ModelCustUuidIsNotFound() throws Exception {
69         expectedException.expect(VnfException.class);
70         MsoRequest msoRequest = getMsoRequest();
71         Map<String, String> map = new HashMap<>();
72         map.put("key1", "value1");
73         msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
74                 "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map,
75                 Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
76                 new Holder<VnfRollback>());
77     }
78
79     @Test
80     public void createVfModule_VduException() throws Exception {
81         expectedException.expect(VnfException.class);
82         MsoRequest msoRequest = getMsoRequest();
83         Map<String, String> map = new HashMap<>();
84         map.put("key1", "value1");
85         msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
86                 "volumeGroupHeatStackId|1", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
87                 Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
88                 new Holder<VnfRollback>());
89     }
90
91     @Test
92     public void createVfModule_INSTANTIATED() throws Exception {
93         mockOpenStackResponseAccess(wireMockPort);
94         mockOpenStackGetStackVfModule_200();
95         MsoRequest msoRequest = getMsoRequest();
96         Map<String, String> map = new HashMap<>();
97         map.put("key1", "value1");
98         msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
99                 "volumeGroupHeatStackId|1", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
100                 Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
101                 new Holder<VnfRollback>());
102     }
103
104     @Test
105     public void createVfModule_queryVduNotFoundWithVolumeGroupId() throws Exception {
106         expectedException.expect(VnfException.class);
107         mockOpenStackResponseAccess(wireMockPort);
108         MsoRequest msoRequest = getMsoRequest();
109         Map<String, String> map = new HashMap<>();
110         map.put("key1", "value1");
111         msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
112                 "volumeGroupHeatStackId|1", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
113                 Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
114                 new Holder<VnfRollback>());
115     }
116
117     @Test
118     public void createVfModule_CreateVduException() throws Exception {
119         expectedException.expect(VnfException.class);
120         mockOpenStackResponseAccess(wireMockPort);
121         mockOpenStackGetStackVfModule_404();
122         stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId"))
123                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
124                         .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json")
125                         .withStatus(HttpStatus.SC_OK)));
126         MsoRequest msoRequest = getMsoRequest();
127         Map<String, String> map = new HashMap<>();
128         map.put("key1", "value1");
129         msoVnfPluginAdapter.createVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
130                 "volumeGroupHeatStackId", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
131                 Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
132                 new Holder<VnfRollback>());
133     }
134
135     @Test
136     public void deleteVfModule_QueryVduException() throws Exception {
137         expectedException.expect(VnfException.class);
138         MsoRequest msoRequest = getMsoRequest();
139         msoVnfPluginAdapter.deleteVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
140                 new Holder<Map<String, String>>());
141     }
142
143     @Test
144     public void deleteVfModule_DeleteVduException() throws Exception {
145         expectedException.expect(VnfException.class);
146         mockOpenStackResponseAccess(wireMockPort);
147         mockOpenStackGetStackVfModule_200();
148         stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vSAMP12"))
149                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
150                         .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json")
151                         .withStatus(HttpStatus.SC_OK)));
152         stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
153                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
154                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
155         MsoRequest msoRequest = getMsoRequest();
156         msoVnfPluginAdapter.deleteVfModule("mtn13", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
157                 new Holder<Map<String, String>>());
158     }
159
160     private MsoRequest getMsoRequest() {
161         MsoRequest msoRequest = new MsoRequest();
162         msoRequest.setRequestId("12345");
163         msoRequest.setServiceInstanceId("12345");
164         return msoRequest;
165     }
166
167 }