2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2018 Nokia. 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=========================================================
 
  20 package org.onap.appc.flow.controller.node;
 
  22 import static org.mockito.Mockito.mock;
 
  23 import static org.mockito.Mockito.when;
 
  25 import org.junit.Assert;
 
  26 import org.junit.Before;
 
  27 import org.junit.Test;
 
  28 import org.onap.appc.flow.controller.interfaceData.InventoryInfo;
 
  29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  31 public class InventoryInfoExtractorTest {
 
  33   private SvcLogicContext ctx;
 
  34   private InventoryInfoExtractor inventoryInfoExtractor;
 
  38     inventoryInfoExtractor = new InventoryInfoExtractor();
 
  39     ctx = mock(SvcLogicContext.class);
 
  43   public void full_config() throws Exception {
 
  44     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
 
  45     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
 
  46     when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2");
 
  48     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
 
  49     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
 
  50     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
 
  51     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
 
  53     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
 
  54     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("1");
 
  55     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
 
  56     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
 
  58     String vnfId = "some-vnf-id";
 
  59     InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
 
  62         "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, vm=[Vm [vserverId=some-id-0, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0]], Vm [vserverId=some-id-1, vnfc=Vnfcslist [vnfcType=some-vnfc-type-1, vnfcName=some-vnfc-name-1]]]]]",
 
  63         inventoryInfo.toString());
 
  67   public void full_config__with_zero__vnfc_count() throws Exception {
 
  68     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
 
  69     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
 
  70     when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2");
 
  72     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
 
  73     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
 
  74     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
 
  75     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
 
  77     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
 
  78     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
 
  79     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
 
  80     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
 
  82     String vnfId = "some-vnf-id";
 
  83     InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
 
  86         "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, vm=[Vm [vserverId=some-id-0, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0]], Vm [vserverId=some-id-1, vnfc=null]]]]",
 
  87         inventoryInfo.toString());
 
  91   public void full_config__with_zero__vm_count() throws Exception {
 
  92     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
 
  93     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
 
  94     when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("0");
 
  96     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
 
  97     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
 
  98     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
 
  99     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
 
 101     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
 
 102     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
 
 103     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
 
 104     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
 
 106     String vnfId = "some-vnf-id";
 
 107     InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
 
 110         "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, vm=null]]",
 
 111         inventoryInfo.toString());
 
 115   public void full_config__with_empty__vm_count() throws Exception {
 
 116     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
 
 117     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
 
 118     when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("");
 
 120     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
 
 121     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
 
 122     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
 
 123     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
 
 125     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
 
 126     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
 
 127     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
 
 128     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
 
 130     String vnfId = "some-vnf-id";
 
 131     InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
 
 134         "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, vm=null]]",
 
 135         inventoryInfo.toString());
 
 139   public void full_config__with_null__vm_count() throws Exception {
 
 140     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
 
 141     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
 
 142     when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(null);
 
 144     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
 
 145     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
 
 146     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
 
 147     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
 
 149     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
 
 150     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
 
 151     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
 
 152     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
 
 154     String vnfId = "some-vnf-id";
 
 155     InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
 
 158         "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, vm=null]]",
 
 159         inventoryInfo.toString());