2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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;
24 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
25 import static com.github.tomakehurst.wiremock.client.WireMock.containing;
26 import static com.github.tomakehurst.wiremock.client.WireMock.post;
27 import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
29 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
30 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
31 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
32 import java.util.HashMap;
34 import org.apache.http.HttpStatus;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.rules.ExpectedException;
38 import org.onap.so.entity.MsoRequest;
39 import org.onap.so.openstack.beans.VnfRollback;
40 import org.springframework.beans.factory.annotation.Autowired;
42 public class MsoVnfAdapterAsyncImplTest extends BaseRestTestUtils {
45 MsoVnfAdapterAsyncImpl instance;
48 public ExpectedException expectedException = ExpectedException.none();
51 public void healthCheckVNFTest() {
52 instance.healthCheckA();
56 public void createVNFTest() throws Exception {
57 MsoRequest msoRequest = new MsoRequest();
58 msoRequest.setRequestId("12345");
59 msoRequest.setServiceInstanceId("12345");
61 mockOpenStackResponseAccess(wireMockServer, wireMockPort);
62 mockOpenStackGetStackVfModule_200(wireMockServer);
63 wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest"))
64 .withRequestBody(containing("messageId")).willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
66 String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
67 String notificationUrl =
68 "http://localhost:" + wireMockPort + "/notify/adapterNotify/updateVnfNotificationRequest";
69 instance.createVnfA("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
70 "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE,
71 "messageId", msoRequest, notificationUrl);
73 wireMockServer.verify(1, postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
77 public void createVNFTest_Exception() throws Exception {
78 String notificationUrl =
79 "http://localhost:" + wireMockPort + "/notify/adapterNotify/updateVnfNotificationRequest";
80 instance.createVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
81 "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE,
82 "messageId", null, notificationUrl);
84 wireMockServer.verify(1, postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
89 public void updateVnfTest() throws Exception {
90 MsoRequest msoRequest = new MsoRequest();
91 msoRequest.setRequestId("12345");
92 msoRequest.setServiceInstanceId("12345");
94 Map<String, Object> map = new HashMap<>();
95 map.put("key1", "value1");
96 wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest"))
97 .withRequestBody(containing("messageId")).willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
98 String notificationUrl =
99 "http://localhost:" + wireMockPort + "/notify/adapterNotify/updateVnfNotificationRequest";
100 instance.updateVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
101 "volumeGroupHeatStackId|1", map, "messageId", msoRequest, notificationUrl);
105 public void updateVnfTest_Exception() throws Exception {
106 MsoRequest msoRequest = new MsoRequest();
107 msoRequest.setRequestId("12345");
108 msoRequest.setServiceInstanceId("12345");
110 Map<String, Object> map = new HashMap<>();
111 map.put("key1", "value1");
112 wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest"))
113 .withRequestBody(containing("messageId")).willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
114 String notificationUrl =
115 "http://localhost:" + wireMockPort + "/notify/adapterNotify/updateVnfNotificationRequest";
116 instance.updateVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
117 "volumeGroupHeatStackId|1", map, "messageId", msoRequest, notificationUrl);
118 wireMockServer.verify(1, postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
122 public void queryVnfTest() {
123 MsoRequest msoRequest = new MsoRequest();
124 msoRequest.setRequestId("12345");
125 msoRequest.setServiceInstanceId("12345");
126 instance.queryVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", msoRequest,
127 "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
131 public void deleteVnfTest() {
132 MsoRequest msoRequest = new MsoRequest();
133 msoRequest.setRequestId("12345");
134 msoRequest.setServiceInstanceId("12345");
135 instance.deleteVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId",
136 msoRequest, "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
140 public void rollbackVnfTest() {
141 VnfRollback vnfRollBack = new VnfRollback();
142 vnfRollBack.setCloudSiteId("mdt1");
143 vnfRollBack.setCloudOwner("CloudOwner");
144 vnfRollBack.setTenantId("88a6ca3ee0394ade9403f075db23167e");
145 vnfRollBack.setVnfId("ff5256d1-5a33-55df-13ab-12abad84e7ff");
146 instance.rollbackVnfA(vnfRollBack, "messageId",
147 "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");