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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.aai.client.aai;
27 import static org.junit.Assert.assertEquals;
29 import java.util.HashMap;
32 import org.apache.commons.lang3.StringUtils;
33 import org.junit.Test;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
40 public class TestAaiService {
43 private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAaiService.class);
44 private AAIClient aaiClient;
47 public void testGetGenericVnfInfo() throws Exception {
49 MockAaiService mockAai = new MockAaiService(aaiClient);
51 Map<String, String> inParams = new HashMap<String, String>();
52 inParams.put("vnfId", "ibcxvm0000");
53 inParams.put("responsePrefix", "tmp.vnfInfo");
55 SvcLogicContext ctx = new SvcLogicContext();
57 mockAai.getGenericVnfInfo(inParams, ctx);
59 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"), "vUSP-Metaswitch");
60 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2");
61 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcx001vm001-id");
62 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcx000000");
66 public void testGetVmInfo() throws Exception {
68 MockAaiService mockAai = new MockAaiService(aaiClient);
70 Map<String, String> inParams = new HashMap<String, String>();
71 inParams.put("vserverId", "vserverId1");
72 inParams.put("tenantId", "tenantId1");
73 inParams.put("cloudOwner", "cloudOwner1");
74 inParams.put("cloudRegionId", "cloudRegionId1");
75 inParams.put("responsePrefix", "tmp.vnfInfo");
77 SvcLogicContext ctx = new SvcLogicContext();
79 mockAai.getVMInfo(inParams, ctx);
83 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vserver-name"), "ibcx0000000");
84 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc-count"), "1");
85 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vf-module-id"), "vfModule1");
86 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc[0].vnfc-name"), "ibcx0001vm001vnfc1");
91 public void testGetVnfcInfo() throws Exception {
93 MockAaiService mockAai = new MockAaiService(aaiClient);
95 Map<String, String> inParams = new HashMap<String, String>();
96 inParams.put("vnfcName", "vnfcName1");
98 inParams.put("responsePrefix", "tmp.vnfInfo");
100 SvcLogicContext ctx = new SvcLogicContext();
102 mockAai.getVnfcInfo(inParams, ctx);
106 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-type"), null);
107 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-function-code"), null);
108 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.group-notation"), "grpnot1");
113 public void testGetFirstVnfcNameForVnfcType() throws Exception {
115 MockAaiService mockAai = new MockAaiService(aaiClient);
117 String prefix = "tmp.vnfInfo.";
119 SvcLogicContext ctx = new SvcLogicContext(); // VNFC with specified vnfc
121 mockAai.populateFirstVnfcData(ctx, prefix);
122 String firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc");
123 assertEquals(firstVnfcName, "vnfcname3");
125 ctx = new SvcLogicContext(); // no VMS found
126 firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc");
127 assertEquals(firstVnfcName, null);
129 ctx = new SvcLogicContext(); // no VMS found with specified type
130 mockAai.populateFirstVnfcData(ctx, prefix);
131 firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "test");
132 assertEquals(firstVnfcName, null);
137 public void testGroupNotation() throws Exception {
139 MockAaiService mockAai = new MockAaiService(aaiClient);
141 String prefix = "tmp.vnfInfo.";
143 SvcLogicContext ctx = new SvcLogicContext();
144 mockAai.populateGroupNotation(ctx, prefix);
146 // printContext(ctx);
147 String grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002");
148 assertEquals(grpNotation, "grpNot2");
150 ctx = new SvcLogicContext(); // no VMS found
151 grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002");
152 assertEquals(grpNotation, null);
154 ctx = new SvcLogicContext(); // no VMS found with specified name
155 mockAai.populateGroupNotation(ctx, prefix);
156 grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "test");
157 assertEquals(grpNotation, null);
162 public void testGetGroupNotation() throws Exception {
164 MockAaiService mockAai = new MockAaiService(aaiClient);
166 String prefix = "tmp.vnfInfo.";
168 SvcLogicContext ctx = new SvcLogicContext();
170 String grpNotation = mockAai.getGroupNotation("fixed-value", "2", null, null, null, null, null,null, 0);
171 assertEquals(grpNotation, "2");
173 mockAai.populateFirstVnfcData(ctx, prefix); // Existing VNFC Found
174 grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix,
175 ctx, "ssc", null, 0);
176 assertEquals(grpNotation, "vnfcname32");
178 ctx = new SvcLogicContext(); // no vnfcs exist in A&AI- Use current
180 grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix,
181 ctx, "ssc", null, 0);
182 assertEquals(grpNotation, "currentVnfcName2");
184 ctx = new SvcLogicContext();
185 mockAai.populateGroupNotation(ctx, prefix);
186 grpNotation = mockAai.getGroupNotation("relative-value", "same", "currentVnfcName", "ibcxvm0003", prefix, ctx,
188 assertEquals(grpNotation, "grpNot2");
190 ctx = new SvcLogicContext();
191 mockAai.populateGroupNotation(ctx, prefix);
192 grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0006", prefix, ctx,
194 assertEquals(grpNotation, "5");
196 ctx = new SvcLogicContext();
197 mockAai.populateGroupNotation(ctx, prefix);
198 grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0003", prefix, ctx,
200 assertEquals(grpNotation, null); // Null if grpNotation is not numeric
205 public void testInsertVnfcs() throws Exception {
207 MockAaiService mockAai = new MockAaiService(aaiClient);
209 Map<String, String> inParams = new HashMap<String, String>();
211 inParams.put("responsePrefix", "tmp.vnfInfo");
213 SvcLogicContext ctx = new SvcLogicContext();
215 mockAai.populateVnfcRef(ctx);
217 mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
219 // mockAai.insertVnfcs(inParams,ctx,2, 2) ;
223 public void testUpdateVServerStatus() throws Exception {
225 MockAaiService mockAai = new MockAaiService(aaiClient);
227 Map<String, String> inParams = new HashMap<String, String>();
229 inParams.put("responsePrefix", "tmp.vnfInfo");
231 SvcLogicContext ctx = new SvcLogicContext();
233 mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
235 mockAai.updateVServerStatus(inParams, ctx, 2);
239 public void testInsertVnfcsForFirstVnfc() throws Exception {
241 MockAaiService mockAai = new MockAaiService(aaiClient);
243 Map<String, String> inParams = new HashMap<String, String>();
245 inParams.put("responsePrefix", "tmp.vnfInfo");
247 SvcLogicContext ctx = new SvcLogicContext();
249 mockAai.populateVnfcRefFirstVnfcName(ctx);
251 mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
253 mockAai.insertVnfcs(inParams, ctx, 2, 2,"vfModuleId1");
258 public void testInsertVnfcsForRelativeValueSame() throws Exception {
260 MockAaiService mockAai = new MockAaiService(aaiClient);
262 Map<String, String> inParams = new HashMap<String, String>();
264 inParams.put("responsePrefix", "tmp.vnfInfo");
266 SvcLogicContext ctx = new SvcLogicContext();
268 mockAai.populateVnfcRefRelValueSame(ctx);
270 mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
272 mockAai.insertVnfcs(inParams, ctx, 2, 2, null);
274 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001");
275 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj");
276 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX");
277 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1");
278 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001");
279 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj");
280 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX");
281 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "1");
285 public void testInsertVnfcsForRelativeValueNext() throws Exception {
287 MockAaiService mockAai = new MockAaiService(aaiClient);
289 Map<String, String> inParams = new HashMap<String, String>();
291 inParams.put("responsePrefix", "tmp.vnfInfo");
293 SvcLogicContext ctx = new SvcLogicContext();
295 mockAai.populateVnfcRefRelValueNext(ctx);
297 mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo");
299 mockAai.insertVnfcs(inParams, ctx, 2, 2,null);
303 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001");
304 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj");
305 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX");
306 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1");
307 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001");
308 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj");
309 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX");
310 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "2");
314 public void testUpdateVnfStatus() throws Exception {
316 MockAaiService mockAai = new MockAaiService(aaiClient);
318 Map<String, String> inParams = new HashMap<String, String>();
320 inParams.put("responsePrefix", "tmp.vnfInfo");
322 SvcLogicContext ctx = new SvcLogicContext();
324 mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo");
326 mockAai.updateVnfStatus(inParams, ctx);
330 public void testReadResource() throws Exception {
332 MockAaiService mockAai = new MockAaiService(aaiClient);
333 // AaiService mockAai = new AaiService(new AAIClientMock());
335 String vnfId = "ibcx0001v";
336 String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'";
337 String resourceType = "generic-vnf";
338 String queryPrefix = "vnfInfo";
339 SvcLogicContext ctx = mockAai.readResource(resourceKey, queryPrefix, resourceType);
341 // System.out.println("VNF TYPE " + queryPrefix + ".vnf.vnf-type");
343 assertEquals(ctx.getAttribute("vnfInfo.vnf-type"), "vUSP-Metaswitch");
346 private void printContext(SvcLogicContext ctx) throws Exception {
347 for (String key : ctx.getAttributeKeySet()) {
348 log.info(" KEY " + key);
349 log.info(" VALUE " + ctx.getAttribute(key));
354 public void testGetGroupNotationForExistingValue() throws Exception {
356 SvcLogicContext ctx = new SvcLogicContext();
357 ctx.setAttribute("req-vf-module-id", "vfmodule01");
358 ctx.setAttribute("tmp.vnfInfo.vm[0].vf-module-id", "vfmodule01");
359 ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-function-code", "fc1");
360 ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn1");
361 ctx.setAttribute("tmp.vnfInfo.vm[1].vf-module-id", "vfmodule01");
362 ctx.setAttribute("tmp.vnfInfo.vm[1].vnfc-function-code", "fc1");
363 ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-function-code", "fc1");
364 ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn2");
365 MockAaiService aai=new MockAaiService(aaiClient);
366 String groupNotationValue1 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 2);
367 assertEquals (groupNotationValue1,null);
369 ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn1");
370 ctx.setAttribute("tmp.vnfInfo.vm[1].group-notation", "gn1");
371 String groupNotationValue2 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 2);
372 assertEquals (groupNotationValue2,"gn1");
374 ctx.setAttribute("tmp.vnfInfo.vm[2].vf-module-id", "vfmodule01");
375 ctx.setAttribute("tmp.vnfInfo.vm[2].vnfc-function-code", "fc1");
376 ctx.setAttribute("tmp.vnfInfo.vm[2].group-notation", "gn2");
377 String groupNotationValue3 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 3);
378 assertEquals (groupNotationValue3,null);
380 ctx.setAttribute("tmp.vnfInfo.vm[2].group-notation", "gn1");
381 String groupNotationValue4 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 3);
382 assertEquals (groupNotationValue4,"gn1");