Merge " Duplicate service entry removed"
[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.context.embedded.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/vfname/outputs")).willReturn(aResponse()
84                 .withStatus(HttpStatus.SC_NOT_FOUND)));
85
86         stubFor(post(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload")).willReturn(aResponse()
87                 .withBodyFile("MulticloudResponse_Stack_Create.json")
88                 .withStatus(HttpStatus.SC_CREATED)));
89
90         instance.createVfModule("MTN13", "123", "vf", "v1", "vfname", "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
91     }
92
93     @Test
94     public void deleteVfModule() throws Exception {
95         MsoRequest msoRequest = new MsoRequest();
96         msoRequest.setRequestId("12345");
97         msoRequest.setServiceInstanceId("12345");
98
99         stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
100                 .withBodyFile("MulticloudResponse_Stack.json")
101                 .withStatus(HttpStatus.SC_OK)));
102
103         stubFor(delete(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
104                 .withStatus(HttpStatus.SC_NO_CONTENT)));
105
106         instance.deleteVfModule("MTN13", "123", "workload-id", msoRequest, new Holder<>());
107     }
108
109     @Test
110     public void queryVfModule() throws Exception {
111         MsoRequest msoRequest = new MsoRequest();
112         msoRequest.setRequestId("12345");
113         msoRequest.setServiceInstanceId("12345");
114
115         stubFor(get(urlPathEqualTo("/api/multicloud/v1/cloud_owner/cloud_region_id/infra_workload/workload-id")).willReturn(aResponse()
116                 .withBodyFile("MulticloudResponse_Stack.json")
117                 .withStatus(HttpStatus.SC_OK)));
118
119         instance.queryVnf("MTN13", "123", "workload-id", msoRequest, new Holder<>(), new Holder<>(), new Holder<>(), new Holder<>());
120     }
121
122     // TODO Error Tests
123 }