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.ServiceInstance;
35 import org.onap.aai.domain.yang.Tenant;
36 import org.onap.aai.domain.yang.VfModule;
37 import org.onap.aai.domain.yang.Vserver;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 public class AaiCqResponseTest {
42 private static final Logger LOGGER = LoggerFactory.getLogger(AaiCqResponseTest.class);
43 private static final String CQ_RESPONSE_SAMPLE = "src/test/resources/org/onap/policy/aai/AaiCqResponse.json";
47 public void testConstructor() throws Exception {
49 * Read JSON String and add all AaiObjects
52 String responseString = "";
53 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
55 AaiCqResponse aaiCqResponse;
56 aaiCqResponse = new AaiCqResponse(responseString);
57 assertNotNull(aaiCqResponse);
58 assertNotNull(aaiCqResponse.getInventoryResponseItems());
62 public void testAaiMalformedCqResponse() throws Exception {
64 * Read JSON String and add all AaiObjects
67 String responseString = "";
68 responseString = new String(Files
69 .readAllBytes(new File("src/test/resources/org/onap/policy/aai/AaiMalformedCqResponse.json").toPath()));
71 AaiCqResponse aaiCqResponse;
72 aaiCqResponse = new AaiCqResponse(responseString);
73 for (Object aaiObj : aaiCqResponse.getInventoryResponseItems()) {
81 public void testGetItemByList() throws Exception {
83 * Read JSON String and add all AaiObjects
86 String responseString = "";
87 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
89 AaiCqResponse aaiCqResponse;
90 aaiCqResponse = new AaiCqResponse(responseString);
91 ArrayList<Vserver> vs = (ArrayList<Vserver>) aaiCqResponse.getItemListByType(Vserver.class);
93 assertEquals("e7f1db09-ff78-44fc-b256-69095c5556fb", vs.get(0).getVserverId());
94 LOGGER.info(vs.get(0).getVserverId());
99 public void testGetServiceInstance() throws Exception {
101 String responseString = "";
102 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
104 AaiCqResponse aaiCqResponse;
105 aaiCqResponse = new AaiCqResponse(responseString);
106 ServiceInstance si = aaiCqResponse.getServiceInstance();
108 assertEquals("vLoadBalancerMS-0211-1", si.getServiceInstanceName());
109 LOGGER.info(si.getServiceInstanceName());
113 public void testGetDefaultCloudRegion() throws Exception {
115 String responseString = "";
116 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
118 AaiCqResponse aaiCqResponse;
119 aaiCqResponse = new AaiCqResponse(responseString);
120 CloudRegion cloudRegion = aaiCqResponse.getDefaultCloudRegion();
121 assertNotNull(cloudRegion);
122 assertEquals("cr-16197-01-as988q", cloudRegion.getCloudRegionId());
123 LOGGER.info(cloudRegion.getCloudRegionId());
127 public void testGetDefaultTenant() throws Exception {
129 String responseString = "";
130 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
132 AaiCqResponse aaiCqResponse;
133 aaiCqResponse = new AaiCqResponse(responseString);
134 Tenant tenant = aaiCqResponse.getDefaultTenant();
135 assertNotNull(tenant);
136 assertEquals("tenant1-16197-as988q", tenant.getTenantId());
137 LOGGER.info(tenant.getTenantId());
143 public void testGetGenericVnfs() throws Exception {
145 String responseString = "";
146 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
148 AaiCqResponse aaiCqResponse;
149 aaiCqResponse = new AaiCqResponse(responseString);
150 List<GenericVnf> genericVnfList = aaiCqResponse.getGenericVnfs();
151 assertNotNull(genericVnfList);
152 for (GenericVnf genVnf : genericVnfList) {
153 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("TestVM-Vnf-0201-1", 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("TestVM-Vnf-0201-1");
184 assertNotNull(genVnf);
185 assertEquals("17044ef4-e7f3-46a1-af03-e2aa562f23ac", genVnf.getVnfId());
186 LOGGER.info(genVnf.getVnfId());
191 public void testGetGenericVnfByModelInvariantId() throws Exception {
193 String responseString = "";
194 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
196 AaiCqResponse aaiCqResponse;
197 aaiCqResponse = new AaiCqResponse(responseString);
198 GenericVnf genVnf = aaiCqResponse.getGenericVnfByModelInvariantId("724ab1cf-6120-49e8-b909-849963bed1d6");
199 assertNotNull(genVnf);
200 assertEquals("724ab1cf-6120-49e8-b909-849963bed1d6", genVnf.getModelInvariantId());
201 LOGGER.info(genVnf.getModelInvariantId());
205 public void testGetAllVfModules() 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 List<VfModule> vfModuleList = aaiCqResponse.getAllVfModules();
213 assertNotNull(vfModuleList);
214 for (VfModule vfMod : vfModuleList) {
215 LOGGER.info(vfMod.getVfModuleName());
222 public void testGetVfModuleByVfModuleName() throws Exception {
224 String responseString = "";
225 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
227 AaiCqResponse aaiCqResponse;
228 aaiCqResponse = new AaiCqResponse(responseString);
229 VfModule vfModule = aaiCqResponse.getVfModuleByVfModuleName("vLoadBalancerMS-0211-1");
230 assertNotNull(vfModule);
231 assertEquals("vLoadBalancerMS-0211-1", vfModule.getVfModuleName());
232 LOGGER.info(vfModule.getVfModuleName());
238 public void testGetDefaultVfModule() throws Exception {
240 String responseString = "";
241 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
243 AaiCqResponse aaiCqResponse;
244 aaiCqResponse = new AaiCqResponse(responseString);
245 VfModule vfModule = aaiCqResponse.getDefaultVfModule();
246 assertNotNull(vfModule);
247 assertEquals("TestVM-0201-2", vfModule.getVfModuleName());
248 LOGGER.info(vfModule.getVfModuleName());
252 public void testGetVserver() throws Exception {
254 String responseString = "";
255 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
257 AaiCqResponse aaiCqResponse;
258 aaiCqResponse = new AaiCqResponse(responseString);
259 Vserver vserver = aaiCqResponse.getVserver();
260 assertNotNull(vserver);
261 assertEquals("vfw-vm-0201-2", vserver.getVserverName());
262 LOGGER.info(vserver.getVserverName());
267 * Aai Cq sample response.
269 * @return String return response
270 * @throws Exception file read exception
272 public String getAaiCqResponse() throws Exception {
273 String responseString = "";
274 responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
275 return responseString;