2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Intel Corp. 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 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.post;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertTrue;
31 import static org.junit.Assert.fail;
32 import java.util.HashMap;
34 import javax.xml.ws.Holder;
35 import org.apache.http.HttpStatus;
36 import org.junit.Before;
37 import org.junit.Rule;
38 import org.junit.Test;
39 import org.junit.rules.ExpectedException;
40 import org.onap.so.adapters.vdu.VduModelInfo;
41 import org.onap.so.adapters.vnf.exceptions.VnfException;
42 import org.onap.so.cloud.CloudConfig;
43 import org.onap.so.entity.MsoRequest;
44 import org.onap.so.openstack.beans.StackInfo;
45 import org.onap.so.openstack.exceptions.MsoException;
46 import org.springframework.beans.factory.annotation.Autowired;
48 public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils {
50 public ExpectedException expectedException = ExpectedException.none();
53 private MsoVnfPluginAdapterImpl instance;
56 private CloudConfig cloudConfig;
58 private static final String UPDATE_STACK_RESPONSE =
59 "{\"template_type\": \"heat\", \"workload_id\": " + "\"workload-id\"}";
60 private static final String GET_CREATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": "
61 + "\"workload-id\", \"workload_status\": \"CREATE_COMPLETE\"}";
62 private static final String GET_UPDATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": "
63 + "\"workload-id\", \"workload_status\": \"UPDATE_COMPLETE\"}";
65 private static final String MULTICLOUD_CREATE_PATH = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload";
66 private static final String MULTICLOUD_UPDATE_PATH =
67 "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id";
68 private static final String MULTICLOUD_GET_PATH_BY_NAME =
69 "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname";
70 private static final String MULTICLOUD_GET_PATH_BY_ID =
71 "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id";
74 public void before() throws Exception {
75 super.orchestrator = "multicloud";
76 super.cloudEndpoint = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload";
81 public void createVfModule() throws Exception {
83 Map<String, Object> stackInputs = new HashMap<>();
84 stackInputs.put("oof_directives", "{}");
85 stackInputs.put("sdnc_directives", "{}");
86 stackInputs.put("user_directives", "{}");
87 stackInputs.put("generic_vnf_id", "genVNFID");
88 stackInputs.put("vf_module_id", "vfMODULEID");
90 MsoRequest msoRequest = new MsoRequest();
91 msoRequest.setRequestId("12345");
92 msoRequest.setServiceInstanceId("12345");
94 wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_NAME)).willReturn(
95 aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
97 wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID)).inScenario("CREATE")
98 .whenScenarioStateIs("CREATING").willReturn(aResponse().withHeader("Content-Type", "application/json")
99 .withBody(GET_CREATE_STACK_RESPONSE).withStatus(HttpStatus.SC_OK)));
101 wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID)).inScenario("CREATE")
102 .whenScenarioStateIs("UPDATING").willReturn(aResponse().withHeader("Content-Type", "application/json")
103 .withBody(GET_UPDATE_STACK_RESPONSE).withStatus(HttpStatus.SC_OK)));
105 wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)).inScenario("CREATE")
106 .willReturn(aResponse().withHeader("Content-Type", "application/json")
107 .withBodyFile("MulticloudResponse_Stack_Create.json").withStatus(HttpStatus.SC_CREATED))
108 .willSetStateTo("CREATING"));
110 wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_UPDATE_PATH))
111 .inScenario("CREATE").willReturn(aResponse().withHeader("Content-Type", "application/json")
112 .withBody(UPDATE_STACK_RESPONSE).withStatus(HttpStatus.SC_ACCEPTED))
113 .willSetStateTo("UPDATING"));
116 instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId",
117 "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true,
118 msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
119 } catch (VnfException e) {
120 fail("createVfModule success expected, failed with exception: " + e.toString());
122 wireMockServer.resetScenarios();
126 public void createVfModule2() throws Exception {
128 Map<String, Object> stackInputs = new HashMap<>();
129 stackInputs.put("oof_directives", "{}");
130 stackInputs.put("sdnc_directives", "{}");
131 stackInputs.put("user_directives", "{}");
132 stackInputs.put("generic_vnf_id", "genVNFID");
133 stackInputs.put("vf_module_id", "vfMODULEID");
135 MsoRequest msoRequest = new MsoRequest();
136 msoRequest.setRequestId("12345");
137 msoRequest.setServiceInstanceId("12345");
139 wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_NAME)).willReturn(
140 aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
142 wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID)).inScenario("CREATE")
143 .whenScenarioStateIs("CREATING").willReturn(aResponse().withHeader("Content-Type", "application/json")
144 .withBody(GET_CREATE_STACK_RESPONSE).withStatus(HttpStatus.SC_OK)));
146 wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID)).inScenario("CREATE")
147 .whenScenarioStateIs("UPDATING").willReturn(aResponse().withHeader("Content-Type", "application/json")
148 .withBody(GET_UPDATE_STACK_RESPONSE).withStatus(HttpStatus.SC_OK)));
150 wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)).inScenario("CREATE")
151 .willReturn(aResponse().withHeader("Content-Type", "application/json")
152 .withBodyFile("MulticloudResponse_Stack_Create2.json").withStatus(HttpStatus.SC_CREATED))
153 .willSetStateTo("CREATING"));
155 wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_UPDATE_PATH))
156 .inScenario("CREATE").willReturn(aResponse().withHeader("Content-Type", "application/json")
157 .withBody(UPDATE_STACK_RESPONSE).withStatus(HttpStatus.SC_ACCEPTED))
158 .willSetStateTo("UPDATING"));
161 instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId",
162 "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true,
163 msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
164 } catch (VnfException e) {
165 fail("createVfModule success expected, failed with exception: " + e.toString());
167 wireMockServer.resetScenarios();
171 public void createVfModuleAlreadyExists() throws Exception {
173 Map<String, Object> stackInputs = new HashMap<>();
174 stackInputs.put("oof_directives", "{}");
175 stackInputs.put("sdnc_directives", "{}");
176 stackInputs.put("user_directives", "{}");
177 stackInputs.put("generic_vnf_id", "genVNFID");
178 stackInputs.put("vf_module_id", "vfMODULEID");
180 MsoRequest msoRequest = new MsoRequest();
181 msoRequest.setRequestId("12345");
182 msoRequest.setServiceInstanceId("12345");
184 wireMockServer.stubFor(
185 get(urlEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload?name=vfname")).willReturn(aResponse()
187 .withBodyFile("MulticloudGetStackExists.json").withStatus(HttpStatus.SC_OK)));
190 instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId",
191 "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true,
192 msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
193 } catch (VnfException e) {
194 assertTrue(e.toString().contains(
195 "Resource vfname already exists in owner/cloud/tenant CloudOwner/MTN13/123 with ID vfname/vfname"));
198 fail("VnfAlreadyExists Exception expected!");
202 public void deleteVfModule() throws Exception {
203 MsoRequest msoRequest = new MsoRequest();
204 msoRequest.setRequestId("12345");
205 msoRequest.setServiceInstanceId("12345");
207 wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id"))
208 .willReturn(aResponse().withBodyFile("MulticloudResponse_Stack.json").withStatus(HttpStatus.SC_OK)));
210 wireMockServer.stubFor(delete(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id"))
211 .willReturn(aResponse().withStatus(HttpStatus.SC_NO_CONTENT)));
213 instance.deleteVfModule("MTN13", "CloudOwner", "123", "workload-id", msoRequest, new Holder<>());
217 public void queryVfModule() throws Exception {
218 MsoRequest msoRequest = new MsoRequest();
219 msoRequest.setRequestId("12345");
220 msoRequest.setServiceInstanceId("12345");
222 wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id"))
223 .willReturn(aResponse().withBodyFile("MulticloudResponse_Stack.json").withStatus(HttpStatus.SC_OK)));
225 instance.queryVnf("MTN13", "CloudOwner", "123", "workload-id", msoRequest, new Holder<>(), new Holder<>(),
226 new Holder<>(), new Holder<>());