2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
 
   6  * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
 
   7  * ================================================================================
 
   8  * Licensed under the Apache License, Version 2.0 (the "License");
 
   9  * you may not use this file except in compliance with the License.
 
  10  * You may obtain a copy of the License at
 
  12  *      http://www.apache.org/licenses/LICENSE-2.0
 
  14  * Unless required by applicable law or agreed to in writing, software
 
  15  * distributed under the License is distributed on an "AS IS" BASIS,
 
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  17  * See the License for the specific language governing permissions and
 
  18  * limitations under the License.
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.so.adapters.vnf;
 
  24 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
 
  25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
 
  26 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
 
  27 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
 
  28 import static org.junit.Assert.assertTrue;
 
  30 import java.util.HashMap;
 
  33 import javax.xml.ws.Holder;
 
  35 import org.apache.http.HttpStatus;
 
  36 import org.junit.Before;
 
  37 import org.junit.Rule;
 
  38 import org.junit.Test;
 
  39 import org.junit.rules.ExpectedException;
 
  40 import org.onap.so.adapters.vnf.exceptions.VnfException;
 
  41 import org.onap.so.cloud.CloudConfig;
 
  42 import org.onap.so.db.catalog.beans.CloudifyManager;
 
  43 import org.onap.so.entity.MsoRequest;
 
  44 import org.onap.so.openstack.beans.VnfRollback;
 
  45 import org.springframework.beans.factory.annotation.Autowired;
 
  47 public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils {
 
  50         public ExpectedException expectedException = ExpectedException.none();
 
  53         private MsoVnfCloudifyAdapterImpl instance;
 
  56         private CloudConfig cloudConfig;
 
  59         public void before() throws Exception {
 
  61                 CloudifyManager cloudifyManager = new CloudifyManager();
 
  62                 cloudifyManager.setId("mtn13");
 
  63                 cloudifyManager.setCloudifyUrl("http://localhost:"+wireMockPort+"/v2.0");
 
  64                 cloudifyManager.setUsername("m93945");
 
  65                 cloudifyManager.setPassword("93937EA01B94A10A49279D4572B48369");
 
  69     public void queryVnfExceptionTest() throws Exception {
 
  70         MsoRequest msoRequest = new MsoRequest();
 
  71         msoRequest.setRequestId("12345");
 
  72         msoRequest.setServiceInstanceId("12345");
 
  73         Holder <Map <String, String>> outputs = new Holder<>();
 
  74         instance.queryVnf("siteid", "CloudOwner", "1234", "vfname",
 
  75                 msoRequest, new Holder<>(), new Holder<>(), new Holder<>(),
 
  78         assertTrue(outputs.value.isEmpty());
 
  82         public void queryVnfTest() throws Exception {
 
  83                 MsoRequest msoRequest = new MsoRequest();
 
  84                 msoRequest.setRequestId("12345");
 
  85                 msoRequest.setServiceInstanceId("12345");
 
  86                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
 
  87                                 .withBody("{ \"id\": \"123\" }")
 
  88                                 .withStatus(HttpStatus.SC_OK)));
 
  90                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
 
  91                                 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
 
  92                                 .withStatus(HttpStatus.SC_OK)));
 
  94                 wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
 
  95                                 .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
 
  96                                 .withStatus(HttpStatus.SC_OK)));
 
  98                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
 
  99                                 .withBodyFile("OpenstackResponse_Access.json")
 
 100                                 .withStatus(HttpStatus.SC_OK)));
 
 102                 instance.queryVnf("mtn13", "CloudOwner", "1234", "vfname",
 
 103                                 msoRequest, new Holder<>(), new Holder<>(), new Holder<>(),
 
 108         public void deleteVfModuleTest_ExceptionWhileQueryDeployment() throws Exception {
 
 109                 expectedException.expect(VnfException.class);
 
 110                 MsoRequest msoRequest = new MsoRequest();
 
 111                 msoRequest.setRequestId("12345");
 
 112                 msoRequest.setServiceInstanceId("12345");
 
 114                 instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>());
 
 118         public void deleteVfModuleTest_ExceptionWhileDeleteDeployment() throws Exception {
 
 119                 expectedException.expect(VnfException.class);
 
 120                 MsoRequest msoRequest = new MsoRequest();
 
 121                 msoRequest.setRequestId("12345");
 
 122                 msoRequest.setServiceInstanceId("12345");
 
 123                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
 
 124                                 .withBody("{ \"id\": \"123\" }")
 
 125                                 .withStatus(HttpStatus.SC_OK)));
 
 127                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
 
 128                                 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
 
 129                                 .withStatus(HttpStatus.SC_OK)));
 
 131                 wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
 
 132                                 .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
 
 133                                 .withStatus(HttpStatus.SC_OK)));
 
 135                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
 
 136                                 .withBodyFile("OpenstackResponse_Access.json")
 
 137                                 .withStatus(HttpStatus.SC_OK)));
 
 139                 instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>());
 
 143     public void deleteVnfVnfExceptionTest() throws Exception {
 
 144                 expectedException.expect(VnfException.class);
 
 145         MsoRequest msoRequest = new MsoRequest();
 
 146         msoRequest.setRequestId("12345");
 
 147         msoRequest.setServiceInstanceId("12345");
 
 149         instance.deleteVnf("12344", "CloudOwner", "234", "vnfname", msoRequest);
 
 154         public void rollbackVnf() throws Exception {
 
 155                 MsoRequest msoRequest = new MsoRequest();
 
 156                 msoRequest.setRequestId("12345");
 
 157                 msoRequest.setServiceInstanceId("12345");
 
 159         VnfRollback vnfRollback = new VnfRollback();
 
 160         vnfRollback.setModelCustomizationUuid("1234");
 
 161         vnfRollback.setVfModuleStackId("2134");
 
 162         vnfRollback.setVnfId("123");
 
 163         vnfRollback.setModelCustomizationUuid("1234");
 
 165         instance.rollbackVnf(vnfRollback);
 
 169         public void rollbackVnf_Created() throws Exception {
 
 170                 expectedException.expect(VnfException.class);
 
 171                 MsoRequest msoRequest = new MsoRequest();
 
 172                 msoRequest.setRequestId("12345");
 
 173                 msoRequest.setServiceInstanceId("12345");
 
 175                 VnfRollback vnfRollback = new VnfRollback();
 
 176                 vnfRollback.setModelCustomizationUuid("1234");
 
 177                 vnfRollback.setVfModuleStackId("2134");
 
 178                 vnfRollback.setVnfId("123");
 
 179                 vnfRollback.setModelCustomizationUuid("1234");
 
 180                 vnfRollback.setVnfCreated(true);
 
 182                 instance.rollbackVnf(vnfRollback);
 
 186         public void createVfModuleVnfException() throws Exception {
 
 187                 expectedException.expect(VnfException.class);
 
 188                 MsoRequest msoRequest = new MsoRequest();
 
 189                 msoRequest.setRequestId("12345");
 
 190                 msoRequest.setServiceInstanceId("12345");
 
 192                 instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", "123", new HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
 
 196         public void createVfModule_ModelCustUuidIsNull() throws Exception {
 
 197                 expectedException.expect(VnfException.class);
 
 198                 MsoRequest msoRequest = new MsoRequest();
 
 199                 msoRequest.setRequestId("12345");
 
 200                 msoRequest.setServiceInstanceId("12345");
 
 202                 instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", null, new 
 
 203                                 HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
 
 207         public void createVfModule_CloudSiteIdNotFound() throws Exception {
 
 208                 expectedException.expect(VnfException.class);
 
 209                 MsoRequest msoRequest = new MsoRequest();
 
 210                 msoRequest.setRequestId("12345");
 
 211                 msoRequest.setServiceInstanceId("12345");
 
 213                 instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
 
 217         public void createVfModule_MsoCloudifyManagerNotFound() throws Exception {
 
 218                 expectedException.expect(VnfException.class);
 
 219                 MsoRequest msoRequest = new MsoRequest();
 
 220                 msoRequest.setRequestId("12345");
 
 221                 msoRequest.setServiceInstanceId("12345");
 
 223                 instance.createVfModule("mtn13", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
 
 227         public void createVfModule() throws Exception {
 
 228                 expectedException.expect(VnfException.class);
 
 229                 MsoRequest msoRequest = new MsoRequest();
 
 230                 msoRequest.setRequestId("12345");
 
 231                 msoRequest.setServiceInstanceId("12345");
 
 233                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse()
 
 234                                 .withBody("{ \"id\": \"123\" }")
 
 235                                 .withStatus(HttpStatus.SC_OK)));
 
 237                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse()
 
 238                                 .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }")
 
 239                                 .withStatus(HttpStatus.SC_OK)));
 
 241                 wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse()
 
 242                                 .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ")
 
 243                                 .withStatus(HttpStatus.SC_OK)));
 
 245                 wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse()
 
 246                                 .withBodyFile("OpenstackResponse_Access.json")
 
 247                                 .withStatus(HttpStatus.SC_OK)));
 
 249                 instance.createVfModule("mtn13", "CloudOwner", "123", "vf", "v1", "", "vfname", "", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true,  msoRequest, new Holder<>(), new Holder<>(), new Holder<>());
 
 253         public void updateVfModuleVnfException() throws Exception {
 
 254                 expectedException.expect(VnfException.class);
 
 255                 MsoRequest msoRequest = new MsoRequest();
 
 256                 msoRequest.setRequestId("12345");
 
 257                 msoRequest.setServiceInstanceId("12345");
 
 259                 instance.updateVfModule("123", "CloudOwner", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234", new HashMap<>(), msoRequest, new Holder<>(), new Holder<>());
 
 263         public void healthCheckVNFTest() {
 
 264                 instance.healthCheck();
 
 268         public void createVnfTest() {
 
 269                 MsoRequest msoRequest = new MsoRequest();
 
 270                 msoRequest.setRequestId("12345");
 
 271                 msoRequest.setServiceInstanceId("12345");
 
 273                 Map<String, Object> map = new HashMap<>();
 
 274                 map.put("key1", "value1");
 
 276                         instance.createVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
 
 277                                         "volumeGroupHeatStackId|1", map,
 
 278                                         Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, msoRequest, new Holder<>(), new Holder<>(),
 
 280                 } catch (Exception e) {
 
 285         public void updateVnfTest() {
 
 286                 MsoRequest msoRequest = new MsoRequest();
 
 287                 msoRequest.setRequestId("12345");
 
 288                 msoRequest.setServiceInstanceId("12345");
 
 290                 Map<String, Object> map = new HashMap<>();
 
 292                 map.put("key1", "value1");
 
 294                         instance.updateVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD",
 
 295                                         "volumeGroupHeatStackId|1",  map, msoRequest, new Holder<>(),
 
 297                 } catch (Exception e) {
 
 303         public void deleteVnfTest() {
 
 304                 MsoRequest msoRequest = new MsoRequest();
 
 305                 msoRequest.setRequestId("12345");
 
 306                 msoRequest.setServiceInstanceId("12345");
 
 308                         instance.deleteVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest);
 
 309                 } catch (Exception e) {