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.urlPathEqualTo;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
32 import java.util.HashMap;
35 import javax.xml.ws.Holder;
37 import org.apache.http.HttpStatus;
38 import org.junit.Before;
39 import org.junit.Rule;
40 import org.junit.Test;
41 import org.junit.rules.ExpectedException;
42 import org.onap.so.adapters.vdu.VduModelInfo;
43 import org.onap.so.adapters.vnf.exceptions.VnfException;
44 import org.onap.so.cloud.CloudConfig;
45 import org.onap.so.entity.MsoRequest;
46 import org.onap.so.openstack.beans.StackInfo;
47 import org.onap.so.openstack.exceptions.MsoException;
48 import org.springframework.beans.factory.annotation.Autowired;
50 public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{
52 public ExpectedException expectedException = ExpectedException.none();
55 private MsoVnfPluginAdapterImpl instance;
58 private CloudConfig cloudConfig;
60 private static final String CREATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": "
61 + "\"workload-id\", \"template_response\": {\"stack\": {\"id\": \"TEST-stack\", \"links\": []}}}";
62 private static final String UPDATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": "
64 private static final String GET_CREATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": "
65 + "\"workload-id\", \"workload_status\": \"CREATE_COMPLETE\"}";
66 private static final String GET_UPDATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": "
67 + "\"workload-id\", \"workload_status\": \"UPDATE_COMPLETE\"}";
69 private static final String MULTICLOUD_CREATE_PATH = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload";
70 private static final String MULTICLOUD_UPDATE_PATH = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id";
71 private static final String MULTICLOUD_GET_PATH_BY_NAME = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname";
72 private static final String MULTICLOUD_GET_PATH_BY_ID = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id";
75 public void before() throws Exception {
76 super.orchestrator = "multicloud";
77 super.cloudEndpoint = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload";
82 public void createVfModule() throws Exception {
84 Map<String, Object> stackInputs = new HashMap<>();
85 stackInputs.put("oof_directives", "{}");
86 stackInputs.put("sdnc_directives", "{}");
87 stackInputs.put("user_directives", "{}");
88 stackInputs.put("generic_vnf_id", "genVNFID");
89 stackInputs.put("vf_module_id", "vfMODULEID");
91 MsoRequest msoRequest = new MsoRequest();
92 msoRequest.setRequestId("12345");
93 msoRequest.setServiceInstanceId("12345");
95 wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_NAME))
96 .willReturn(aResponse()
97 .withHeader("Content-Type", "application/json")
98 .withStatus(HttpStatus.SC_NOT_FOUND)));
100 wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID))
101 .inScenario("CREATE").whenScenarioStateIs("CREATING")
102 .willReturn(aResponse()
103 .withHeader("Content-Type", "application/json")
104 .withBody(GET_CREATE_STACK_RESPONSE)
105 .withStatus(HttpStatus.SC_OK)));
107 wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID))
108 .inScenario("CREATE").whenScenarioStateIs("UPDATING")
109 .willReturn(aResponse()
110 .withHeader("Content-Type", "application/json")
111 .withBody(GET_UPDATE_STACK_RESPONSE)
112 .withStatus(HttpStatus.SC_OK)));
114 wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)).inScenario("CREATE")
115 .willReturn(aResponse()
116 .withHeader("Content-Type", "application/json")
117 .withBodyFile("MulticloudResponse_Stack_Create.json")
118 .withStatus(HttpStatus.SC_CREATED))
119 .willSetStateTo("CREATING"));
121 wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_UPDATE_PATH)).inScenario("CREATE")
122 .willReturn(aResponse()
123 .withHeader("Content-Type", "application/json")
124 .withBody(UPDATE_STACK_RESPONSE)
125 .withStatus(HttpStatus.SC_ACCEPTED))
126 .willSetStateTo("UPDATING"));
129 instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId", "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
130 } catch (VnfException e) {
131 fail("createVfModule success expected, failed with exception: " + e.toString());
133 wireMockServer.resetScenarios();
137 public void createVfModuleAlreadyExists() throws Exception {
139 Map<String, Object> stackInputs = new HashMap<>();
140 stackInputs.put("oof_directives", "{}");
141 stackInputs.put("sdnc_directives", "{}");
142 stackInputs.put("user_directives", "{}");
143 stackInputs.put("generic_vnf_id", "genVNFID");
144 stackInputs.put("vf_module_id", "vfMODULEID");
146 MsoRequest msoRequest = new MsoRequest();
147 msoRequest.setRequestId("12345");
148 msoRequest.setServiceInstanceId("12345");
150 wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname")).willReturn(aResponse()
152 .withBodyFile("MulticloudResponse_Stack.json")
153 .withStatus(HttpStatus.SC_OK)));
156 instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId", "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
157 } catch (VnfException e) {
158 assertTrue(e.toString().contains("Resource vfname already exists in owner/cloud/tenant CloudOwner/MTN13/123 with ID vfname/vfname"));
161 fail("VnfAlreadyExists Exception expected!");
165 public void deleteVfModule() throws Exception {
166 MsoRequest msoRequest = new MsoRequest();
167 msoRequest.setRequestId("12345");
168 msoRequest.setServiceInstanceId("12345");
170 wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")).willReturn(aResponse()
171 .withBodyFile("MulticloudResponse_Stack.json")
172 .withStatus(HttpStatus.SC_OK)));
174 wireMockServer.stubFor(delete(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")).willReturn(aResponse()
175 .withStatus(HttpStatus.SC_NO_CONTENT)));
177 instance.deleteVfModule("MTN13", "CloudOwner", "123", "workload-id", msoRequest, new Holder<>());
181 public void queryVfModule() throws Exception {
182 MsoRequest msoRequest = new MsoRequest();
183 msoRequest.setRequestId("12345");
184 msoRequest.setServiceInstanceId("12345");
186 wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")).willReturn(aResponse()
187 .withBodyFile("MulticloudResponse_Stack.json")
188 .withStatus(HttpStatus.SC_OK)));
190 instance.queryVnf("MTN13", "CloudOwner", "123", "workload-id", msoRequest, new Holder<>(), new Holder<>(), new Holder<>(), new Holder<>());