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.node;
26 import static org.junit.Assert.*;
29 import java.nio.charset.Charset;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.Comparator;
33 import java.util.HashMap;
34 import java.util.List;
37 import org.apache.commons.io.FileUtils;
38 import org.apache.commons.io.IOUtils;
39 import org.junit.Assert;
40 import org.junit.Test;
41 import org.onap.appc.aai.client.AppcAaiClientConstant;
42 import org.onap.appc.aai.client.aai.AaiService;
43 import org.onap.appc.aai.client.aai.TestAaiService;
45 import com.att.eelf.configuration.EELFLogger;
46 import com.att.eelf.configuration.EELFManager;
47 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
49 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
50 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
52 import com.fasterxml.jackson.databind.ObjectMapper;
55 public class TestAAIResourceNode {
57 //Removed for ONAP integration
59 private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAAIResourceNode.class);
62 public void sortVServer() throws Exception{
66 ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>();
67 HashMap<String, String> vserverMap = new HashMap<String, String>();
68 vserverMap.put("vserver-id", "vserverId9");
69 vserverMap.put("tenant-id", "tenantId9");
70 vserverMap.put("cloud-owner", "cloudOwner9");
71 vserverMap.put("cloud-region-id", "cloudRegionId9");
72 vserverMap.put("vserver-name", "vServerName9");
73 vservers.add(vserverMap);
74 vserverMap = new HashMap<String, String>();
75 vserverMap.put("vserver-id", "vserverId1");
76 vserverMap.put("tenant-id", "tenantId1");
77 vserverMap.put("cloud-owner", "cloudOwner1");
78 vserverMap.put("cloud-region-id", "cloudRegionId1");
79 vserverMap.put("vserver-name", "vServerName1");
80 vservers.add(vserverMap);
81 vserverMap = new HashMap<String, String>();
82 vserverMap.put("vserver-id", "vserverId3");
83 vserverMap.put("tenant-id", "tenantId3");
84 vserverMap.put("cloud-owner", "cloudOwner3");
85 vserverMap.put("cloud-region-id", "cloudRegionId3");
86 vserverMap.put("vserver-name", "vServerName3");
87 vservers.add(vserverMap);
88 Collections.sort(vservers, new Comparator<Map<String, String>>() {
90 public int compare(Map<String, String> o1, Map<String, String> o2) {
91 return o1.get("vserver-name").compareTo(o2.get("vserver-name"));
95 SvcLogicContext ctx = new SvcLogicContext();
96 AAIResourceNode aai = new AAIResourceNode();
97 aai.populateContext(vservers, ctx, "vserver.");
98 log.info(ctx.getAttribute("vserver.vm[0].vserver-name"));
102 public void testAllVServer() throws Exception{
104 MockAAIResourceNode mrn = new MockAAIResourceNode();
105 SvcLogicContext ctx = new SvcLogicContext();
106 populateAllVServerInfo(ctx, "tmp.vnfInfo");
107 Map<String, String> inParams =new HashMap<String, String>();
108 inParams.put("responsePrefix", "tmp.vnfInfo");
109 mrn.getAllVServersVnfcsInfo(inParams, ctx);
110 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2");
111 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-count"), "2");
112 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-with-no-vnfcs-count"), "0");
114 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcsm0002id");
115 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].tenant-id"), "tenantid2");
116 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-owner"), "cloudOwner2");
117 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-region-id"), "cloudRegionId2");
118 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-name"), "vserverName2");
119 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vf-module-id"), "vfModule2");
120 //assertNull(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"));
123 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcxvm0001id");
124 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].tenant-id"), "tenantid1");
125 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].cloud-owner"), "cloudOwner1");
126 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].cloud-region-id"), "cloudRegionId1");
127 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-name"), "vserverName2");
128 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vf-module-id"), "vfModule2");
129 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "vnfcName2");
130 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "vnfcType2");
131 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "vnfcFuncCode2");
132 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "vnfcGrpNot2");
134 ctx.setAttribute("tmp.vnfInfo.vm[0].vserver-id","ibcm0001id");
135 ctx.setAttribute("req-vf-module-id","vfModule1");
136 mrn.getAllVServersVnfcsInfo(inParams, ctx);
137 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-with-no-vnfcs-count-vf-module"),"1");
138 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-count-for-vf-module"),"1");
141 public void populateAllVServerInfo(SvcLogicContext ctx, String prefix) throws Exception {
142 ctx.setAttribute("vnf-id", "ibcx0001v");
143 ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
144 ctx.setAttribute(prefix + ".vm-count", "2");
145 ctx.setAttribute(prefix+ ".vm[0].vserver-id", "ibcsm0002id");
146 ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid2");
147 ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner2");
148 ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId2");
149 ctx.setAttribute(prefix+ ".vm[1].vserver-id", "ibcxvm0001id");
150 ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantid1");
151 ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner1");
152 ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId1");
156 public static class MockAAIResourceNode extends AAIResourceNode {
157 private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAAIResourceNode.class);
158 private AAIClient aaiClient;
160 public AaiService getAaiService() {
161 log.info("In MockAAI");
162 return new MockAaiService(aaiClient);
167 public void testPopulateContext() throws Exception{
169 ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>();
170 HashMap<String, String> vserverMap = new HashMap<String, String>();
171 vserverMap = new HashMap<String, String>();
172 vserverMap.put("vserver-id", "vserverId1");
173 vserverMap.put("tenant-id", "tenantId1");
174 vserverMap.put("cloud-owner", "cloudOwner1");
175 vserverMap.put("cloud-region-id", "cloudRegionId1");
176 vserverMap.put("vserver-name", "vServerName1");
177 vserverMap.put("vnfc-name", "vnfcName1");
178 vservers.add(vserverMap);
179 vserverMap = new HashMap<String, String>();
180 vserverMap.put("vserver-id", "vserverId3");
181 vserverMap.put("tenant-id", "tenantId3");
182 vserverMap.put("cloud-owner", "cloudOwner3");
183 vserverMap.put("cloud-region-id", "cloudRegionId3");
184 vserverMap.put("vserver-name", "vServerName3");
185 vservers.add(vserverMap);
186 vserverMap = new HashMap<String, String>();
187 vserverMap.put("vserver-id", "vserverId9");
188 vserverMap.put("tenant-id", "tenantId9");
189 vserverMap.put("cloud-owner", "cloudOwner9");
190 vserverMap.put("cloud-region-id", "cloudRegionId9");
191 vserverMap.put("vserver-name", "vServerName9");
192 vservers.add(vserverMap);
193 SvcLogicContext ctx = new SvcLogicContext();
194 AAIResourceNode aai = new AAIResourceNode();
195 aai.populateContext(vservers, ctx, "tmp.vnfInfo.");
196 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-name"), "vServerName1");
197 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].tenant-id"), "tenantId1");
198 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-owner"), "cloudOwner1");
199 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-region-id"), "cloudRegionId1");
200 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "vserverId1");
201 assertEquals(ctx.getAttribute("vm-name"), "vServerName3");
205 public final void testGetVnfInfo() {
206 SvcLogicContext ctx = new SvcLogicContext();
207 AAIResourceNode aai = new AAIResourceNode();
208 Map<String, String> inParams =new HashMap<String, String>();
209 inParams.put("responsePrefix", "tmp.vnfInfo");
211 aai.getVnfInfo(inParams, ctx);
212 } catch (SvcLogicException e) {
218 public final void testaddVnfcs()
220 SvcLogicContext ctx = new SvcLogicContext();
221 AAIResourceNode aai = new AAIResourceNode();
222 Map<String, String> inParams =new HashMap<String, String>();
223 inParams.put("responsePrefix", "tmp.vnfInfo");
225 aai.addVnfcs(inParams, ctx);
226 } catch (SvcLogicException e) {
232 public final void testupdateVnfAndVServerStatus(){
233 SvcLogicContext ctx = new SvcLogicContext();
234 AAIResourceNode aai = new AAIResourceNode();
235 Map<String, String> inParams =new HashMap<String, String>();
237 inParams.put("responsePrefix", "tmp.vnfInfo");
239 aai.updateVnfAndVServerStatus(inParams, ctx);
240 } catch (SvcLogicException e) {
246 public void testgetVfModduleModelInfo() throws Exception{
247 SvcLogicContext ctx = new SvcLogicContext();
248 AAIResourceNode aai = new AAIResourceNode();
250 MockAaiService aaiService=new MockAaiService(aaic);
251 Map<String, String> inParams =new HashMap<String, String>();
252 inParams.put("responsePrefix", "tmp.vnfInfo");
253 aai.processForVfModuleModelInfo(aaiService,inParams, ctx);
254 assertEquals(ctx.getAttribute("template-model-id"),"model0001");
258 public final void testSetVmParams() {
259 SvcLogicContext ctx = new SvcLogicContext();
260 String vServerId = "vserver02";
261 ctx.setAttribute("tmp.vnfInfo.vm-count","3");
262 ctx.setAttribute("tmp.vnfInfo.vm[0].vserver-id","vserver01");
263 ctx.setAttribute("tmp.vnfInfo.vm[1].vserver-id","vserver02");
264 ctx.setAttribute("tmp.vnfInfo.vm[1].tenant-id","ten01");
265 ctx.setAttribute("tmp.vnfInfo.vm[1].cloud-region-id","cr01");
266 ctx.setAttribute("tmp.vnfInfo.vm[1].cloud-owner","co01");
267 AAIResourceNode aairn= new AAIResourceNode();
268 Map <String, String> params = aairn.setVmParams(ctx, vServerId);
269 assertNotNull(params);
272 public final void testGetVnfcInformationForVserver() throws Exception{
273 MockAAIResourceNode aairn = new MockAAIResourceNode();
274 SvcLogicContext ctx = new SvcLogicContext();
275 SvcLogicContext newVnfcCtx = new SvcLogicContext();
276 Map<String,String> inParams = new HashMap<String, String>();
277 Map<String,String> vnfcParams = new HashMap<String, String>();
278 String responsePrefix="test.";
279 inParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX, "test");
280 vnfcParams.put("vnfcName", "vnfcName2");
281 aairn.getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aairn.getAaiService(), responsePrefix);
282 assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-name"),"vnfcName2");
283 assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-type"), "vnfcType2");
284 assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-function-code"), "vnfcFuncCode2");
285 assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-group-notation"), "vnfcGrpNot2");
289 public final void testGetFormattedValue() throws Exception{
290 MockAAIResourceNode aairn = new MockAAIResourceNode();
291 SvcLogicContext ctx = new SvcLogicContext();
292 Map<String,String> inParams = new HashMap<String, String>();
293 inParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX, "test");
294 inParams.put("inputParameter", "Some/Value/With/ Many Spaces");
295 aairn.getFormattedValue(inParams, ctx);
296 assertEquals(ctx.getAttribute("template-model-id"),"Some_Value_With_ManySpaces");
301 public final void testProcessCheckForVfModule() throws Exception{
302 MockAAIResourceNode aairn = new MockAAIResourceNode();
303 SvcLogicContext ctx = new SvcLogicContext();
304 Map<String,String> inParams = new HashMap<String, String>();
305 inParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX, "test");
306 inParams.put("inputParameter", "Some/Value/With/ Many Spaces");
307 ctx.setAttribute("test.vnf.vm-with-no-vnfcs-count-vf-module", "0");
308 ctx.setAttribute("test.vnf.vm-count-for-vf-module", "2");
309 aairn.processCheckForVfModule("vfmoduleId1", ctx, "test.", 2);