0e81e5b521742d192e7776fa90b11108d1dbc25f
[ccsdk/sli/adaptors.git] / aai-service / provider / src / test / java / org / onap / ccsdk / sli / adaptors / aai / RegressionTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.sli.adaptors.aai;
23
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
27
28 import java.io.FileNotFoundException;
29 import java.io.InputStream;
30 import java.net.URL;
31 import java.util.Enumeration;
32 import java.util.HashMap;
33 import java.util.LinkedList;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Properties;
37
38 import org.apache.commons.lang.StringUtils;
39 import org.junit.AfterClass;
40 import org.junit.BeforeClass;
41 import org.junit.FixMethodOrder;
42 import org.junit.Test;
43 import org.junit.runners.MethodSorters;
44 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
45 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
46 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49
50
51 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
52 public class RegressionTest {
53
54         static {
55                 System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "INFO");
56 //              System.setProperty(org.slf4j.impl.SimpleLogger.LOG_FILE_KEY, String.format("RegressionTest-%d.txt", System.currentTimeMillis()));
57         }
58
59         private static final Logger LOG = LoggerFactory.getLogger(RegressionTest.class);
60
61         protected static AAIService client;
62
63         @BeforeClass
64         public static void setUp() throws Exception {
65 //              super.setUp();
66                 URL url = AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES);
67                 client = new AAIService(url);
68                 LOG.info("\nTaicAAIResourceTest.setUp\n");
69         }
70
71         @AfterClass
72         public static void tearDown() throws Exception {
73 //              super.tearDown();
74                 client = null;
75                 LOG.info("----------------------- AAIResourceTest.tearDown -----------------------");
76         }
77
78 //    @Test
79 //      public void R1510Test05GenericVnfDataRequestDelete() {
80 //              LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
81 //              try
82 //              {
83 //                  String vnf_id = "bpsx0001v-7071";
84 //                  boolean response = client.deleteGenericVnfData(vnf_id, null);
85 //                  assertTrue(response);
86 //
87 //              }
88 //              catch (Throwable e)
89 //              {
90 //                      assert(true);
91 //              }
92 //      }
93
94         @Test
95         public void R1604TestWanConnectorSave01Request()
96         {
97                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
98
99                 try
100                 {
101                         SvcLogicContext ctx = new SvcLogicContext();
102
103                         Map<String, String> data = new HashMap<String, String>();
104                         data.put("resource-instance-id", "12345");
105                         data.put("resource-model-uuid", "45678");
106
107                         data.put("relationship-list.relationship[0].related-to", "service-instance");
108
109                         data.put("relationship-list.relationship[0].relationship-data[0].relationship-key",             "customer.global-customer-id");
110                         data.put("relationship-list.relationship[0].relationship-data[0].relationship-value",   "$global-customer-id");
111
112                         data.put("relationship-list.relationship[0].relationship-data[1].relationship-key",             "service-subscription.service-type");
113                         data.put("relationship-list.relationship[0].relationship-data[1].relationship-value",   "$service-type");
114
115                         data.put("relationship-list.relationship[0].relationship-data[2].relationship-key",             "service-instance.service-instance-id");
116                         data.put("relationship-list.relationship[0].relationship-data[2].relationship-value",   "$serviceInstanceID");
117
118
119
120                         //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix,     SvcLogicContext ctx)
121                         QueryStatus resp = client.save("connector", false, false, "resource-instance-id = '12345'", data, "aaidata", ctx);
122
123                         LOG.info("AAIResponse: " + resp.toString());
124                 }
125                 catch (Exception e)
126                 {
127                         assert(true);
128                 }
129         }
130
131
132         @Test
133         public void R1604TestWanConnectorSave02Request()
134         {
135                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
136
137                 try
138                 {
139                         SvcLogicContext ctx = new SvcLogicContext();
140
141                         Map<String, String> data = new HashMap<String, String>();
142                         data.put("resource-instance-id", "11012345");
143                         data.put("widget-model-id", "45678");
144                         data.put("persona-model-version", "0.1");
145                         data.put("persona-model-id", "dc700a83-c507-47d9-b775-1fdfcdd5f9eb");
146                         data.put("relationship-list.relationship[0].relationship-data[0].relationship-key", "customer.global-customer-id");
147                         data.put("metadata.metadatum[0].meta-value", "100640");
148                         data.put("metadata.metadatum[0].meta-key", "vni");
149                         data.put("relationship-list.relationship[0].relationship-data[1].relationship-value", "ATT-COLLABORATE");
150                         data.put("relationship-list.relationship[0].relationship-data[0].relationship-value", "ds828e091614l");
151                         data.put("relationship-list.relationship[0].relationship-data[2].relationship-key", "service-instance.service-instance-id");
152                         data.put("relationship-list.relationship[0].relationship-data[1].relationship-key", "service-subscription.service-type");
153                         data.put("relationship-list.relationship[0].related-to", "service-instance");
154                         data.put("relationship-list.relationship[0].relationship-data[2].relationship-value", "1990e84d-546d-4b61-8069-e0db1318ade2");
155
156
157                         //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix,     SvcLogicContext ctx)
158                         QueryStatus resp = client.save("connector", false, false, "resource-instance-id = '11012345'", data, "aaidata", ctx);
159
160                         LOG.info("AAIResponse: " + resp.toString());
161                 }
162                 catch (Exception e)
163                 {
164                         assert(true);
165                 }
166         }
167
168
169         @Test
170         public void R1604TestLogicalLinkSaveRequest()
171         {
172                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
173
174                 try
175                 {
176                         SvcLogicContext ctx = new SvcLogicContext();
177
178                         Map<String, String> data = new HashMap<String, String>();
179                         data.put("link-name"            , "1252541");
180                         data.put("link-type"            , "L2 Bridge between IPE and BorderElement");
181                         data.put("speed-value"          , "1000");
182
183                         data.put("speed-units"          , "MBPS");
184                         data.put("ip-version"           , "IP-V6");
185                         data.put("routing-protocol"     , "BGP");
186                         data.put("resource-version"     , "1.0.0");
187                         data.put("resource-model-uuid"  , "TEST01");
188
189                         data.put("relationship-list.relationship[0].related-to" , "virtual-data-center");
190                         data.put("relationship-list.relationship[0].relationship-data[0].relationship-key", "virtual-data-center.vdc-id");
191                         data.put("relationship-list.relationship[0].relationship-data[0].relationship-value", "dpa2_cci_att_com-1068");
192
193                         data.put("relationship-list.relationship[1].related-to" , "generic-vnf");
194                         data.put("relationship-list.relationship[1].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
195                         data.put("relationship-list.relationship[1].relationship-data[0].relationship-value" , "basx0001v-1189");
196
197                         data.put("relationship-list.relationship[2].related-to" , "l-interface");
198                         data.put("relationship-list.relationship[2].relationship-data[0].relationship-key", "pserver.hostname");
199                         data.put("relationship-list.relationship[2].relationship-data[0].relationship-value" , "ptpbe101snd");
200
201                         data.put("relationship-list.relationship[2].relationship-data[1].relationship-key", "lag-interface.interface-name");
202                         data.put("relationship-list.relationship[2].relationship-data[1].relationship-value" , "$name");
203
204                         data.put("relationship-list.relationship[2].relationship-data[2].relationship-key", "l-interface.interface-name");
205                         data.put("relationship-list.relationship[2].relationship-data[2].relationship-value" , "$hostname");
206
207
208
209                         //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix,     SvcLogicContext ctx)
210                         QueryStatus resp = client.save("logical-link", false, false, "link-name = '1252541'", data, "aaidata", ctx);
211
212                         LOG.info("AAIResponse: " + resp.toString());
213                 }
214                 catch (Exception e)
215                 {
216                         assert(true);
217                 }
218         }
219
220         @Test
221         public void R1604TestVDCISaveRequest()
222         {
223                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
224
225                 try
226                 {
227                         SvcLogicContext ctx = new SvcLogicContext();
228
229                         Map<String, String> data = new HashMap<String, String>();
230                         data.put("vdc-id"       , "1252541");
231                         data.put("vdc-name"     , "put.the.variable.of.your.data.here");
232
233                         data.put("relationship-list.relationship[0].related-to" , "connector");
234
235                         data.put("relationship-list.relationship[0].relationship-data[0].relationship-key"   , "connector.resource-instance-id");
236                         data.put("relationship-list.relationship[0].relationship-data[0].relationship-value" , "$resource-instance-id");
237
238
239
240                         //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix,     SvcLogicContext ctx)
241                         QueryStatus resp = client.save("virtual-data-center", false, false, "vdc-id = '1252541'", data, "aaidata", ctx);
242
243                         LOG.info("AAIResponse: " + resp.toString());
244                 }
245                 catch (Exception e)
246                 {
247                         assert(true);
248                 }
249         }
250
251 //      @Test
252         public void R1510Test03RequestGenericVnfDataRequest()
253         {
254                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
255
256                 try
257                 {
258                         SvcLogicContext ctx = new SvcLogicContext();
259
260                         QueryStatus response = client.query("generic-vnf:relationship-list", false, null, "vnf-id = '34e94596-bdfa-411d-a664-16dea8583139'  AND related-to = 'l3-network' ", "aaiTest", null, ctx);
261 //                      QueryStatus response = client.delete("generic-vnf:relationship-list", "vnf-id = '34e94596-bdfa-411d-a664-16dea8583139'  AND related-to = 'pserver' ", ctx);
262
263                         assertTrue(response == QueryStatus.SUCCESS);
264                         LOG.info("AAIResponse: " + response.toString());
265                 }
266                 catch (Exception e)
267                 {
268                         LOG.error("Caught exception", e);
269                         fail("Caught exception");
270                 }
271         }
272
273         @Test
274         public void R1510Test03RequestVserverDataRequest()
275         {
276                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
277
278                 try
279                 {
280                         SvcLogicContext ctx = new SvcLogicContext();
281                         QueryStatus response = client.query("vserver", false, null,
282                                         "vserver.vserver-id = 'FRNKGEFF1' AND depth = 'all' AND cloud-region.cloud-owner = 'att-aic' AND tenant.tenant-id = '1710vPEPROJECTS::297135PROJECT' AND cloud-region.cloud-region-id = 'FRN1'"
283                                         , "aaiTest", null, ctx);
284
285                         assertNotNull(response);
286                 }
287                 catch (Exception e)
288                 {
289                         LOG.error("Caught exception", e);
290                         fail("Caught exception");
291                 }
292         }
293
294 //      @Test
295         public void R1510Test03UpdateVserverDataRequest()
296         {
297                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
298
299                 try
300                 {
301                         Properties prop = new Properties();
302                         String propFileName = "vserver-issue.txt";
303
304                         InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
305
306                         if (inputStream != null) {
307                                 prop.load(inputStream);
308                         } else {
309                                 throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
310                         }
311
312
313                         SvcLogicContext ctx = new SvcLogicContext();
314
315                         Map<String, String> data = new HashMap<String, String>();
316
317                         Enumeration keys = prop.keys();
318                         while(keys.hasMoreElements()) {
319                                 String key = keys.nextElement().toString();
320                                 String value = prop.getProperty(key);
321                                 data.put(key, value);
322                         }
323
324                         QueryStatus response = client.update("vserver", "vserver-id = '59567c27-706e-4f41-953f-b5d3a525812f' AND tenant-id = 'USITUCAB3NJ0101UJZZ01::uCPE-VMS'", data, "aaiTest",  ctx);
325
326                         assertTrue(response == QueryStatus.SUCCESS);
327                         LOG.info("AAIResponse: " + response.toString());
328                 }
329                 catch (Exception e)
330                 {
331                         LOG.error("Caught exception", e);
332                         fail("Caught exception");
333                 }
334         }
335
336 //      @Test
337         public void R1510Test03RequestVCloudRegionDataRequest()
338         {
339                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
340
341                 try
342                 {
343                         SvcLogicContext ctx = new SvcLogicContext();
344 //                      QueryStatus response = client.query("vserver", false, null, "tenant-id = '3220171995171220' AND vserver-id = '4b491df8-cf0e-4f08-88a2-133e82b63432'", "aaiTest", null, ctx);
345 //                      QueryStatus response = client.query("vserver", false, null, "vserver-name = 'bpsx0001vm001bps001'", "aaiTest", null, ctx);
346                         QueryStatus response = client.query("cloud-region", false, null,
347                                         "depth = '0' AND cloud-region.cloud-owner = 'att-aic'  AND cloud-region.cloud-region-id = 'mtn6'"
348                                         , "aaiTest", null, ctx);
349
350                         assertTrue(response == QueryStatus.SUCCESS);
351                         LOG.info("AAIResponse: " + response.toString());
352                 }
353                 catch (Exception e)
354                 {
355                         LOG.error("Caught exception", e);
356                         fail("Caught exception");
357                 }
358         }
359
360 //      @Test
361         public void R1510Test03RequestVCloudRegionData1Request()
362         {
363                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
364
365                 try
366                 {
367                         List<String> data = new LinkedList<String>();
368                         data.add("depth = 0");
369                         data.add("cloud-region.cloud-owner = 'att-aic'");
370                         data.add("cloud-region.cloud-region-id = 'mtn6'");
371
372
373                         SvcLogicContext ctx = new SvcLogicContext();
374                         QueryStatus response = client.query("cloud-region", false, null, StringUtils.join(data, " AND ")
375 //                                      "depth = '0' AND cloud-region.cloud-owner = 'att-aic'  AND cloud-region.cloud-region-id = 'mtn6'"
376                                         , "aaiTest", null, ctx);
377
378                         assertTrue(response == QueryStatus.SUCCESS);
379                         LOG.info("AAIResponse: " + response.toString());
380                 }
381                 catch (Exception e)
382                 {
383                         LOG.error("Caught exception", e);
384                         fail("Caught exception");
385                 }
386         }
387
388         @Test
389         public void R1510Test03RequestVCloudRegionData2Request()
390         {
391                 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
392
393                 try
394                 {
395                         Map<String, String> nameValues = new HashMap<String, String>();
396                         nameValues.put("depth","0");
397                         nameValues.put("cloud-region.cloud-owner", "att-aic");
398                         nameValues.put("cloud-region.cloud-region-id","mtn6");
399
400                         AAIRequest request = AAIRequest.createRequest("cloud-region", nameValues);
401
402                         for(String key : nameValues.keySet()) {
403                                 request.addRequestProperty(key, nameValues.get(key).toString());
404                         }
405
406                         String response = client.query(request);
407                         AAIDatum  datum = request.jsonStringToObject(response);
408
409 //                      assertTrue(response == QueryStatus.SUCCESS);
410                         LOG.info("AAIResponse: " + datum.toString());
411                 }
412                 catch (Exception e)
413                 {
414                         LOG.error("Caught exception", e);
415                 }
416         }
417 }