cbf252ec3a2d849daa7c220684faf5c48b8d151b
[so.git] / adapters / mso-openstack-adapters / src / test / java / org / onap / so / adapters / vnf / MsoVnfAdapterAsyncImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.adapters.vnf;
22
23
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;
34
35 import java.util.HashMap;
36 import java.util.Map;
37
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;
50
51 public class MsoVnfAdapterAsyncImplTest extends BaseRestTestUtils {
52
53         @Autowired
54         MsoVnfAdapterAsyncImpl instance;
55
56         @Rule
57         public ExpectedException expectedException = ExpectedException.none();
58
59         @Test
60         public void healthCheckVNFTest() {
61                 instance.healthCheckA();
62         }
63
64         @Test
65         public void createVNFTest() throws Exception {
66                 MsoRequest msoRequest = new MsoRequest();
67                 msoRequest.setRequestId("12345");
68                 msoRequest.setServiceInstanceId("12345");
69
70                 mockOpenStackResponseAccess(wireMockPort);
71                 mockOpenStackGetStackVfModule_200();
72                 stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody
73                                 (containing("messageId"))
74                                 .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
75
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);
81
82                 verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
83         }
84
85         @Test
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);
91
92                 verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
93
94         }
95
96         @Test
97         public void updateVnfTest() throws Exception{
98                 MsoRequest msoRequest = new MsoRequest();
99                 msoRequest.setRequestId("12345");
100                 msoRequest.setServiceInstanceId("12345");
101
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,
110                                 notificationUrl);
111         }
112
113         @Test
114         public void updateVnfTest_Exception() throws Exception{
115                 MsoRequest msoRequest = new MsoRequest();
116                 msoRequest.setRequestId("12345");
117                 msoRequest.setServiceInstanceId("12345");
118
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,
127                                 notificationUrl);
128                 verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
129         }
130
131         @Test
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");
138         }
139
140         @Test
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");
147         }
148
149         @Test
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");
158         }
159 }