50272dca20cf5f99b9ad448afc8306060ef4fe25
[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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
27 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
28 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_404;
29 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
30
31 import java.util.HashMap;
32 import java.util.Map;
33
34 import javax.xml.ws.Holder;
35
36 import org.apache.http.HttpStatus;
37 import org.junit.Rule;
38 import org.junit.Test;
39 import org.junit.rules.ExpectedException;
40 import org.onap.so.adapters.vnf.exceptions.VnfException;
41 import org.onap.so.entity.MsoRequest;
42 import org.onap.so.openstack.beans.VnfRollback;
43 import org.springframework.beans.factory.annotation.Autowired;
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, Object> map = new HashMap<>();
60         map.put("key1", "value1");
61         msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "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, Object> map = new HashMap<>();
72         map.put("key1", "value1");
73         msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "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, Object> map = new HashMap<>();
84         map.put("key1", "value1");
85         msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "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(wireMockServer, wireMockPort);
94         mockOpenStackGetStackVfModule_200(wireMockServer);
95
96         MsoRequest msoRequest = getMsoRequest();
97         Map<String, Object> map = new HashMap<>();
98         map.put("key1", "value1");
99         msoVnfPluginAdapter.createVfModule("MTN13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD",
100                 null, "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
101                 Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
102                 new Holder<VnfRollback>());
103     }
104
105     @Test
106     public void createVfModule_queryVduNotFoundWithVolumeGroupId() throws Exception {
107         expectedException.expect(VnfException.class);
108         mockOpenStackResponseAccess(wireMockServer, wireMockPort);
109         MsoRequest msoRequest = getMsoRequest();
110         Map<String, Object> map = new HashMap<>();
111         map.put("key1", "value1");
112         msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD",
113                 "volumeGroupHeatStackId|1", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
114                 Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
115                 new Holder<VnfRollback>());
116     }
117
118     @Test
119     public void createVfModule_CreateVduException() throws Exception {
120         expectedException.expect(VnfException.class);
121         mockOpenStackResponseAccess(wireMockServer, wireMockPort);
122         mockOpenStackGetStackVfModule_404(wireMockServer);
123         wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId"))
124                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
125                         .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json")
126                         .withStatus(HttpStatus.SC_OK)));
127         MsoRequest msoRequest = getMsoRequest();
128         Map<String, Object> map = new HashMap<>();
129         map.put("key1", "value1");
130         msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD",
131                 "volumeGroupHeatStackId", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map,
132                 Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(),
133                 new Holder<VnfRollback>());
134     }
135
136     @Test
137     public void deleteVfModule_QueryVduException() throws Exception {
138         expectedException.expect(VnfException.class);
139         MsoRequest msoRequest = getMsoRequest();
140         msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
141                 new Holder<Map<String, String>>());
142     }
143
144     @Test
145     public void deleteVfModule_DeleteVduException() throws Exception {
146         expectedException.expect(VnfException.class);
147         mockOpenStackResponseAccess(wireMockServer, wireMockPort);
148         mockOpenStackGetStackVfModule_200(wireMockServer);
149         wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vSAMP12"))
150                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
151                         .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json")
152                         .withStatus(HttpStatus.SC_OK)));
153         wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"))
154                 .willReturn(aResponse().withHeader("Content-Type", "application/json")
155                         .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
156         MsoRequest msoRequest = getMsoRequest();
157         msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest,
158                 new Holder<Map<String, String>>());
159     }
160
161     private MsoRequest getMsoRequest() {
162         MsoRequest msoRequest = new MsoRequest();
163         msoRequest.setRequestId("12345");
164         msoRequest.setServiceInstanceId("12345");
165         return msoRequest;
166     }
167
168 }