Springboot 2.0 upgrade
[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 org.apache.http.HttpStatus;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.ExpectedException;
29 import org.onap.so.adapters.openstack.MsoOpenstackAdaptersApplication;
30 import org.onap.so.adapters.vnf.exceptions.VnfException;
31 import org.onap.so.cloud.CloudConfig;
32 import org.onap.so.db.catalog.beans.CloudSite;
33 import org.onap.so.entity.MsoRequest;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.boot.web.server.LocalServerPort;
36
37 import javax.xml.ws.Holder;
38 import java.util.HashMap;
39 import java.util.Map;
40
41 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
42 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
43 import static com.github.tomakehurst.wiremock.client.WireMock.get;
44 import static com.github.tomakehurst.wiremock.client.WireMock.post;
45 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
46 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
47 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
48
49 public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{
50     @Rule
51     public ExpectedException expectedException = ExpectedException.none();
52
53     @Autowired
54     private MsoVnfPluginAdapterImpl instance;
55
56     @Autowired
57     private CloudConfig cloudConfig;
58
59     @Before
60     public void before() throws Exception {
61         super.orchestrator = "multicloud";
62         super.cloudEndpoint = "/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload";
63         super.setUp();
64     }
65
66     @Test
67     public void createVfModule() throws Exception {
68         //expectedException.expect(VnfException.class);
69         Map<String, String> stackInputs = new HashMap<>();
70         stackInputs.put("oof_directives", "{oofDIRECTIVES}");
71         stackInputs.put("sdnc_directives", "{sdncDIRECTIVES}");
72         stackInputs.put("generic_vnf_id", "genVNFID");
73         stackInputs.put("vf_module_id", "vfMODULEID");
74
75         MsoRequest msoRequest = new MsoRequest();
76         msoRequest.setRequestId("12345");
77         msoRequest.setServiceInstanceId("12345");
78
79         stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/vfname")).willReturn(aResponse()
80                 //.withHeader()
81                 .withStatus(HttpStatus.SC_NOT_FOUND)));
82
83         stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
84                 //.withHeader()
85                 .withBodyFile("MulticloudResponse_Stack.json")
86                 .withStatus(HttpStatus.SC_OK)));
87
88         stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/vfname/outputs")).willReturn(aResponse()
89                 .withStatus(HttpStatus.SC_NOT_FOUND)));
90
91         stubFor(post(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload")).willReturn(aResponse()
92                 .withBodyFile("MulticloudResponse_Stack_Create.json")
93                 .withStatus(HttpStatus.SC_CREATED)));
94
95         instance.createVfModule("MTN13", "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<>());
96     }
97
98     @Test
99     public void deleteVfModule() throws Exception {
100         MsoRequest msoRequest = new MsoRequest();
101         msoRequest.setRequestId("12345");
102         msoRequest.setServiceInstanceId("12345");
103
104         stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
105                 .withBodyFile("MulticloudResponse_Stack.json")
106                 .withStatus(HttpStatus.SC_OK)));
107
108         stubFor(delete(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
109                 .withStatus(HttpStatus.SC_NO_CONTENT)));
110
111         instance.deleteVfModule("MTN13", "123", "workload-id", msoRequest, new Holder<>());
112     }
113
114     @Test
115     public void queryVfModule() throws Exception {
116         MsoRequest msoRequest = new MsoRequest();
117         msoRequest.setRequestId("12345");
118         msoRequest.setServiceInstanceId("12345");
119
120         stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
121                 .withBodyFile("MulticloudResponse_Stack.json")
122                 .withStatus(HttpStatus.SC_OK)));
123
124         instance.queryVnf("MTN13", "123", "workload-id", msoRequest, new Holder<>(), new Holder<>(), new Holder<>(), new Holder<>());
125     }
126
127     // TODO Error Tests
128 }