2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.aai;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
28 import java.nio.file.Files;
29 import java.util.ArrayList;
30 import java.util.List;
31 import org.junit.Test;
32 import org.onap.aai.domain.yang.CloudRegion;
33 import org.onap.aai.domain.yang.GenericVnf;
34 import org.onap.aai.domain.yang.ModelVer;
35 import org.onap.aai.domain.yang.ServiceInstance;
36 import org.onap.aai.domain.yang.Tenant;
37 import org.onap.aai.domain.yang.VfModule;
38 import org.onap.aai.domain.yang.Vserver;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 public class AaiCqResponseTest {
43 private static final String ETE_VFMODULE = "Vfmodule_Ete_vFWCLvFWSNK_7ba1fbde_0";
44 private static final String ETE_VNF = "Ete_vFWCLvFWSNK_7ba1fbde_0";
45 private static final Logger LOGGER = LoggerFactory.getLogger(AaiCqResponseTest.class);
46 private static final String CQ_RESPONSE_SAMPLE =
47 "src/test/resources/org/onap/policy/aai/AaiCqResponseFull.json";
50 public void testConstructor() throws Exception {
52 * Read JSON String and add all AaiObjects
55 String responseString = "";
56 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
58 AaiCqResponse aaiCqResponse;
59 aaiCqResponse = new AaiCqResponse(responseString);
60 assertNotNull(aaiCqResponse);
61 assertNotNull(aaiCqResponse.getInventoryResponseItems());
65 public void testAaiMalformedCqResponse() throws Exception {
67 * Read JSON String and add all AaiObjects
70 String responseString = "";
71 responseString = new String(Files.readAllBytes(
72 new File("src/test/resources/org/onap/policy/aai/AaiMalformedCqResponse.json")
75 AaiCqResponse aaiCqResponse;
76 aaiCqResponse = new AaiCqResponse(responseString);
77 for (Object aaiObj : aaiCqResponse.getInventoryResponseItems()) {
84 public void testGetItemByList() throws Exception {
86 * Read JSON String and add all AaiObjects
89 String responseString = "";
90 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
92 AaiCqResponse aaiCqResponse;
93 aaiCqResponse = new AaiCqResponse(responseString);
94 ArrayList<Vserver> vs = (ArrayList<Vserver>) aaiCqResponse.getItemListByType(Vserver.class);
96 assertEquals("f953c499-4b1e-426b-8c6d-e9e9f1fc730f", vs.get(0).getVserverId());
97 LOGGER.info(vs.get(0).getVserverId());
102 public void testGetServiceInstance() throws Exception {
104 String responseString = "";
105 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
107 AaiCqResponse aaiCqResponse;
108 aaiCqResponse = new AaiCqResponse(responseString);
109 ServiceInstance si = aaiCqResponse.getServiceInstance();
111 assertEquals("Service_Ete_Name7ba1fbde-6187-464a-a62d-d9dd25bdf4e8",
112 si.getServiceInstanceName());
113 LOGGER.info(si.getServiceInstanceName());
117 public void testGetDefaultCloudRegion() throws Exception {
119 String responseString = "";
120 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
122 AaiCqResponse aaiCqResponse;
123 aaiCqResponse = new AaiCqResponse(responseString);
124 CloudRegion cloudRegion = aaiCqResponse.getDefaultCloudRegion();
125 assertNotNull(cloudRegion);
126 assertEquals("RegionOne", cloudRegion.getCloudRegionId());
127 LOGGER.info(cloudRegion.getCloudRegionId());
131 public void testGetDefaultTenant() throws Exception {
133 String responseString = "";
134 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
136 AaiCqResponse aaiCqResponse;
137 aaiCqResponse = new AaiCqResponse(responseString);
138 Tenant tenant = aaiCqResponse.getDefaultTenant();
139 assertNotNull(tenant);
140 assertEquals("41d6d38489bd40b09ea8a6b6b852dcbd", tenant.getTenantId());
141 LOGGER.info(tenant.getTenantId());
145 public void testGetGenericVnfs() throws Exception {
147 String responseString = "";
148 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
150 AaiCqResponse aaiCqResponse;
151 aaiCqResponse = new AaiCqResponse(responseString);
152 List<GenericVnf> genericVnfList = aaiCqResponse.getGenericVnfs();
153 assertNotNull(genericVnfList);
154 for (GenericVnf genVnf : genericVnfList) {
155 LOGGER.info(genVnf.getVnfName());
161 public void testGetDefaultGenericVnf() throws Exception {
163 String responseString = "";
164 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
166 AaiCqResponse aaiCqResponse;
167 aaiCqResponse = new AaiCqResponse(responseString);
168 GenericVnf genVnf = aaiCqResponse.getDefaultGenericVnf();
169 assertNotNull(genVnf);
170 assertEquals(ETE_VNF, genVnf.getVnfName());
171 LOGGER.info(genVnf.getVnfName());
176 public void testGetGenericVnfByName() throws Exception {
178 String responseString = "";
179 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
181 AaiCqResponse aaiCqResponse;
182 aaiCqResponse = new AaiCqResponse(responseString);
183 GenericVnf genVnf = aaiCqResponse.getGenericVnfByVnfName(ETE_VNF);
184 assertNotNull(genVnf);
185 assertEquals("f17face5-69cb-4c88-9e0b-7426db7edddd", genVnf.getVnfId());
186 LOGGER.info(genVnf.getVnfId());
190 public void testGetGenericVnfByModelInvariantId() throws Exception {
192 String responseString = "";
193 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
195 AaiCqResponse aaiCqResponse;
196 aaiCqResponse = new AaiCqResponse(responseString);
198 aaiCqResponse.getGenericVnfByModelInvariantId("9a243c47-fd5f-43d1-bd2a-f17bd12a61f2");
199 assertNotNull(genVnf);
200 assertEquals("9a243c47-fd5f-43d1-bd2a-f17bd12a61f2", genVnf.getModelInvariantId());
201 LOGGER.info(genVnf.getModelInvariantId());
205 public void testGetGenericVnfByVfModuleModelInvariantId() throws Exception {
207 String responseString = "";
208 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
210 AaiCqResponse aaiCqResponse;
211 aaiCqResponse = new AaiCqResponse(responseString);
212 GenericVnf genVnf = aaiCqResponse
213 .getGenericVnfByVfModuleModelInvariantId("e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e");
214 assertNotNull(genVnf);
215 assertEquals(ETE_VNF, genVnf.getVnfName());
216 LOGGER.info(genVnf.getVnfName());
220 public void testGetAllVfModules() throws Exception {
222 String responseString = "";
223 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
225 AaiCqResponse aaiCqResponse;
226 aaiCqResponse = new AaiCqResponse(responseString);
227 List<VfModule> vfModuleList = aaiCqResponse.getAllVfModules();
228 assertNotNull(vfModuleList);
229 for (VfModule vfMod : vfModuleList) {
230 LOGGER.info(vfMod.getVfModuleName());
236 public void testGetVfModuleByVfModuleName() throws Exception {
238 String responseString = "";
239 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
241 AaiCqResponse aaiCqResponse;
242 aaiCqResponse = new AaiCqResponse(responseString);
243 VfModule vfModule = aaiCqResponse.getVfModuleByVfModuleName(ETE_VFMODULE);
244 assertNotNull(vfModule);
245 assertEquals(ETE_VFMODULE, vfModule.getVfModuleName());
246 LOGGER.info(vfModule.getVfModuleName());
251 public void testGetVfModuleByVfModelInvariantId() throws Exception {
253 String responseString = "";
254 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
256 AaiCqResponse aaiCqResponse;
257 aaiCqResponse = new AaiCqResponse(responseString);
259 aaiCqResponse.getVfModuleByVfModelInvariantId("e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e");
260 assertNotNull(vfModule);
261 assertEquals(ETE_VFMODULE, vfModule.getVfModuleName());
262 LOGGER.info(vfModule.getVfModuleName());
267 public void testGetDefaultVfModule() throws Exception {
269 String responseString = "";
270 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
272 AaiCqResponse aaiCqResponse;
273 aaiCqResponse = new AaiCqResponse(responseString);
274 VfModule vfModule = aaiCqResponse.getDefaultVfModule();
275 assertNotNull(vfModule);
276 assertEquals(ETE_VFMODULE, vfModule.getVfModuleName());
277 LOGGER.info(vfModule.getVfModuleName());
281 public void testGetVserver() throws Exception {
283 String responseString = "";
284 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
286 AaiCqResponse aaiCqResponse;
287 aaiCqResponse = new AaiCqResponse(responseString);
288 Vserver vserver = aaiCqResponse.getVserver();
289 assertNotNull(vserver);
290 assertEquals(ETE_VNF, vserver.getVserverName());
291 LOGGER.info(vserver.getVserverName());
296 public void testGetAllModelVer() throws Exception {
298 String responseString = "";
299 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
301 AaiCqResponse aaiCqResponse;
302 aaiCqResponse = new AaiCqResponse(responseString);
303 List<ModelVer> modelVerList = aaiCqResponse.getAllModelVer();
304 assertNotNull(modelVerList);
305 for (ModelVer modV : modelVerList) {
306 LOGGER.info(modV.getModelName());
312 public void testGetModelVerByVersionId() throws Exception {
314 String responseString = "";
315 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
317 AaiCqResponse aaiCqResponse;
318 aaiCqResponse = new AaiCqResponse(responseString);
320 aaiCqResponse.getModelVerByVersionId("189a5070-3bd5-45ac-8a1d-c84ca40b277b");
321 assertNotNull(modelVer);
322 assertEquals("vFWCL_vFWSNK bbefb8ce-2bde", modelVer.getModelName());
323 LOGGER.info(modelVer.getModelName());
328 public void testGetVfModuleCount() throws Exception {
329 String responseString =
330 new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
331 AaiCqResponse aaiCqResponse;
332 aaiCqResponse = new AaiCqResponse(responseString);
333 int count = aaiCqResponse.getVfModuleCount("47958575-138f-452a-8c8d-d89b595f8164",
334 "e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e", "94b18b1d-cc91-4f43-911a-e6348665f292");
335 assertEquals(1, count);
339 * Provides sample CQ response.
341 * @return a CQ response
342 * @throws Exception file read exception
344 public String getAaiCqResponse() throws Exception {
345 String responseString = "";
346 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
347 return responseString;