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 Logger LOGGER = LoggerFactory.getLogger(AaiCqResponseTest.class);
44 private static final String CQ_RESPONSE_SAMPLE = "src/test/resources/org/onap/policy/aai/AaiCqResponseFull.json";
48 public void testConstructor() throws Exception {
50 * Read JSON String and add all AaiObjects
53 String responseString = "";
54 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
56 AaiCqResponse aaiCqResponse;
57 aaiCqResponse = new AaiCqResponse(responseString);
58 assertNotNull(aaiCqResponse);
59 assertNotNull(aaiCqResponse.getInventoryResponseItems());
63 public void testAaiMalformedCqResponse() throws Exception {
65 * Read JSON String and add all AaiObjects
68 String responseString = "";
69 responseString = new String(Files
70 .readAllBytes(new File("src/test/resources/org/onap/policy/aai/AaiMalformedCqResponse.json").toPath()));
72 AaiCqResponse aaiCqResponse;
73 aaiCqResponse = new AaiCqResponse(responseString);
74 for (Object aaiObj : aaiCqResponse.getInventoryResponseItems()) {
82 public void testGetItemByList() throws Exception {
84 * Read JSON String and add all AaiObjects
87 String responseString = "";
88 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
90 AaiCqResponse aaiCqResponse;
91 aaiCqResponse = new AaiCqResponse(responseString);
92 ArrayList<Vserver> vs = (ArrayList<Vserver>) aaiCqResponse.getItemListByType(Vserver.class);
94 assertEquals("f953c499-4b1e-426b-8c6d-e9e9f1fc730f", vs.get(0).getVserverId());
95 LOGGER.info(vs.get(0).getVserverId());
100 public void testGetServiceInstance() throws Exception {
102 String responseString = "";
103 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
105 AaiCqResponse aaiCqResponse;
106 aaiCqResponse = new AaiCqResponse(responseString);
107 ServiceInstance si = aaiCqResponse.getServiceInstance();
109 assertEquals("Service_Ete_Name7ba1fbde-6187-464a-a62d-d9dd25bdf4e8", si.getServiceInstanceName());
110 LOGGER.info(si.getServiceInstanceName());
114 public void testGetDefaultCloudRegion() throws Exception {
116 String responseString = "";
117 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
119 AaiCqResponse aaiCqResponse;
120 aaiCqResponse = new AaiCqResponse(responseString);
121 CloudRegion cloudRegion = aaiCqResponse.getDefaultCloudRegion();
122 assertNotNull(cloudRegion);
123 assertEquals("RegionOne", cloudRegion.getCloudRegionId());
124 LOGGER.info(cloudRegion.getCloudRegionId());
128 public void testGetDefaultTenant() throws Exception {
130 String responseString = "";
131 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
133 AaiCqResponse aaiCqResponse;
134 aaiCqResponse = new AaiCqResponse(responseString);
135 Tenant tenant = aaiCqResponse.getDefaultTenant();
136 assertNotNull(tenant);
137 assertEquals("41d6d38489bd40b09ea8a6b6b852dcbd", tenant.getTenantId());
138 LOGGER.info(tenant.getTenantId());
144 public void testGetGenericVnfs() throws Exception {
146 String responseString = "";
147 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
149 AaiCqResponse aaiCqResponse;
150 aaiCqResponse = new AaiCqResponse(responseString);
151 List<GenericVnf> genericVnfList = aaiCqResponse.getGenericVnfs();
152 assertNotNull(genericVnfList);
153 for (GenericVnf genVnf : genericVnfList) {
154 LOGGER.info(genVnf.getVnfName());
162 public void testGetDefaultGenericVnf() throws Exception {
164 String responseString = "";
165 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
167 AaiCqResponse aaiCqResponse;
168 aaiCqResponse = new AaiCqResponse(responseString);
169 GenericVnf genVnf = aaiCqResponse.getDefaultGenericVnf();
170 assertNotNull(genVnf);
171 assertEquals("Ete_vFWCLvFWSNK_7ba1fbde_0", genVnf.getVnfName());
172 LOGGER.info(genVnf.getVnfName());
177 public void testGetGenericVnfByName() throws Exception {
179 String responseString = "";
180 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
182 AaiCqResponse aaiCqResponse;
183 aaiCqResponse = new AaiCqResponse(responseString);
184 GenericVnf genVnf = aaiCqResponse.getGenericVnfByVnfName("Ete_vFWCLvFWSNK_7ba1fbde_0");
185 assertNotNull(genVnf);
186 assertEquals("f17face5-69cb-4c88-9e0b-7426db7edddd", genVnf.getVnfId());
187 LOGGER.info(genVnf.getVnfId());
192 public void testGetGenericVnfByModelInvariantId() throws Exception {
194 String responseString = "";
195 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
197 AaiCqResponse aaiCqResponse;
198 aaiCqResponse = new AaiCqResponse(responseString);
199 GenericVnf genVnf = aaiCqResponse.getGenericVnfByModelInvariantId("9a243c47-fd5f-43d1-bd2a-f17bd12a61f2");
200 assertNotNull(genVnf);
201 assertEquals("9a243c47-fd5f-43d1-bd2a-f17bd12a61f2", genVnf.getModelInvariantId());
202 LOGGER.info(genVnf.getModelInvariantId());
207 public void testGetGenericVnfByVfModuleModelInvariantId() throws Exception {
209 String responseString = "";
210 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
212 AaiCqResponse aaiCqResponse;
213 aaiCqResponse = new AaiCqResponse(responseString);
215 aaiCqResponse.getGenericVnfByVfModuleModelInvariantId("e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e");
216 assertNotNull(genVnf);
217 assertEquals("Ete_vFWCLvFWSNK_7ba1fbde_0", genVnf.getVnfName());
218 LOGGER.info(genVnf.getVnfName());
224 public void testGetAllVfModules() throws Exception {
226 String responseString = "";
227 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
229 AaiCqResponse aaiCqResponse;
230 aaiCqResponse = new AaiCqResponse(responseString);
231 List<VfModule> vfModuleList = aaiCqResponse.getAllVfModules();
232 assertNotNull(vfModuleList);
233 for (VfModule vfMod : vfModuleList) {
234 LOGGER.info(vfMod.getVfModuleName());
241 public void testGetVfModuleByVfModuleName() throws Exception {
243 String responseString = "";
244 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
246 AaiCqResponse aaiCqResponse;
247 aaiCqResponse = new AaiCqResponse(responseString);
248 VfModule vfModule = aaiCqResponse.getVfModuleByVfModuleName("Vfmodule_Ete_vFWCLvFWSNK_7ba1fbde_0");
249 assertNotNull(vfModule);
250 assertEquals("Vfmodule_Ete_vFWCLvFWSNK_7ba1fbde_0", vfModule.getVfModuleName());
251 LOGGER.info(vfModule.getVfModuleName());
257 public void testGetVfModuleByVfModelInvariantId() throws Exception {
259 String responseString = "";
260 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
262 AaiCqResponse aaiCqResponse;
263 aaiCqResponse = new AaiCqResponse(responseString);
264 VfModule vfModule = aaiCqResponse.getVfModuleByVfModelInvariantId("e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e");
265 assertNotNull(vfModule);
266 assertEquals("Vfmodule_Ete_vFWCLvFWSNK_7ba1fbde_0", vfModule.getVfModuleName());
267 LOGGER.info(vfModule.getVfModuleName());
273 public void testGetDefaultVfModule() throws Exception {
275 String responseString = "";
276 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
278 AaiCqResponse aaiCqResponse;
279 aaiCqResponse = new AaiCqResponse(responseString);
280 VfModule vfModule = aaiCqResponse.getDefaultVfModule();
281 assertNotNull(vfModule);
282 assertEquals("Vfmodule_Ete_vFWCLvFWSNK_7ba1fbde_0", vfModule.getVfModuleName());
283 LOGGER.info(vfModule.getVfModuleName());
287 public void testGetVserver() throws Exception {
289 String responseString = "";
290 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
292 AaiCqResponse aaiCqResponse;
293 aaiCqResponse = new AaiCqResponse(responseString);
294 Vserver vserver = aaiCqResponse.getVserver();
295 assertNotNull(vserver);
296 assertEquals("Ete_vFWCLvFWSNK_7ba1fbde_0", vserver.getVserverName());
297 LOGGER.info(vserver.getVserverName());
302 public void testGetAllModelVer() throws Exception {
304 String responseString = "";
305 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
307 AaiCqResponse aaiCqResponse;
308 aaiCqResponse = new AaiCqResponse(responseString);
309 List<ModelVer> modelVerList = aaiCqResponse.getAllModelVer();
310 assertNotNull(modelVerList);
311 for (ModelVer modV : modelVerList) {
312 LOGGER.info(modV.getModelName());
318 public void testGetModelVerByVersionId() throws Exception {
320 String responseString = "";
321 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
323 AaiCqResponse aaiCqResponse;
324 aaiCqResponse = new AaiCqResponse(responseString);
325 ModelVer modelVer = aaiCqResponse.getModelVerByVersionId("189a5070-3bd5-45ac-8a1d-c84ca40b277b");
326 assertNotNull(modelVer);
327 assertEquals("vFWCL_vFWSNK bbefb8ce-2bde", modelVer.getModelName());
328 LOGGER.info(modelVer.getModelName());
334 * Aai Cq sample response.
336 * @return String return response
337 * @throws Exception file read exception
339 public String getAaiCqResponse() throws Exception {
340 String responseString = "";
341 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
342 return responseString;