02fbe2c5305dad6bb5e2070108017e126fdd5bd3
[so.git] /
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 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
33 import java.util.HashMap;
34 import java.util.Map;
35
36 import org.apache.http.HttpStatus;
37 import org.junit.Rule;
38 import org.junit.Test;
39 import org.junit.rules.ExpectedException;
40 import org.onap.so.entity.MsoRequest;
41 import org.onap.so.openstack.beans.VnfRollback;
42 import org.springframework.beans.factory.annotation.Autowired;
43
44 public class MsoVnfAdapterAsyncImplTest extends BaseRestTestUtils {
45
46         @Autowired
47         MsoVnfAdapterAsyncImpl instance;
48
49         @Rule
50         public ExpectedException expectedException = ExpectedException.none();
51
52         @Test
53         public void healthCheckVNFTest() {
54                 instance.healthCheckA();
55         }
56
57         @Test
58         public void createVNFTest() throws Exception {
59                 MsoRequest msoRequest = new MsoRequest();
60                 msoRequest.setRequestId("12345");
61                 msoRequest.setServiceInstanceId("12345");
62
63                 mockOpenStackResponseAccess(wireMockServer, wireMockPort);
64                 mockOpenStackGetStackVfModule_200(wireMockServer);
65                 wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody
66                                 (containing("messageId"))
67                                 .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
68
69                 String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
70                 String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
71                 instance.createVnfA("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
72                                 "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, "messageId",
73                                 msoRequest, notificationUrl);
74
75         wireMockServer.verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
76         }
77
78         @Test
79         public void createVNFTest_Exception() throws Exception {
80                 String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
81                 instance.createVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
82                                 "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, "messageId",
83                                 null, notificationUrl);
84
85         wireMockServer.verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
86
87         }
88
89         @Test
90         public void updateVnfTest() throws Exception{
91                 MsoRequest msoRequest = new MsoRequest();
92                 msoRequest.setRequestId("12345");
93                 msoRequest.setServiceInstanceId("12345");
94
95                 Map<String, Object> map = new HashMap<>();
96                 map.put("key1", "value1");
97                 wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody
98                                 (containing("messageId"))
99                                 .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
100                 String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
101                 instance.updateVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
102                                 "volumeGroupHeatStackId|1", map, "messageId", msoRequest,
103                                 notificationUrl);
104         }
105
106         @Test
107         public void updateVnfTest_Exception() throws Exception{
108                 MsoRequest msoRequest = new MsoRequest();
109                 msoRequest.setRequestId("12345");
110                 msoRequest.setServiceInstanceId("12345");
111
112                 Map<String, Object> map = new HashMap<>();
113                 map.put("key1", "value1");
114                 wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody
115                                 (containing("messageId"))
116                                 .willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
117                 String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest";
118                 instance.updateVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
119                                 "volumeGroupHeatStackId|1", map, "messageId", msoRequest,
120                                 notificationUrl);
121         wireMockServer.verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
122         }
123
124         @Test
125         public void queryVnfTest() {
126                 MsoRequest msoRequest = new MsoRequest();
127                 msoRequest.setRequestId("12345");
128                 msoRequest.setServiceInstanceId("12345");
129                         instance.queryVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", msoRequest,
130                                         "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
131         }
132
133         @Test
134         public void deleteVnfTest() {
135                 MsoRequest msoRequest = new MsoRequest();
136                 msoRequest.setRequestId("12345");
137                 msoRequest.setServiceInstanceId("12345");
138                         instance.deleteVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", msoRequest,
139                                         "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
140         }
141
142         @Test
143         public void rollbackVnfTest() {
144                 VnfRollback vnfRollBack = new VnfRollback();
145                 vnfRollBack.setCloudSiteId("mdt1");
146                 vnfRollBack.setCloudOwner("CloudOwner");
147                 vnfRollBack.setTenantId("88a6ca3ee0394ade9403f075db23167e");
148                 vnfRollBack.setVnfId("ff5256d1-5a33-55df-13ab-12abad84e7ff");
149                         instance.rollbackVnfA(vnfRollBack, "messageId",
150                                         "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
151         }
152 }