2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
6 * Copyright (C) 2018-2019 AT&T 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=========================================================
21 package org.onap.appc.flow.controller.node;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.appc.flow.controller.interfaceData.InventoryInfo;
30 import org.onap.appc.flow.controller.interfaceData.VnfInfo;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 public class InventoryInfoExtractorTest {
35 private SvcLogicContext ctx;
36 private InventoryInfoExtractor inventoryInfoExtractor;
40 inventoryInfoExtractor = new InventoryInfoExtractor();
41 ctx = mock(SvcLogicContext.class);
45 public void full_config() throws Exception {
46 when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
47 when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
48 when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2");
49 when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url");
51 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
52 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
53 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
54 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
55 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0");
57 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
58 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("1");
59 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
60 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
61 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1");
63 String vnfId = "some-vnf-id";
64 InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
67 "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=[Vm [vserverId=some-id-0, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0, vnfcFunctionCode=some-vnfc-function-code-0]], Vm [vserverId=some-id-1, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-1, vnfcName=some-vnfc-name-1, vnfcFunctionCode=some-vnfc-function-code-1]]]]]",
68 inventoryInfo.toString());
69 // System.out.println("New inventory info"+inventoryInfo.toString());
73 public void full_config__with_zero__vnfc_count() throws Exception {
74 when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
75 when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
76 when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2");
77 when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url");
79 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
80 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
81 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
82 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
83 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0");
85 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
86 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
87 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
88 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
89 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1");
91 String vnfId = "some-vnf-id";
92 InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
95 "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=[Vm [vserverId=some-id-0, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0, vnfcFunctionCode=some-vnfc-function-code-0]], Vm [vserverId=some-id-1, vmId=null, vnfc=null]]]]",
96 inventoryInfo.toString());
100 public void full_config__with_zero__vm_count() throws Exception {
101 when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
102 when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
103 when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("0");
104 when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url");
106 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
107 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
108 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
109 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
110 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0");
112 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
113 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
114 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
115 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
116 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1");
118 String vnfId = "some-vnf-id";
119 InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
122 "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=null]]",
123 inventoryInfo.toString());
127 public void full_config__with_empty__vm_count() throws Exception {
128 when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
129 when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
130 when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("");
131 when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url");
133 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
134 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
135 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
136 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
137 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0");
139 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
140 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
141 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
142 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
143 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1");
145 String vnfId = "some-vnf-id";
146 InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
149 "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=null]]",
150 inventoryInfo.toString());
154 public void full_config__with_null__vm_count() throws Exception {
155 when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
156 when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
157 when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(null);
158 when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url");
160 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
161 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
162 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
163 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
164 when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0");
166 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
167 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
168 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
169 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
170 when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1");
172 String vnfId = "some-vnf-id";
173 InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
176 "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=null]]",
177 inventoryInfo.toString());
181 public void testGetIdentityUrl_from_payload() throws Exception {
182 InventoryInfoExtractor info = new InventoryInfoExtractor();
183 when(ctx.getAttribute("identity-url")).thenReturn("some_url");
184 VnfInfo vnfInfo = new VnfInfo();
185 String url = info.getIdentityUrl(ctx, vnfInfo, "123");
186 System.out.println(info.toString());
187 Assert.assertEquals(url, "some_url");
191 public void testGetIdentityUrl_from_Inventory() throws Exception {
192 InventoryInfoExtractor info = new InventoryInfoExtractor();
193 when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some_url_from_inventory");
194 VnfInfo vnfInfo = new VnfInfo();
195 String url = info.getIdentityUrl(ctx, vnfInfo, "123");
196 System.out.println(info.toString());
197 Assert.assertEquals(url, "some_url_from_inventory");