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 org.apache.http.HttpStatus;
25 import org.junit.Ignore;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.ExpectedException;
29 import org.onap.so.adapters.vnf.exceptions.VnfException;
30 import org.onap.so.entity.MsoRequest;
31 import org.onap.so.openstack.beans.VnfRollback;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.boot.test.mock.mockito.SpyBean;
35 import java.util.HashMap;
38 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
39 import static com.github.tomakehurst.wiremock.client.WireMock.containing;
40 import static com.github.tomakehurst.wiremock.client.WireMock.post;
41 import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
42 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
43 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
44 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
45 import static com.github.tomakehurst.wiremock.client.WireMock.verify;
46 import static org.mockito.ArgumentMatchers.any;
47 import static org.mockito.Mockito.doThrow;
48 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200;
49 import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess;
51 public class MsoVnfAdapterAsyncImplTest extends BaseRestTestUtils {
54 MsoVnfAdapterAsyncImpl instance;
57 public ExpectedException expectedException = ExpectedException.none();
60 public void healthCheckVNFTest() {
61 instance.healthCheckA();
65 public void createVNFTest() throws Exception {
66 MsoRequest msoRequest = new MsoRequest();
67 msoRequest.setRequestId("12345");
68 msoRequest.setServiceInstanceId("12345");
70 mockOpenStackResponseAccess(wireMockPort);
71 mockOpenStackGetStackVfModule_200();
72 stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody
73 (containing("messageId"))
74 .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
76 String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
77 String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
78 instance.createVnfA("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
79 "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, "messageId",
80 msoRequest, notificationUrl);
82 verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
86 public void createVNFTest_Exception() throws Exception {
87 String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
88 instance.createVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
89 "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, "messageId",
90 null, notificationUrl);
92 verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
97 public void updateVnfTest() throws Exception{
98 MsoRequest msoRequest = new MsoRequest();
99 msoRequest.setRequestId("12345");
100 msoRequest.setServiceInstanceId("12345");
102 Map<String, Object> map = new HashMap<>();
103 map.put("key1", "value1");
104 stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody
105 (containing("messageId"))
106 .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
107 String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
108 instance.updateVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
109 "volumeGroupHeatStackId|1", map, "messageId", msoRequest,
114 public void updateVnfTest_Exception() throws Exception{
115 MsoRequest msoRequest = new MsoRequest();
116 msoRequest.setRequestId("12345");
117 msoRequest.setServiceInstanceId("12345");
119 Map<String, Object> map = new HashMap<>();
120 map.put("key1", "value1");
121 stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody
122 (containing("messageId"))
123 .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
124 String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
125 instance.updateVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
126 "volumeGroupHeatStackId|1", map, "messageId", msoRequest,
128 verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
132 public void queryVnfTest() {
133 MsoRequest msoRequest = new MsoRequest();
134 msoRequest.setRequestId("12345");
135 msoRequest.setServiceInstanceId("12345");
136 instance.queryVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", msoRequest,
137 "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
141 public void deleteVnfTest() {
142 MsoRequest msoRequest = new MsoRequest();
143 msoRequest.setRequestId("12345");
144 msoRequest.setServiceInstanceId("12345");
145 instance.deleteVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", msoRequest,
146 "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
150 public void rollbackVnfTest() {
151 VnfRollback vnfRollBack = new VnfRollback();
152 vnfRollBack.setCloudSiteId("mdt1");
153 vnfRollBack.setCloudOwner("CloudOwner");
154 vnfRollBack.setTenantId("88a6ca3ee0394ade9403f075db23167e");
155 vnfRollBack.setVnfId("ff5256d1-5a33-55df-13ab-12abad84e7ff");
156 instance.rollbackVnfA(vnfRollBack, "messageId",
157 "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");