2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.aai.client.aai;
26 import static org.junit.Assert.assertEquals;
28 import java.util.HashMap;
31 import org.apache.commons.lang3.StringUtils;
32 import org.junit.Test;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
39 public class TestAaiService {
42 private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAaiService.class);
43 private AAIClient aaiClient;
46 public void testGetGenericVnfInfo() throws Exception {
48 MockAaiService mockAai = new MockAaiService(aaiClient);
50 Map<String, String> inParams = new HashMap<String, String>();
51 inParams.put("vnfId", "ibcxvm0000");
52 inParams.put("responsePrefix", "tmp.vnfInfo");
54 SvcLogicContext ctx = new SvcLogicContext();
56 mockAai.getGenericVnfInfo(inParams, ctx);
58 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"), "vUSP-Metaswitch");
59 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2");
60 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcx001vm001-id");
61 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcx000000");
65 public void testGetVmInfo() throws Exception {
67 MockAaiService mockAai = new MockAaiService(aaiClient);
69 Map<String, String> inParams = new HashMap<String, String>();
70 inParams.put("vserverId", "vserverId1");
71 inParams.put("tenantId", "tenantId1");
72 inParams.put("cloudOwner", "cloudOwner1");
73 inParams.put("cloudRegionId", "cloudRegionId1");
74 inParams.put("responsePrefix", "tmp.vnfInfo");
76 SvcLogicContext ctx = new SvcLogicContext();
78 mockAai.getVMInfo(inParams, ctx);
82 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vserver-name"), "ibcx0000000");
83 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc-count"), "1");
84 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vf-module-id"), "vfModule1");
85 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc[0].vnfc-name"), "ibcx0001vm001vnfc1");
90 public void testGetVnfcInfo() throws Exception {
92 MockAaiService mockAai = new MockAaiService(aaiClient);
94 Map<String, String> inParams = new HashMap<String, String>();
95 inParams.put("vnfcName", "vnfcName1");
97 inParams.put("responsePrefix", "tmp.vnfInfo");
99 SvcLogicContext ctx = new SvcLogicContext();
101 mockAai.getVnfcInfo(inParams, ctx);
105 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-type"), null);
106 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-function-code"), null);
107 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.group-notation"), "grpnot1");
112 public void testGetFirstVnfcNameForVnfcType() throws Exception {
114 MockAaiService mockAai = new MockAaiService(aaiClient);
116 String prefix = "tmp.vnfInfo.";
118 SvcLogicContext ctx = new SvcLogicContext(); // VNFC with specified vnfc
120 mockAai.populateFirstVnfcData(ctx, prefix);
121 String firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc");
122 assertEquals(firstVnfcName, "vnfcname3");
124 ctx = new SvcLogicContext(); // no VMS found
125 firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc");
126 assertEquals(firstVnfcName, null);
128 ctx = new SvcLogicContext(); // no VMS found with specified type
129 mockAai.populateFirstVnfcData(ctx, prefix);
130 firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "test");
131 assertEquals(firstVnfcName, null);
136 public void testGroupNotation() throws Exception {
138 MockAaiService mockAai = new MockAaiService(aaiClient);
140 String prefix = "tmp.vnfInfo.";
142 SvcLogicContext ctx = new SvcLogicContext();
143 mockAai.populateGroupNotation(ctx, prefix);
145 // printContext(ctx);
146 String grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002");
147 assertEquals(grpNotation, "grpNot2");
149 ctx = new SvcLogicContext(); // no VMS found
150 grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002");
151 assertEquals(grpNotation, null);
153 ctx = new SvcLogicContext(); // no VMS found with specified name
154 mockAai.populateGroupNotation(ctx, prefix);
155 grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "test");
156 assertEquals(grpNotation, null);
161 public void testGetGroupNotation() throws Exception {
163 MockAaiService mockAai = new MockAaiService(aaiClient);
165 String prefix = "tmp.vnfInfo.";
167 SvcLogicContext ctx = new SvcLogicContext();
169 String grpNotation = mockAai.getGroupNotation("fixed-value", "2", null, null, null, null, null,null, 0);
170 assertEquals(grpNotation, "2");
172 mockAai.populateFirstVnfcData(ctx, prefix); // Existing VNFC Found
173 grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix,
174 ctx, "ssc", null, 0);
175 assertEquals(grpNotation, "vnfcname32");
177 ctx = new SvcLogicContext(); // no vnfcs exist in A&AI- Use current
179 grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix,
180 ctx, "ssc", null, 0);
181 assertEquals(grpNotation, "currentVnfcName2");
183 ctx = new SvcLogicContext();
184 mockAai.populateGroupNotation(ctx, prefix);
185 grpNotation = mockAai.getGroupNotation("relative-value", "same", "currentVnfcName", "ibcxvm0003", prefix, ctx,
187 assertEquals(grpNotation, "grpNot2");
189 ctx = new SvcLogicContext();
190 mockAai.populateGroupNotation(ctx, prefix);
191 grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0006", prefix, ctx,
193 assertEquals(grpNotation, "5");
195 ctx = new SvcLogicContext();
196 mockAai.populateGroupNotation(ctx, prefix);
197 grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0003", prefix, ctx,
199 assertEquals(grpNotation, null); // Null if grpNotation is not numeric
204 public void testInsertVnfcs() throws Exception {
206 MockAaiService mockAai = new MockAaiService(aaiClient);
208 Map<String, String> inParams = new HashMap<String, String>();
210 inParams.put("responsePrefix", "tmp.vnfInfo");
212 SvcLogicContext ctx = new SvcLogicContext();
214 mockAai.populateVnfcRef(ctx);
216 mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
218 // mockAai.insertVnfcs(inParams,ctx,2, 2) ;
222 public void testUpdateVServerStatus() throws Exception {
224 MockAaiService mockAai = new MockAaiService(aaiClient);
226 Map<String, String> inParams = new HashMap<String, String>();
228 inParams.put("responsePrefix", "tmp.vnfInfo");
230 SvcLogicContext ctx = new SvcLogicContext();
232 mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
234 mockAai.updateVServerStatus(inParams, ctx, 2);
238 public void testInsertVnfcsForFirstVnfc() throws Exception {
240 MockAaiService mockAai = new MockAaiService(aaiClient);
242 Map<String, String> inParams = new HashMap<String, String>();
244 inParams.put("responsePrefix", "tmp.vnfInfo");
246 SvcLogicContext ctx = new SvcLogicContext();
248 mockAai.populateVnfcRefFirstVnfcName(ctx);
250 mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
252 mockAai.insertVnfcs(inParams, ctx, 2, 2,"vfModuleId1");
257 public void testInsertVnfcsForRelativeValueSame() throws Exception {
259 MockAaiService mockAai = new MockAaiService(aaiClient);
261 Map<String, String> inParams = new HashMap<String, String>();
263 inParams.put("responsePrefix", "tmp.vnfInfo");
265 SvcLogicContext ctx = new SvcLogicContext();
267 mockAai.populateVnfcRefRelValueSame(ctx);
269 mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
271 mockAai.insertVnfcs(inParams, ctx, 2, 2, null);
273 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001");
274 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj");
275 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX");
276 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1");
277 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001");
278 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj");
279 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX");
280 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "1");
284 public void testInsertVnfcsForRelativeValueNext() throws Exception {
286 MockAaiService mockAai = new MockAaiService(aaiClient);
288 Map<String, String> inParams = new HashMap<String, String>();
290 inParams.put("responsePrefix", "tmp.vnfInfo");
292 SvcLogicContext ctx = new SvcLogicContext();
294 mockAai.populateVnfcRefRelValueNext(ctx);
296 mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
298 mockAai.insertVnfcs(inParams, ctx, 2, 2,null);
302 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001");
303 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj");
304 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX");
305 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1");
306 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001");
307 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj");
308 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX");
309 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "2");
313 public void testUpdateVnfStatus() throws Exception {
315 MockAaiService mockAai = new MockAaiService(aaiClient);
317 Map<String, String> inParams = new HashMap<String, String>();
319 inParams.put("responsePrefix", "tmp.vnfInfo");
321 SvcLogicContext ctx = new SvcLogicContext();
323 mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
325 mockAai.updateVnfStatus(inParams, ctx);
329 public void testReadResource() throws Exception {
331 MockAaiService mockAai = new MockAaiService(aaiClient);
332 // AaiService mockAai = new AaiService(new AAIClientMock());
334 String vnfId = "ibcx0001v";
335 String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'";
336 String resourceType = "generic-vnf";
337 String queryPrefix = "vnfInfo";
338 SvcLogicContext ctx = mockAai.readResource(resourceKey, queryPrefix, resourceType);
340 // System.out.println("VNF TYPE " + queryPrefix + ".vnf.vnf-type");
342 assertEquals(ctx.getAttribute("vnfInfo.vnf-type"), "vUSP-Metaswitch");
345 private void printContext(SvcLogicContext ctx) throws Exception {
346 for (String key : ctx.getAttributeKeySet()) {
347 log.info(" KEY " + key);
348 log.info(" VALUE " + ctx.getAttribute(key));
353 public void testGetGroupNotationForExistingValue() throws Exception {
355 SvcLogicContext ctx = new SvcLogicContext();
356 ctx.setAttribute("req-vf-module-id", "vfmodule01");
357 ctx.setAttribute("tmp.vnfInfo.vm[0].vf-module-id", "vfmodule01");
358 ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-function-code", "fc1");
359 ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn1");
360 ctx.setAttribute("tmp.vnfInfo.vm[1].vf-module-id", "vfmodule01");
361 ctx.setAttribute("tmp.vnfInfo.vm[1].vnfc-function-code", "fc1");
362 ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-function-code", "fc1");
363 ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn2");
364 MockAaiService aai=new MockAaiService(aaiClient);
365 String groupNotationValue1 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 2);
366 assertEquals (groupNotationValue1,null);
368 ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn1");
369 ctx.setAttribute("tmp.vnfInfo.vm[1].group-notation", "gn1");
370 String groupNotationValue2 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 2);
371 assertEquals (groupNotationValue2,"gn1");
373 ctx.setAttribute("tmp.vnfInfo.vm[2].vf-module-id", "vfmodule01");
374 ctx.setAttribute("tmp.vnfInfo.vm[2].vnfc-function-code", "fc1");
375 ctx.setAttribute("tmp.vnfInfo.vm[2].group-notation", "gn2");
376 String groupNotationValue3 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 3);
377 assertEquals (groupNotationValue3,null);
379 ctx.setAttribute("tmp.vnfInfo.vm[2].group-notation", "gn1");
380 String groupNotationValue4 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 3);
381 assertEquals (groupNotationValue4,"gn1");