2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.client.adapter.vnf;
\r
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
\r
24 import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
\r
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
\r
26 import static com.github.tomakehurst.wiremock.client.WireMock.post;
\r
27 import static com.github.tomakehurst.wiremock.client.WireMock.put;
\r
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
\r
29 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
\r
30 import static org.junit.Assert.assertEquals;
\r
32 import org.junit.BeforeClass;
\r
33 import org.junit.Rule;
\r
34 import org.junit.Test;
\r
35 import org.openecomp.mso.adapters.vnfrest.CreateVfModuleRequest;
\r
36 import org.openecomp.mso.adapters.vnfrest.CreateVfModuleResponse;
\r
37 import org.openecomp.mso.adapters.vnfrest.DeleteVfModuleRequest;
\r
38 import org.openecomp.mso.adapters.vnfrest.DeleteVfModuleResponse;
\r
39 import org.openecomp.mso.adapters.vnfrest.QueryVfModuleResponse;
\r
40 import org.openecomp.mso.adapters.vnfrest.RollbackVfModuleRequest;
\r
41 import org.openecomp.mso.adapters.vnfrest.RollbackVfModuleResponse;
\r
42 import org.openecomp.mso.adapters.vnfrest.UpdateVfModuleRequest;
\r
43 import org.openecomp.mso.adapters.vnfrest.UpdateVfModuleResponse;
\r
44 import org.openecomp.mso.adapters.vnfrest.VfModuleRollback;
\r
46 import com.github.tomakehurst.wiremock.junit.WireMockRule;
\r
48 public class VnfAdapterClientTest {
\r
51 public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(28090));
\r
53 private static final String TESTING_ID = "___TESTING___";
\r
54 private static final String AAI_VNF_ID = "test";
\r
55 private static final String AAI_VF_MODULE_ID = "test";
\r
56 private static final String REST_ENDPOINT = "/vnfs/rest/v1/vnfs";
\r
58 private VnfAdapterClientImpl client = new VnfAdapterClientImpl();
\r
61 public static void setUp() {
\r
62 System.setProperty("mso.config.path", "src/test/resources");
\r
66 public void createVfModuleTest() {
\r
67 CreateVfModuleRequest request = new CreateVfModuleRequest();
\r
68 request.setCloudSiteId(TESTING_ID);
\r
70 CreateVfModuleResponse mockResponse = new CreateVfModuleResponse();
\r
71 mockResponse.setVfModuleCreated(true);
\r
72 wireMockRule.stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules"))
\r
73 .willReturn(aResponse().withHeader("Content-Type", "application/json")
\r
74 .withBody(mockResponse.toJsonString()).withStatus(200)));
\r
76 CreateVfModuleResponse response = client.createVfModule(AAI_VNF_ID, request);
\r
77 assertEquals("Testing CreateVfModule response", true, response.getVfModuleCreated());
\r
81 public void rollbackVfModuleTest() {
\r
82 RollbackVfModuleRequest request = new RollbackVfModuleRequest();
\r
83 VfModuleRollback rollback = new VfModuleRollback();
\r
84 rollback.setCloudSiteId(TESTING_ID);
\r
85 request.setVfModuleRollback(rollback);
\r
87 RollbackVfModuleResponse mockResponse = new RollbackVfModuleResponse();
\r
88 mockResponse.setVfModuleRolledback(true);
\r
89 wireMockRule.stubFor(
\r
90 put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback"))
\r
91 .willReturn(aResponse().withHeader("Content-Type", "application/json")
\r
92 .withBody(mockResponse.toJsonString()).withStatus(200)));
\r
94 RollbackVfModuleResponse response = client.rollbackVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, request);
\r
95 assertEquals("Testing RollbackVfModule response", true, response.getVfModuleRolledback());
\r
99 public void deleteVfModuleTest() {
\r
100 DeleteVfModuleRequest request = new DeleteVfModuleRequest();
\r
101 request.setCloudSiteId(TESTING_ID);
\r
103 DeleteVfModuleResponse mockResponse = new DeleteVfModuleResponse();
\r
104 mockResponse.setVfModuleDeleted(true);
\r
105 wireMockRule.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID))
\r
106 .willReturn(aResponse().withHeader("Content-Type", "application/json")
\r
107 .withBody(mockResponse.toJsonString()).withStatus(200)));
\r
109 DeleteVfModuleResponse response = client.deleteVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, request);
\r
110 assertEquals("Testing DeleteVfModule response", true, response.getVfModuleDeleted());
\r
114 public void updateVfModuleTest() {
\r
115 UpdateVfModuleRequest request = new UpdateVfModuleRequest();
\r
116 request.setCloudSiteId(TESTING_ID);
\r
117 request.setVfModuleId("test1");
\r
119 UpdateVfModuleResponse mockResponse = new UpdateVfModuleResponse();
\r
120 mockResponse.setVfModuleId("test1");
\r
121 wireMockRule.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/"))
\r
122 .willReturn(aResponse().withHeader("Content-Type", "application/json")
\r
123 .withBody(mockResponse.toJsonString()).withStatus(200)));
\r
125 UpdateVfModuleResponse response = client.updateVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, request);
\r
126 assertEquals("Testing UpdateVfModule response", "test1", response.getVfModuleId());
\r
130 public void queryVfModuleTest() {
\r
131 QueryVfModuleResponse mockResponse = new QueryVfModuleResponse();
\r
132 mockResponse.setVnfId(AAI_VNF_ID);
\r
133 mockResponse.setVfModuleId(AAI_VF_MODULE_ID);
\r
134 wireMockRule.stubFor(get(urlPathEqualTo(REST_ENDPOINT))
\r
135 .withQueryParam("cloudSiteId", equalTo(TESTING_ID))
\r
136 .withQueryParam("tenantId", equalTo(TESTING_ID))
\r
137 .withQueryParam("vfModuleName", equalTo("someName"))
\r
138 .withQueryParam("skipAAI", equalTo("true"))
\r
139 .withQueryParam("msoRequest.requestId", equalTo("testRequestId"))
\r
140 .withQueryParam("msoRequest.serviceInstanceId", equalTo("serviceInstanceId"))
\r
141 .willReturn(aResponse().withHeader("Content-Type", "application/json")
\r
142 .withBody(mockResponse.toJsonString()).withStatus(200)));
\r
143 QueryVfModuleResponse response = client.queryVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, TESTING_ID, TESTING_ID,
\r
144 "someName", true, "testRequestId", "serviceInstanceId");
\r
145 assertEquals("Testing QueryVfModule response", AAI_VF_MODULE_ID, response.getVfModuleId());
\r
149 public void healthCheckTest() {
\r
150 wireMockRule.stubFor(get(urlPathEqualTo("/vnfs/rest/v1/vnfs")).willReturn(
\r
151 aResponse().withHeader("Content-Type", "text/plain").withBody("healthCheck").withStatus(200)));
\r
153 String healthCheck = client.healthCheck();
\r
154 assertEquals("HealthCheck is correct", "healthCheck", healthCheck);
\r