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.node;
27 import static org.junit.Assert.*;
30 import java.nio.charset.Charset;
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.Comparator;
34 import java.util.HashMap;
35 import java.util.List;
38 import org.apache.commons.io.FileUtils;
39 import org.apache.commons.io.IOUtils;
40 import org.junit.Assert;
41 import org.junit.Test;
42 import org.onap.appc.aai.client.AppcAaiClientConstant;
43 import org.onap.appc.aai.client.aai.AaiService;
44 import org.onap.appc.aai.client.aai.TestAaiService;
46 import com.att.eelf.configuration.EELFLogger;
47 import com.att.eelf.configuration.EELFManager;
48 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
50 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
51 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
53 import com.fasterxml.jackson.databind.ObjectMapper;
56 public class TestAAIResourceNode {
58 //Removed for ONAP integration
60 private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAAIResourceNode.class);
63 public void sortVServer() throws Exception{
67 ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>();
68 HashMap<String, String> vserverMap = new HashMap<String, String>();
69 vserverMap.put("vserver-id", "vserverId9");
70 vserverMap.put("tenant-id", "tenantId9");
71 vserverMap.put("cloud-owner", "cloudOwner9");
72 vserverMap.put("cloud-region-id", "cloudRegionId9");
73 vserverMap.put("vserver-name", "vServerName9");
74 vservers.add(vserverMap);
75 vserverMap = new HashMap<String, String>();
76 vserverMap.put("vserver-id", "vserverId1");
77 vserverMap.put("tenant-id", "tenantId1");
78 vserverMap.put("cloud-owner", "cloudOwner1");
79 vserverMap.put("cloud-region-id", "cloudRegionId1");
80 vserverMap.put("vserver-name", "vServerName1");
81 vservers.add(vserverMap);
82 vserverMap = new HashMap<String, String>();
83 vserverMap.put("vserver-id", "vserverId3");
84 vserverMap.put("tenant-id", "tenantId3");
85 vserverMap.put("cloud-owner", "cloudOwner3");
86 vserverMap.put("cloud-region-id", "cloudRegionId3");
87 vserverMap.put("vserver-name", "vServerName3");
88 vservers.add(vserverMap);
89 Collections.sort(vservers, new Comparator<Map<String, String>>() {
91 public int compare(Map<String, String> o1, Map<String, String> o2) {
92 return o1.get("vserver-name").compareTo(o2.get("vserver-name"));
96 SvcLogicContext ctx = new SvcLogicContext();
97 AAIResourceNode aai = new AAIResourceNode();
98 aai.populateContext(vservers, ctx, "vserver.");
99 log.info(ctx.getAttribute("vserver.vm[0].vserver-name"));
103 public void testAllVServer() throws Exception{
105 MockAAIResourceNode mrn = new MockAAIResourceNode();
106 SvcLogicContext ctx = new SvcLogicContext();
107 populateAllVServerInfo(ctx, "tmp.vnfInfo");
108 Map<String, String> inParams =new HashMap<String, String>();
109 inParams.put("responsePrefix", "tmp.vnfInfo");
110 mrn.getAllVServersVnfcsInfo(inParams, ctx);
111 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2");
112 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-count"), "2");
113 assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-with-no-vnfcs-count"), "0");
115 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcsm0002id");
116 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].tenant-id"), "tenantid2");
117 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-owner"), "cloudOwner2");
118 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-region-id"), "cloudRegionId2");
119 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-name"), "vserverName2");
120 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vf-module-id"), "vfModule2");
121 //assertNull(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"));
124 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcxvm0001id");
125 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].tenant-id"), "tenantid1");
126 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].cloud-owner"), "cloudOwner1");
127 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].cloud-region-id"), "cloudRegionId1");
128 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-name"), "vserverName2");
129 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vf-module-id"), "vfModule2");
130 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "vnfcName2");
131 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "vnfcType2");
132 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "vnfcFuncCode2");
133 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "vnfcGrpNot2");
135 public void populateAllVServerInfo(SvcLogicContext ctx, String prefix) throws Exception {
136 ctx.setAttribute("vnf-id", "ibcx0001v");
137 ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
138 ctx.setAttribute(prefix + ".vm-count", "2");
139 ctx.setAttribute(prefix+ ".vm[0].vserver-id", "ibcsm0002id");
140 ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid2");
141 ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner2");
142 ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId2");
143 ctx.setAttribute(prefix+ ".vm[1].vserver-id", "ibcxvm0001id");
144 ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantid1");
145 ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner1");
146 ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId1");
150 public static class MockAAIResourceNode extends AAIResourceNode {
151 private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAAIResourceNode.class);
152 private AAIClient aaiClient;
154 public AaiService getAaiService() {
155 log.info("In MockAAI");
156 return new MockAaiService(aaiClient);
161 public void testPopulateContext() throws Exception{
163 ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>();
164 HashMap<String, String> vserverMap = new HashMap<String, String>();
165 vserverMap = new HashMap<String, String>();
166 vserverMap.put("vserver-id", "vserverId1");
167 vserverMap.put("tenant-id", "tenantId1");
168 vserverMap.put("cloud-owner", "cloudOwner1");
169 vserverMap.put("cloud-region-id", "cloudRegionId1");
170 vserverMap.put("vserver-name", "vServerName1");
171 vserverMap.put("vnfc-name", "vnfcName1");
172 vservers.add(vserverMap);
173 vserverMap = new HashMap<String, String>();
174 vserverMap.put("vserver-id", "vserverId3");
175 vserverMap.put("tenant-id", "tenantId3");
176 vserverMap.put("cloud-owner", "cloudOwner3");
177 vserverMap.put("cloud-region-id", "cloudRegionId3");
178 vserverMap.put("vserver-name", "vServerName3");
179 vservers.add(vserverMap);
180 vserverMap = new HashMap<String, String>();
181 vserverMap.put("vserver-id", "vserverId9");
182 vserverMap.put("tenant-id", "tenantId9");
183 vserverMap.put("cloud-owner", "cloudOwner9");
184 vserverMap.put("cloud-region-id", "cloudRegionId9");
185 vserverMap.put("vserver-name", "vServerName9");
186 vservers.add(vserverMap);
187 SvcLogicContext ctx = new SvcLogicContext();
188 AAIResourceNode aai = new AAIResourceNode();
189 aai.populateContext(vservers, ctx, "tmp.vnfInfo.");
190 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-name"), "vServerName1");
191 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].tenant-id"), "tenantId1");
192 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-owner"), "cloudOwner1");
193 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-region-id"), "cloudRegionId1");
194 assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "vserverId1");
195 assertEquals(ctx.getAttribute("vm-name"), "vServerName3");
199 public final void testGetVnfInfo() {
200 SvcLogicContext ctx = new SvcLogicContext();
201 AAIResourceNode aai = new AAIResourceNode();
202 Map<String, String> inParams =new HashMap<String, String>();
203 inParams.put("responsePrefix", "tmp.vnfInfo");
205 aai.getVnfInfo(inParams, ctx);
206 } catch (SvcLogicException e) {
212 public final void testaddVnfcs()
214 SvcLogicContext ctx = new SvcLogicContext();
215 AAIResourceNode aai = new AAIResourceNode();
216 Map<String, String> inParams =new HashMap<String, String>();
217 inParams.put("responsePrefix", "tmp.vnfInfo");
219 aai.addVnfcs(inParams, ctx);
220 } catch (SvcLogicException e) {
226 public final void testupdateVnfAndVServerStatus(){
227 SvcLogicContext ctx = new SvcLogicContext();
228 AAIResourceNode aai = new AAIResourceNode();
229 Map<String, String> inParams =new HashMap<String, String>();
231 inParams.put("responsePrefix", "tmp.vnfInfo");
233 aai.updateVnfAndVServerStatus(inParams, ctx);
234 } catch (SvcLogicException e) {
240 public void testgetVfModduleModelInfo() throws Exception{
241 SvcLogicContext ctx = new SvcLogicContext();
242 AAIResourceNode aai = new AAIResourceNode();
244 MockAaiService aaiService=new MockAaiService(aaic);
245 Map<String, String> inParams =new HashMap<String, String>();
246 inParams.put("responsePrefix", "tmp.vnfInfo");
247 aai.processForVfModuleModelInfo(aaiService,inParams, ctx);
248 assertEquals(ctx.getAttribute("template-model-id"),"model0001");