2  * Copyright 2016-2017, Nokia Corporation
 
   4  * Licensed under the Apache License, Version 2.0 (the "License");
 
   5  * you may not use this file except in compliance with the License.
 
   6  * You may obtain a copy of the License at
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  10  * Unless required by applicable law or agreed to in writing, software
 
  11  * distributed under the License is distributed on an "AS IS" BASIS,
 
  12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13  * See the License for the specific language governing permissions and
 
  14  * limitations under the License.
 
  16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
 
  18 import com.nokia.cbam.lcm.v32.model.AffectedVnfc;
 
  19 import com.nokia.cbam.lcm.v32.model.ResourceHandle;
 
  20 import org.junit.Before;
 
  21 import org.junit.Test;
 
  22 import org.mockito.ArgumentCaptor;
 
  23 import org.mockito.Mock;
 
  24 import org.onap.aai.api.NetworkApi;
 
  25 import org.onap.aai.model.Vnfc;
 
  26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
 
  27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
 
  29 import static junit.framework.TestCase.assertEquals;
 
  30 import static org.mockito.Matchers.eq;
 
  31 import static org.mockito.Mockito.verify;
 
  32 import static org.mockito.Mockito.when;
 
  33 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.AbstractManager.buildRelationshipData;
 
  34 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.TestGenericVnfManager.assertRelation;
 
  35 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
 
  36 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
 
  37 import static org.springframework.test.util.ReflectionTestUtils.setField;
 
  39 public class TestVnfcManager extends TestBase {
 
  40     private ArgumentCaptor<Vnfc> payload = ArgumentCaptor.forClass(Vnfc.class);
 
  43     private AAIRestApiProvider aaiRestApiProvider;
 
  44     private VnfcManager vnfcManager;
 
  46     private NetworkApi networkApi;
 
  50         vnfcManager = new VnfcManager(aaiRestApiProvider, cbamRestApiProvider, driverProperties);
 
  51         setField(VnfcManager.class, "logger", logger);
 
  52         when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
 
  59     public void testUpdate() throws Exception {
 
  60         AffectedVnfc affectedVnfc = new AffectedVnfc();
 
  61         affectedVnfc.setComputeResource(new ResourceHandle());
 
  62         affectedVnfc.getComputeResource().setResourceId("serverProviderId");
 
  63         affectedVnfc.setId("vnfcId");
 
  64         Vnfc existingVnfc = new Vnfc();
 
  65         when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
 
  66         when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(null);
 
  68         vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
 
  70         Vnfc vnfc = payload.getValue();
 
  71         assertEquals("myVnfId_vnfcId", vnfc.getVnfcName());
 
  72         assertEquals("vnfcId", vnfc.getNfcFunction());
 
  73         assertEquals("vnfcId", vnfc.getNfcNamingCode());
 
  74         assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
 
  76         assertRelation(vnfc.getRelationshipList(), "vserver",
 
  77                 buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)),
 
  78                 buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
 
  79                 buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"),
 
  80                 buildRelationshipData("vserver.vserver-id", "serverProviderId"));
 
  87     public void testDelete() throws Exception {
 
  88         AffectedVnfc affectedVnfc = new AffectedVnfc();
 
  89         affectedVnfc.setComputeResource(new ResourceHandle());
 
  90         affectedVnfc.getComputeResource().setResourceId("serverProviderId");
 
  91         affectedVnfc.setId("vnfcId");
 
  92         Vnfc existingVnfc = new Vnfc();
 
  93         existingVnfc.setResourceVersion("v3");
 
  94         existingVnfc.setVnfcName("myVnfId_vnfcId");
 
  95         when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
 
  97         vnfcManager.delete(VNF_ID, affectedVnfc);
 
  99         verify(networkApi).deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3");
 
 106     public void testInheritence() {
 
 107         assertEquals(logger, vnfcManager.getLogger());