replace all fixed wiremock ports
[so.git] / adapters / mso-openstack-adapters / src / test / java / org / onap / so / adapters / vnf / MsoVnfMulticloudAdapterImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 Intel Corp. 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 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
26 import static com.github.tomakehurst.wiremock.client.WireMock.post;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
28
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import javax.xml.ws.Holder;
33
34 import org.apache.http.HttpStatus;
35 import org.junit.Before;
36 import org.junit.Rule;
37 import org.junit.Test;
38 import org.junit.rules.ExpectedException;
39 import org.onap.so.cloud.CloudConfig;
40 import org.onap.so.entity.MsoRequest;
41 import org.springframework.beans.factory.annotation.Autowired;
42
43 public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{
44     @Rule
45     public ExpectedException expectedException = ExpectedException.none();
46
47     @Autowired
48     private MsoVnfPluginAdapterImpl instance;
49
50     @Autowired
51     private CloudConfig cloudConfig;
52
53     @Before
54     public void before() throws Exception {
55         super.orchestrator = "multicloud";
56         super.cloudEndpoint = "/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload";
57         super.setUp();
58     }
59
60     @Test
61     public void createVfModule() throws Exception {
62         
63         Map<String, Object> stackInputs = new HashMap<>();
64         stackInputs.put("oof_directives", "{}");
65         stackInputs.put("sdnc_directives", "{}");
66         stackInputs.put("generic_vnf_id", "genVNFID");
67         stackInputs.put("vf_module_id", "vfMODULEID");
68
69         MsoRequest msoRequest = new MsoRequest();
70         msoRequest.setRequestId("12345");
71         msoRequest.setServiceInstanceId("12345");
72
73         wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/vfname")).willReturn(aResponse()
74                 //.withHeader()
75                 .withStatus(HttpStatus.SC_NOT_FOUND)));
76
77         wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
78                 //.withHeader()
79                 .withBodyFile("MulticloudResponse_Stack.json")
80                 .withStatus(HttpStatus.SC_OK)));
81
82         wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/vfname/outputs")).willReturn(aResponse()
83                 .withStatus(HttpStatus.SC_NOT_FOUND)));
84
85         wireMockServer.stubFor(post(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload")).willReturn(aResponse()
86                 .withBodyFile("MulticloudResponse_Stack_Create.json")
87                 .withStatus(HttpStatus.SC_CREATED)));
88
89         instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId", "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
90     }
91
92     @Test
93     public void deleteVfModule() throws Exception {
94         MsoRequest msoRequest = new MsoRequest();
95         msoRequest.setRequestId("12345");
96         msoRequest.setServiceInstanceId("12345");
97
98         wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
99                 .withBodyFile("MulticloudResponse_Stack.json")
100                 .withStatus(HttpStatus.SC_OK)));
101
102         wireMockServer.stubFor(delete(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
103                 .withStatus(HttpStatus.SC_NO_CONTENT)));
104
105         instance.deleteVfModule("MTN13", "CloudOwner", "123", "workload-id", msoRequest, new Holder<>());
106     }
107
108     @Test
109     public void queryVfModule() throws Exception {
110         MsoRequest msoRequest = new MsoRequest();
111         msoRequest.setRequestId("12345");
112         msoRequest.setServiceInstanceId("12345");
113
114         wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
115                 .withBodyFile("MulticloudResponse_Stack.json")
116                 .withStatus(HttpStatus.SC_OK)));
117
118         instance.queryVnf("MTN13", "CloudOwner", "123", "workload-id", msoRequest, new Holder<>(), new Holder<>(), new Holder<>(), new Holder<>());
119     }
120
121     // TODO Error Tests
122 }