Changes needed for MultiStep Actions
[appc.git] / appc-config / appc-flow-controller / provider / src / test / java / org / onap / appc / flow / controller / node / InventoryInfoExtractorTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2018 Nokia. All rights reserved.
6  * Copyright (C) 2018 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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.appc.flow.controller.node;
22
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25
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;
32
33 public class InventoryInfoExtractorTest {
34
35   private SvcLogicContext ctx;
36   private InventoryInfoExtractor inventoryInfoExtractor;
37
38   @Before
39   public void setUp() {
40     inventoryInfoExtractor = new InventoryInfoExtractor();
41     ctx = mock(SvcLogicContext.class);
42   }
43
44   @Test
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
50     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
51     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
52     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
53     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
54
55     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
56     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("1");
57     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
58     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
59
60     when(ctx.getAttribute("tmp.vnfInfo.identity-url")).thenReturn("some-url");
61
62     String vnfId = "some-vnf-id";
63     InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
64
65     Assert.assertEquals(
66         "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, " +
67         "identityUrl=some-url, vm=[Vm [vserverId=some-id-0, vmId=null, " +
68         "vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0]], Vm [vserverId=some-id-1, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-1, vnfcName=some-vnfc-name-1]]]]]",
69         inventoryInfo.toString());
70   }
71
72   @Test
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.identity-url")).thenReturn("some-url");
78
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
84     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
85     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
86     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
87     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
88
89     String vnfId = "some-vnf-id";
90     InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
91
92     Assert.assertEquals(
93             "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, "
94             + "vnfType=some-vnf-type, identityUrl=some-url, vm=[Vm [vserverId=some-id-0, "
95             + "vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0]], "
96             + "Vm [vserverId=some-id-1, vmId=null, vnfc=null]]]]",
97             inventoryInfo.toString());
98   }
99
100   @Test
101   public void full_config__with_zero__vm_count() throws Exception {
102     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
103     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
104     when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("0");
105     when(ctx.getAttribute("tmp.vnfInfo.identity-url")).thenReturn("some-url");
106
107
108     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
109     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
110     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
111     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
112
113     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
114     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
115     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
116     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
117
118     String vnfId = "some-vnf-id";
119     InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
120
121     Assert.assertEquals("InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, "
122             + "vnfType=some-vnf-type, identityUrl=some-url, vm=null]]",
123             inventoryInfo.toString());
124   }
125
126   @Test
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.identity-url")).thenReturn("some-url");
132
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
138     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
139     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
140     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
141     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
142
143     String vnfId = "some-vnf-id";
144     InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
145
146     Assert.assertEquals(
147             "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, "
148             + "vnfType=some-vnf-type, identityUrl=some-url, vm=null]]",
149             inventoryInfo.toString());
150   }
151
152   @Test
153   public void full_config__with_null__vm_count() throws Exception {
154     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name");
155     when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type");
156     when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(null);
157     when(ctx.getAttribute("tmp.vnfInfo.identity-url")).thenReturn("some-url");
158
159     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0");
160     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2");
161     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0");
162     when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0");
163
164     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1");
165     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0");
166     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1");
167     when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1");
168
169     String vnfId = "some-vnf-id";
170     InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId);
171
172     Assert.assertEquals(
173             "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, "
174             + "vnfType=some-vnf-type, identityUrl=some-url, vm=null]]",
175             inventoryInfo.toString());
176   }
177
178   @Test
179   public void testGetIdentityUrl_from_payload() throws Exception{
180       InventoryInfoExtractor info = new InventoryInfoExtractor();
181       when(ctx.getAttribute("AICIdentity")).thenReturn("some_url");
182       VnfInfo vnfInfo = new VnfInfo();
183       String url=info.getIdentityUrl(ctx, vnfInfo, "123");
184       System.out.println(info.toString());
185       Assert.assertEquals(url, "some_url");
186   }
187
188   @Test
189   public void testGetIdentityUrl_from_Inventory() throws Exception{
190       InventoryInfoExtractor info = new InventoryInfoExtractor();
191       when(ctx.getAttribute("tmp.vnfInfo.identity-url")).thenReturn("some_url_from_inventory");
192       VnfInfo vnfInfo = new VnfInfo();
193       String url=info.getIdentityUrl(ctx, vnfInfo, "123");
194       System.out.println(info.toString());
195       Assert.assertEquals(url, "some_url_from_inventory");
196   }
197
198 }