1a308b7c4cb67422612aa49931e79815b7ecbd3e
[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 import java.util.HashMap;
33 import org.apache.http.HttpStatus;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37 import org.onap.so.entity.MsoRequest;
38 import org.springframework.beans.factory.annotation.Autowired;
39
40 public class MsoVnfAdapterAsyncImplTest extends BaseRestTestUtils {
41
42     @Autowired
43     MsoVnfAdapterAsyncImpl instance;
44
45     @Rule
46     public ExpectedException expectedException = ExpectedException.none();
47
48     @Test
49     public void healthCheckVNFTest() {
50         instance.healthCheckA();
51     }
52
53     @Test
54     public void createVNFTest() throws Exception {
55         MsoRequest msoRequest = new MsoRequest();
56         msoRequest.setRequestId("12345");
57         msoRequest.setServiceInstanceId("12345");
58
59         mockOpenStackResponseAccess(wireMockServer, wireMockPort);
60         mockOpenStackGetStackVfModule_200(wireMockServer);
61         wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest"))
62                 .withRequestBody(containing("messageId")).willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
63
64         String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId";
65         String notificationUrl =
66                 "http://localhost:" + wireMockPort + "/notify/adapterNotify/updateVnfNotificationRequest";
67         instance.createVnfA("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD",
68                 "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE,
69                 "messageId", msoRequest, notificationUrl);
70
71         wireMockServer.verify(1, postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
72     }
73
74     @Test
75     public void createVNFTest_Exception() throws Exception {
76         String notificationUrl =
77                 "http://localhost:" + wireMockPort + "/notify/adapterNotify/updateVnfNotificationRequest";
78         instance.createVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
79                 "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE,
80                 "messageId", null, notificationUrl);
81
82         wireMockServer.verify(1, postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")));
83
84     }
85
86     @Test
87     public void deleteVnfTest() {
88         MsoRequest msoRequest = new MsoRequest();
89         msoRequest.setRequestId("12345");
90         msoRequest.setServiceInstanceId("12345");
91         instance.deleteVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId",
92                 msoRequest, "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest");
93     }
94
95 }