2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modification Copyright (C) 2018 IBM.
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.aai.client.aai;
28 import static org.junit.Assert.assertEquals;
30 import java.util.HashMap;
33 import org.apache.commons.lang3.StringUtils;
34 import org.junit.Test;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
38 import com.att.eelf.configuration.EELFLogger;
39 import com.att.eelf.configuration.EELFManager;
41 public class TestAaiService {
44 private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAaiService.class);
45 private AAIClient aaiClient;
48 public void testGetGenericVnfInfo() throws Exception {
50 MockAaiService mockAai = new MockAaiService(aaiClient);
52 Map<String, String> inParams = new HashMap<String, String>();
53 inParams.put("vnfId", "ibcxvm0000");
54 inParams.put("responsePrefix", "tmp.vnfInfo");
56 SvcLogicContext ctx = new SvcLogicContext();
58 mockAai.getGenericVnfInfo(inParams, ctx);
60 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"), "vUSP-Metaswitch");
61 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2");
62 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcx001vm001-id");
63 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcx000000");
67 public void testGetVmInfo() throws Exception {
69 MockAaiService mockAai = new MockAaiService(aaiClient);
71 Map<String, String> inParams = new HashMap<String, String>();
72 inParams.put("vserverId", "vserverId1");
73 inParams.put("tenantId", "tenantId1");
74 inParams.put("cloudOwner", "cloudOwner1");
75 inParams.put("cloudRegionId", "cloudRegionId1");
76 inParams.put("responsePrefix", "tmp.vnfInfo");
78 SvcLogicContext ctx = new SvcLogicContext();
80 mockAai.getVMInfo(inParams, ctx);
84 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vserver-name"), "ibcx0000000");
85 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc-count"), "1");
86 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vf-module-id"), "vfModule1");
87 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc[0].vnfc-name"), "ibcx0001vm001vnfc1");
92 public void testGetVnfcInfo() throws Exception {
94 MockAaiService mockAai = new MockAaiService(aaiClient);
96 Map<String, String> inParams = new HashMap<String, String>();
97 inParams.put("vnfcName", "vnfcName1");
99 inParams.put("responsePrefix", "tmp.vnfInfo");
101 SvcLogicContext ctx = new SvcLogicContext();
103 mockAai.getVnfcInfo(inParams, ctx);
107 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-type"), null);
108 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-function-code"), null);
109 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.group-notation"), "grpnot1");
114 public void testGetFirstVnfcNameForVnfcType() throws Exception {
116 MockAaiService mockAai = new MockAaiService(aaiClient);
118 String prefix = "tmp.vnfInfo.";
120 SvcLogicContext ctx = new SvcLogicContext(); // VNFC with specified vnfc
122 mockAai.populateFirstVnfcData(ctx, prefix);
123 String firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc");
124 assertEquals(firstVnfcName, "vnfcname3");
126 ctx = new SvcLogicContext(); // no VMS found
127 firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc");
128 assertEquals(firstVnfcName, null);
130 ctx = new SvcLogicContext(); // no VMS found with specified type
131 mockAai.populateFirstVnfcData(ctx, prefix);
132 firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "test");
133 assertEquals(firstVnfcName, null);
138 public void testGroupNotation() throws Exception {
140 MockAaiService mockAai = new MockAaiService(aaiClient);
142 String prefix = "tmp.vnfInfo.";
144 SvcLogicContext ctx = new SvcLogicContext();
145 mockAai.populateGroupNotation(ctx, prefix);
147 // printContext(ctx);
148 String grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002");
149 assertEquals(grpNotation, "grpNot2");
151 ctx = new SvcLogicContext(); // no VMS found
152 grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002");
153 assertEquals(grpNotation, null);
155 ctx = new SvcLogicContext(); // no VMS found with specified name
156 mockAai.populateGroupNotation(ctx, prefix);
157 grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "test");
158 assertEquals(grpNotation, null);
163 public void testGetGroupNotation() throws Exception {
165 MockAaiService mockAai = new MockAaiService(aaiClient);
167 String prefix = "tmp.vnfInfo.";
169 SvcLogicContext ctx = new SvcLogicContext();
171 String grpNotation = mockAai.getGroupNotation("fixed-value", "2", null, null, null, null, null,null, 0);
172 assertEquals(grpNotation, "2");
174 mockAai.populateFirstVnfcData(ctx, prefix); // Existing VNFC Found
175 grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix,
176 ctx, "ssc", null, 0);
177 assertEquals(grpNotation, "vnfcname32");
179 ctx = new SvcLogicContext(); // no vnfcs exist in A&AI- Use current
181 grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix,
182 ctx, "ssc", null, 0);
183 assertEquals(grpNotation, "currentVnfcName2");
185 ctx = new SvcLogicContext();
186 mockAai.populateGroupNotation(ctx, prefix);
187 grpNotation = mockAai.getGroupNotation("relative-value", "same", "currentVnfcName", "ibcxvm0003", prefix, ctx,
189 assertEquals(grpNotation, "grpNot2");
191 ctx = new SvcLogicContext();
192 mockAai.populateGroupNotation(ctx, prefix);
193 grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0006", prefix, ctx,
195 assertEquals(grpNotation, "5");
197 ctx = new SvcLogicContext();
198 mockAai.populateGroupNotation(ctx, prefix);
199 grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0003", prefix, ctx,
201 assertEquals(grpNotation, null); // Null if grpNotation is not numeric
206 public void testInsertVnfcs() throws Exception {
208 MockAaiService mockAai = new MockAaiService(aaiClient);
210 Map<String, String> inParams = new HashMap<String, String>();
212 inParams.put("responsePrefix", "tmp.vnfInfo");
214 SvcLogicContext ctx = new SvcLogicContext();
216 mockAai.populateVnfcRef(ctx);
218 mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
220 // mockAai.insertVnfcs(inParams,ctx,2, 2) ;
224 public void testUpdateVServerStatus() throws Exception {
226 MockAaiService mockAai = new MockAaiService(aaiClient);
228 Map<String, String> inParams = new HashMap<String, String>();
230 inParams.put("responsePrefix", "tmp.vnfInfo");
232 SvcLogicContext ctx = new SvcLogicContext();
234 mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
236 mockAai.updateVServerStatus(inParams, ctx, 2);
240 public void testInsertVnfcsForFirstVnfc() throws Exception {
242 MockAaiService mockAai = new MockAaiService(aaiClient);
244 Map<String, String> inParams = new HashMap<String, String>();
246 inParams.put("responsePrefix", "tmp.vnfInfo");
248 SvcLogicContext ctx = new SvcLogicContext();
250 mockAai.populateVnfcRefFirstVnfcName(ctx);
252 mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
254 mockAai.insertVnfcs(inParams, ctx, 2, 2,"vfModuleId1");
259 public void testInsertVnfcsForRelativeValueSame() throws Exception {
261 MockAaiService mockAai = new MockAaiService(aaiClient);
263 Map<String, String> inParams = new HashMap<String, String>();
265 inParams.put("responsePrefix", "tmp.vnfInfo");
267 SvcLogicContext ctx = new SvcLogicContext();
269 mockAai.populateVnfcRefRelValueSame(ctx);
271 mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
273 mockAai.insertVnfcs(inParams, ctx, 2, 2, null);
275 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001");
276 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj");
277 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX");
278 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1");
279 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001");
280 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj");
281 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX");
282 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "1");
286 public void testInsertVnfcsForRelativeValueNext() throws Exception {
288 MockAaiService mockAai = new MockAaiService(aaiClient);
290 Map<String, String> inParams = new HashMap<String, String>();
292 inParams.put("responsePrefix", "tmp.vnfInfo");
294 SvcLogicContext ctx = new SvcLogicContext();
296 mockAai.populateVnfcRefRelValueNext(ctx);
298 mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
300 mockAai.insertVnfcs(inParams, ctx, 2, 2,null);
304 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001");
305 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj");
306 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX");
307 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1");
308 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001");
309 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj");
310 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX");
311 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "2");
315 public void testUpdateVnfStatus() throws Exception {
317 MockAaiService mockAai = new MockAaiService(aaiClient);
319 Map<String, String> inParams = new HashMap<String, String>();
321 inParams.put("responsePrefix", "tmp.vnfInfo");
323 SvcLogicContext ctx = new SvcLogicContext();
325 mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
327 mockAai.updateVnfStatus(inParams, ctx);
331 public void testReadResource() throws Exception {
333 MockAaiService mockAai = new MockAaiService(aaiClient);
334 // AaiService mockAai = new AaiService(new AAIClientMock());
336 String vnfId = "ibcx0001v";
337 String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'";
338 String resourceType = "generic-vnf";
339 String queryPrefix = "vnfInfo";
340 SvcLogicContext ctx = mockAai.readResource(resourceKey, queryPrefix, resourceType);
342 // System.out.println("VNF TYPE " + queryPrefix + ".vnf.vnf-type");
344 assertEquals(ctx.getAttribute("vnfInfo.vnf-type"), "vUSP-Metaswitch");
347 private void printContext(SvcLogicContext ctx) throws Exception {
348 for (String key : ctx.getAttributeKeySet()) {
349 log.info(" KEY " + key);
350 log.info(" VALUE " + ctx.getAttribute(key));
355 public void testGetGroupNotationForExistingValue() throws Exception {
357 SvcLogicContext ctx = new SvcLogicContext();
358 ctx.setAttribute("req-vf-module-id", "vfmodule01");
359 ctx.setAttribute("tmp.vnfInfo.vm[0].vf-module-id", "vfmodule01");
360 ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-function-code", "fc1");
361 ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn1");
362 ctx.setAttribute("tmp.vnfInfo.vm[1].vf-module-id", "vfmodule01");
363 ctx.setAttribute("tmp.vnfInfo.vm[1].vnfc-function-code", "fc1");
364 ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-function-code", "fc1");
365 ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn2");
366 MockAaiService aai=new MockAaiService(aaiClient);
367 String groupNotationValue1 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 2);
368 assertEquals (groupNotationValue1,null);
370 ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn1");
371 ctx.setAttribute("tmp.vnfInfo.vm[1].group-notation", "gn1");
372 String groupNotationValue2 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 2);
373 assertEquals (groupNotationValue2,"gn1");
375 ctx.setAttribute("tmp.vnfInfo.vm[2].vf-module-id", "vfmodule01");
376 ctx.setAttribute("tmp.vnfInfo.vm[2].vnfc-function-code", "fc1");
377 ctx.setAttribute("tmp.vnfInfo.vm[2].group-notation", "gn2");
378 String groupNotationValue3 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 3);
379 assertEquals (groupNotationValue3,null);
381 ctx.setAttribute("tmp.vnfInfo.vm[2].group-notation", "gn1");
382 String groupNotationValue4 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 3);
383 assertEquals (groupNotationValue4,"gn1");
388 public void testgetIdentityUrl() throws Exception {
390 MockAaiService mockAai = new MockAaiService(aaiClient);
392 Map<String, String> inParams = new HashMap<String, String>();
393 inParams.put("responsePrefix", "tmp.vnfInfo");
394 inParams.put("cloudOwner", "testCloudOwner");
395 inParams.put("cloudRegionId", "testCloudRegionId");
397 SvcLogicContext ctx = new SvcLogicContext();
398 mockAai.getIdentityUrl(inParams, ctx);
399 assertEquals(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url"), "TestUrl");
404 public void testAddvnfc()
406 MockAaiService mockAai = new MockAaiService(aaiClient);
407 Map<String, String> params=mockAai.getExpectedParams();
408 mockAai.addVnfc("ibcxvm0002func0001",params , "");