2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.vnf;
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;
32 import javax.xml.ws.Holder;
33 import java.util.HashMap;
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;
45 public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils {
48 public ExpectedException expectedException = ExpectedException.none();
51 MsoVnfPluginAdapterImpl msoVnfPluginAdapter;
53 String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
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>());
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>());
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>());
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>());
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>());
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>());
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>>());
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>>());
160 private MsoRequest getMsoRequest() {
161 MsoRequest msoRequest = new MsoRequest();
162 msoRequest.setRequestId("12345");
163 msoRequest.setServiceInstanceId("12345");