Supports new aai changes.
[policy/models.git] / models-interactions / model-impl / aai / src / test / java / org / onap / policy / aai / AaiCqResponseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.aai;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26
27 import java.io.File;
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;
41
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";
45
46
47     @Test
48     public void testConstructor() throws Exception {
49         /*
50          * Read JSON String and add all AaiObjects
51          */
52
53         String responseString = "";
54         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
55
56         AaiCqResponse aaiCqResponse;
57         aaiCqResponse = new AaiCqResponse(responseString);
58         assertNotNull(aaiCqResponse);
59         assertNotNull(aaiCqResponse.getInventoryResponseItems());
60     }
61
62     @Test
63     public void testAaiMalformedCqResponse() throws Exception {
64         /*
65          * Read JSON String and add all AaiObjects
66          */
67
68         String responseString = "";
69         responseString = new String(Files
70                 .readAllBytes(new File("src/test/resources/org/onap/policy/aai/AaiMalformedCqResponse.json").toPath()));
71
72         AaiCqResponse aaiCqResponse;
73         aaiCqResponse = new AaiCqResponse(responseString);
74         for (Object aaiObj : aaiCqResponse.getInventoryResponseItems()) {
75             assertNull(aaiObj);
76         }
77
78
79     }
80
81     @Test
82     public void testGetItemByList() throws Exception {
83         /*
84          * Read JSON String and add all AaiObjects
85          */
86
87         String responseString = "";
88         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
89
90         AaiCqResponse aaiCqResponse;
91         aaiCqResponse = new AaiCqResponse(responseString);
92         ArrayList<Vserver> vs = (ArrayList<Vserver>) aaiCqResponse.getItemListByType(Vserver.class);
93         assertNotNull(vs);
94         assertEquals("f953c499-4b1e-426b-8c6d-e9e9f1fc730f", vs.get(0).getVserverId());
95         LOGGER.info(vs.get(0).getVserverId());
96
97     }
98
99     @Test
100     public void testGetServiceInstance() throws Exception {
101
102         String responseString = "";
103         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
104
105         AaiCqResponse aaiCqResponse;
106         aaiCqResponse = new AaiCqResponse(responseString);
107         ServiceInstance si = aaiCqResponse.getServiceInstance();
108         assertNotNull(si);
109         assertEquals("Service_Ete_Name7ba1fbde-6187-464a-a62d-d9dd25bdf4e8", si.getServiceInstanceName());
110         LOGGER.info(si.getServiceInstanceName());
111     }
112
113     @Test
114     public void testGetDefaultCloudRegion() throws Exception {
115
116         String responseString = "";
117         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
118
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());
125     }
126
127     @Test
128     public void testGetDefaultTenant() throws Exception {
129
130         String responseString = "";
131         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
132
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());
139     }
140
141
142
143     @Test
144     public void testGetGenericVnfs() throws Exception {
145
146         String responseString = "";
147         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
148
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());
155         }
156
157     }
158
159
160
161     @Test
162     public void testGetDefaultGenericVnf() throws Exception {
163
164         String responseString = "";
165         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
166
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());
173
174     }
175
176     @Test
177     public void testGetGenericVnfByName() throws Exception {
178
179         String responseString = "";
180         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
181
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());
188     }
189
190
191     @Test
192     public void testGetGenericVnfByModelInvariantId() throws Exception {
193
194         String responseString = "";
195         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
196
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());
203     }
204
205
206     @Test
207     public void testGetGenericVnfByVfModuleModelInvariantId() throws Exception {
208
209         String responseString = "";
210         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
211
212         AaiCqResponse aaiCqResponse;
213         aaiCqResponse = new AaiCqResponse(responseString);
214         GenericVnf genVnf =
215                 aaiCqResponse.getGenericVnfByVfModuleModelInvariantId("e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e");
216         assertNotNull(genVnf);
217         assertEquals("Ete_vFWCLvFWSNK_7ba1fbde_0", genVnf.getVnfName());
218         LOGGER.info(genVnf.getVnfName());
219     }
220
221
222
223     @Test
224     public void testGetAllVfModules() throws Exception {
225
226         String responseString = "";
227         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
228
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());
235         }
236
237     }
238
239
240     @Test
241     public void testGetVfModuleByVfModuleName() throws Exception {
242
243         String responseString = "";
244         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
245
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());
252
253
254     }
255
256     @Test
257     public void testGetVfModuleByVfModelInvariantId() throws Exception {
258
259         String responseString = "";
260         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
261
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());
268
269
270     }
271
272     @Test
273     public void testGetDefaultVfModule() throws Exception {
274
275         String responseString = "";
276         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
277
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());
284     }
285
286     @Test
287     public void testGetVserver() throws Exception {
288
289         String responseString = "";
290         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
291
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());
298
299     }
300
301     @Test
302     public void testGetAllModelVer() throws Exception {
303
304         String responseString = "";
305         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
306
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());
313         }
314
315     }
316
317     @Test
318     public void testGetModelVerByVersionId() throws Exception {
319
320         String responseString = "";
321         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
322
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());
329
330     }
331
332
333     /**
334      * Aai Cq sample response.
335      *
336      * @return String return response
337      * @throws Exception file read exception
338      */
339     public String getAaiCqResponse() throws Exception {
340         String responseString = "";
341         responseString = new String(Files.readAllBytes(new File(CQ_RESPONSE_SAMPLE).toPath()));
342         return responseString;
343     }
344
345 }