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